/**
 * Retrieve file list in a folder
 * @global object $REMOTEWWWROOT
 * @param string $username
 * @param integer $folderid  folder to browse
 * @return array The complete folder path + list of files for a specific Mahara folder
 */
function get_folder_files($username, $folderid)
{
    global $REMOTEWWWROOT;
    //check that the user exists
    list($user, $authinstance) = find_remote_user($username, $REMOTEWWWROOT);
    if (!$user) {
        throw new ExportException("Could not find user {$username} for {$REMOTEWWWROOT}");
    }
    $list = array();
    safe_require('artefact', 'file');
    $filetypes = array_diff(PluginArtefactFile::get_artefact_types(), array('profileicon'));
    foreach ($filetypes as $k => $v) {
        if ($v == 'folder') {
            unset($filetypes[$k]);
        }
    }
    $filetypesql = "('" . join("','", $filetypes) . "')";
    $ownersql = artefact_owner_sql($user->id);
    $folderpath = array();
    //the complete folder path (some client could need it)
    if (!empty($folderid)) {
        $pathsql = " AND parent = {$folderid}";
        //build the path
        $parentids = artefact_get_parents_for_cache($folderid);
        //the closest parent is on the first key
        //the further parent is on the last key
        foreach ($parentids as $id => $dump) {
            $artefact = get_record('artefact', 'id', $id);
            array_unshift($folderpath, array('path' => $artefact->id, 'name' => $artefact->title));
        }
    } else {
        $pathsql = "AND parent IS NULL";
    }
    array_unshift($folderpath, array('path' => null, 'name' => 'Root'));
    //retrieve folders and files of a specific Mahara folder
    $list = array('files' => get_records_select_array('artefact', "artefacttype IN {$filetypesql} AND {$ownersql} {$pathsql}", array(), 'title'), 'folders' => get_records_select_array('artefact', "artefacttype = 'folder' AND {$ownersql} {$pathsql}", array(), 'title'));
    return array($folderpath, $list);
}
Example #2
0
File: lib.php Project: kienv/mahara
function artefact_new_title($title, $artefacttype, $owner, $group, $institution)
{
    $taken = get_column_sql('
        SELECT title
        FROM {artefact}
        WHERE ' . artefact_owner_sql($owner, $group, $institution) . "\n            AND title LIKE ? || '%'", array($title));
    $ext = '';
    $i = 0;
    if ($taken) {
        while (in_array($title . $ext, $taken)) {
            $ext = ' (' . ++$i . ')';
        }
    }
    return $title . $ext;
}
Example #3
0
 /**
  * Retrieves info from the artefact table about the folder with the given 
  * name, in the specified directory, owned by the specified 
  * user/group/institution.
  *
  * @param string $name        The name of the folder to search for
  * @param int $parentfolderid The ID of the parent folder in which to look.
  * @param int $userid         The ID of the user who owns the folder
  * @param int $groupid        The ID of the group who owns the folder
  * @param string $institution The name of the institution who owns the folder
  * @param array $artefactstoignore A list of IDs to not consider as the given folder. See {@link default_parent_for_copy()}
  */
 public static function get_folder_by_name($name, $parentfolderid = null, $userid = null, $groupid = null, $institution = null, $artefactstoignore = array())
 {
     $parentclause = $parentfolderid ? 'parent = ' . $parentfolderid : 'parent IS NULL';
     $ownerclause = artefact_owner_sql($userid, $groupid, $institution);
     $ignoreclause = $artefactstoignore ? ' AND id NOT IN(' . implode(', ', array_map('db_quote', $artefactstoignore)) . ')' : '';
     return get_record_sql('SELECT * FROM {artefact}
        WHERE title = ? AND ' . $parentclause . ' AND ' . $ownerclause . "\n           AND artefacttype = 'folder'" . $ignoreclause, array($name));
 }