fields('FM', array('fid')); $query->distinct(); $query->condition('FM.uid', $user->uid); $query->innerJoin('file_usage', 'FU', "FU.fid = FM.fid"); $query->condition('FU.module', $module); $query->orderBy('FM.filename'); $files = $query->execute(); $files_list = []; while ($fid = $files->fetchField()) { $file = file_load($fid); foreach ($allowed_types as $type) { if (preg_match('/\.' . $type . '$/', $file->filename)) { $files_list[$fid] = $file; } } } return $files_list; } /** * Retrieves the URI for the dedicated directory for a user's files. * * This directory is used by the file uploader and by data collections. * * @param $user * A Drupal user object. * * @return * The URI of the directory. * * @ingroup tripal_files_api */ function tripal_get_user_files_dir($user) { $user_dir = 'public://tripal/users/' . $user->uid; return $user_dir; } /** * Checks if the user's dedicated directory is accessible and writeable. * * @param $user * A Drupal user object. * * @return * TRUE if the user's directory is writeable. FALSE otherwise. * * @ingroup tripal_files_api */ function tripal_is_user_files_dir_writeable($user) { $user_dir = tripal_get_user_files_dir($user); // First, make sure the directory exists. if (!file_prepare_directory($user_dir, FILE_CREATE_DIRECTORY)) { return FALSE; } // It has been reported that file_prepare_directory is not properly // detecting if the directory is writeable, so we'll do another // round of checks to be sure. if (!is_dir($user_dir)) { return FALSE; } if (!is_writeable($user_dir)) { return FALSE; } return TRUE; }