示例#1
0
 public function dump_export_data()
 {
     foreach ($this->exporter->get('artefacts') as $artefact) {
         if (in_array($artefact->get('artefacttype'), PluginArtefactFile::get_artefact_types())) {
             $this->artefactdata[$artefact->get('id')] = $artefact;
         }
     }
     // Grab all parent folders of all artefacts selected so we can export
     // the files in their correct folder location
     if ($this->exporter->get('artefactexportmode') != PluginExport::EXPORT_ALL_ARTEFACTS && $this->artefactdata) {
         $folderids = array();
         foreach (array_keys($this->artefactdata) as $artefactid) {
             $folderids = array_merge($folderids, array_keys(artefact_get_parents_for_cache($artefactid)));
         }
         $folderids = array_unique($folderids);
         foreach ($folderids as $folderid) {
             if (!isset($this->artefactdata[$folderid])) {
                 $artefact = artefact_instance_from_id($folderid);
                 // We grabbed all parents of the artefacts in the export,
                 // but not all parents are folders
                 if ($artefact->get('artefacttype') == 'folder') {
                     $this->artefactdata[$folderid] = $artefact;
                 }
             }
         }
     }
     $this->populate_profileicons();
     $this->create_index_for_directory($this->fileroot, 0, null);
     $this->populate_filedir($this->fileroot, 0, null);
 }
示例#2
0
 public function dump_export_data()
 {
     global $SESSION;
     $this->owner = $this->exporter->get('user')->get('id');
     foreach ($this->exporter->get('artefacts') as $artefact) {
         if (in_array($artefact->get('artefacttype'), PluginArtefactFile::get_artefact_types())) {
             $id = $artefact->get('id');
             $this->artefactdata[$id] = $artefact;
             if ($artefact->get('owner') != $this->owner) {
                 $this->otherfiles[$id] = $id;
             }
         }
     }
     // Grab all parent folders of all artefacts owned by the exporting user, so we can export
     // the files in their correct folder location
     if ($this->exporter->get('artefactexportmode') != PluginExport::EXPORT_ALL_ARTEFACTS && $this->artefactdata) {
         $folderids = array();
         foreach (array_keys($this->artefactdata) as $artefactid) {
             if (!isset($this->otherfiles[$artefactid])) {
                 $folderids = array_merge($folderids, array_keys(artefact_get_parents_for_cache($artefactid)));
             }
         }
         $folderids = array_unique($folderids);
         foreach ($folderids as $folderid) {
             if (!isset($this->artefactdata[$folderid])) {
                 $artefact = artefact_instance_from_id($folderid);
                 // We grabbed all parents of the artefacts in the export,
                 // but not all parents are folders
                 if ($artefact->get('artefacttype') == 'folder') {
                     $this->artefactdata[$folderid] = $artefact;
                 }
             }
         }
     }
     $this->populate_profileicons();
     $this->create_index_for_directory($this->fileroot, 0, null);
     $this->populate_filedir($this->fileroot, 0, null);
     // Copy other users' files into the extrafileroot directory
     foreach ($this->otherfiles as $id) {
         if (!$this->artefactdata[$id] instanceof ArtefactTypeFile) {
             continue;
         }
         $dest = $this->extrafileroot . $id . '-' . PluginExportHtml::sanitise_path($this->artefactdata[$id]->get('title'));
         if (!copy($this->artefactdata[$id]->get_path(), $dest)) {
             $SESSION->add_error_msg(get_string('unabletocopyartefact', 'export', $this->artefactdata[$id]->get('title')));
         }
     }
 }
示例#3
0
文件: lib.php 项目: kienv/mahara
function artefact_get_parents_for_cache($artefactids, &$parentids = false)
{
    if (!is_array($artefactids)) {
        $artefactids = array($artefactids);
    }
    $current = array_map('intval', $artefactids);
    if (empty($parentids)) {
        // first call
        $parentids = array();
    }
    while (true) {
        if (!($parents = get_records_select_array('artefact', 'id IN (' . join(',', $current) . ')'))) {
            break;
        }
        // get any blog posts these artefacts may be attached to
        $checkattachments = array();
        foreach ($parents as $p) {
            if (in_array($p->artefacttype, artefact_get_attachment_types())) {
                $checkattachments[] = (int) $p->id;
            }
        }
        if (!empty($checkattachments)) {
            if ($associated = get_records_select_assoc('artefact_attachment', 'attachment IN (' . join(',', $checkattachments) . ')')) {
                $associated = array_keys($associated);
                foreach ($associated as $a) {
                    $parentids[$a] = 1;
                }
                artefact_get_parents_for_cache($associated, $parentids);
            }
        }
        // check parents
        $current = array();
        foreach ($parents as $p) {
            if ($p->parent) {
                $parentids[$p->parent] = 1;
                $current[] = $p->parent;
            }
        }
        if (empty($current)) {
            break;
        }
    }
    return $parentids;
}
示例#4
0
function artefact_watchlist_notification($artefactids)
{
    // gets all the views containing this artefact or a parent of this artefact and creates a watchlist activity for each view
    if ($views = get_column_sql('SELECT DISTINCT "view" FROM {view_artefact} WHERE artefact IN (' . implode(',', array_merge(array_keys(artefact_get_parents_for_cache($artefactids)), array_map('intval', $artefactids))) . ')')) {
        require_once 'activity.php';
        foreach ($views as $view) {
            activity_occurred('watchlist', (object) array('view' => $view));
        }
    }
}
示例#5
0
/**
 * 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);
}