/**
  * Test that an artefact gets a new path when moved.
  */
 public function testArtefactHierarchyMove()
 {
     // Create folder.
     $folderdata = array('owner' => $this->testuserid, 'title' => 'Test folder', 'description' => 'Test folder description');
     $folder = new ArtefactTypeFolder(0, $folderdata);
     $folder->commit();
     // Create a file.
     $filedata = array('owner' => $this->testuserid, 'title' => 'Test file', 'description' => 'Test file description');
     $file = new ArtefactTypeFile(0, $filedata);
     $file->commit();
     // Check that path is root.
     $fileid = $file->get('id');
     $this->assertEquals('/' . $fileid, $file->get('path'));
     // "Move" file to a folder.
     $folderid = $folder->get('id');
     $file = new ArtefactTypeFile($fileid);
     $file->move($folderid);
     $newpath = "/{$folderid}/{$fileid}";
     $this->assertEquals($newpath, $file->get('path'));
 }
Пример #2
0
function pieform_element_filebrowser_createfolder(Pieform $form, $element, $data)
{
    global $USER;
    $parentfolder = $data['folder'] ? (int) $data['folder'] : null;
    $institution = !empty($element['institution']) ? $element['institution'] : $form->get_property('institution');
    $group = !empty($element['group']) ? $element['group'] : $form->get_property('group');
    $result = array();
    $data = (object) array('parent' => $parentfolder, 'owner' => null, 'title' => trim($data['title']));
    if ($parentfolder) {
        $parentartefact = artefact_instance_from_id($parentfolder);
        if (!$USER->can_edit_artefact($parentartefact)) {
            return array('error' => true, 'message' => get_string('cannoteditfolder', 'artefact.file'));
        } else {
            if ($parentartefact->get('locked')) {
                return array('error' => true, 'message' => get_string('cannoteditfoldersubmitted', 'artefact.file'));
            }
        }
    }
    $data->owner = $data->group = $data->institution = null;
    if ($institution) {
        $data->institution = $institution;
    } else {
        if ($group) {
            if (!group_within_edit_window($group)) {
                return array('error' => true, 'message' => get_string('cannoteditfolder', 'artefact.file'));
            }
            if (!$parentfolder) {
                if (!pieform_element_filebrowser_edit_group_folder($group, 0)) {
                    return array('error' => true, 'message' => get_string('cannoteditfolder', 'artefact.file'));
                }
            }
            $data->group = $group;
        } else {
            $data->owner = $USER->get('id');
        }
    }
    if ($oldid = ArtefactTypeFileBase::file_exists($data->title, $data->owner, $parentfolder, $institution, $group)) {
        return array('error' => true, 'message' => get_string('fileexists', 'artefact.file'));
    }
    $f = new ArtefactTypeFolder(0, $data);
    $f->set('dirty', true);
    $f->commit();
    return array('error' => false, 'message' => get_string('foldercreated', 'artefact.file'), 'highlight' => $f->get('id'), 'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $parentfolder, $f->get('id'), $data->owner, $data->group, $data->institution), 'foldercreated' => true);
}
Пример #3
0
 /**
  * Creates a folder artefact based on the given entry.
  *
  * @param SimpleXMLElement $entry The entry to base the folder's data on
  * @param PluginImport $importer  The importer
  * @param int $parent             The ID of the parent artefact for this folder
  * @throws ImportException If the given entry is not detected as being a folder
  * @return int The ID of the folder artefact created
  */
 private static function create_folder(SimpleXMLElement $entry, PluginImport $importer, $parent = null)
 {
     if (!self::is_folder($entry, $importer)) {
         throw new ImportException($importer, "create_folder(): Cannot create a folder artefact from an entry we don't recognise as a folder");
     }
     $folder = new ArtefactTypeFolder();
     $folder->set('title', (string) $entry->title);
     $folder->set('description', PluginImportLeap::get_entry_content($entry, $importer));
     if ($published = strtotime((string) $entry->published)) {
         $folder->set('ctime', $published);
     }
     if ($updated = strtotime((string) $entry->updated)) {
         $folder->set('mtime', $updated);
     }
     $folder->set('owner', $importer->get('usr'));
     $folder->set('tags', PluginImportLeap::get_entry_tags($entry));
     if ($parent) {
         $folder->set('parent', $parent);
     }
     $folder->commit();
     return $folder->get('id');
 }
Пример #4
0
try {
    $folder = param_variable('foldername');
    $folder = trim($folder);
    if ($folder) {
        // TODO: create if doesn't exist - note assumes it is a base folder (hence null parent)
        $artefact = ArtefactTypeFolder::get_folder_by_name($folder, null, $data->owner);
        // id of folder you're putting the file into
        if ($artefact) {
            $data->parent = $artefact->id;
            if ($data->parent == 0) {
                $data->parent = null;
            }
        } else {
            $fd = (object) array('owner' => $data->owner, 'title' => $folder, 'parent' => null);
            $f = new ArtefactTypeFolder(0, $fd);
            $f->commit();
            $data->parent = $f->get('id');
        }
    } else {
        $data->parent = null;
    }
} catch (ParameterException $e) {
    $data->parent = null;
}
// Check for Journal ID to add a post to
$blog = '';
$blogpost = '';
$draft = 0;
$allowcomments = 1;
try {
    $blog = param_integer('blog');
Пример #5
0
 /**
  * Get the id of a folder, creating the folder if necessary
  *
  * @param string $name        The name of the folder to search for
  * @param string $description The description for the folder, should a new folder need creating
  * @param int $parentfolderid The ID of the parent folder in which to look.
  * @param boolean $create     Whether to create a new folder if one isn't found
  * @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_id($name, $description, $parentfolderid = null, $create = true, $userid = null, $groupid = null, $institution = null, $artefactstoignore = array())
 {
     if (!($record = self::get_folder_by_name($name, $parentfolderid, $userid, $groupid, $institution, $artefactstoignore))) {
         if (!$create) {
             return false;
         }
         $data = new StdClass();
         $data->title = $name;
         $data->description = $description;
         $data->owner = $userid;
         $data->group = $groupid;
         $data->institution = $institution;
         $data->parent = $parentfolderid;
         $f = new ArtefactTypeFolder(0, $data);
         $f->commit();
         return $f->get('id');
     }
     return $record->id;
 }
Пример #6
0
 public function create_folder($folder)
 {
     $newfolder = new ArtefactTypeFolder(0, $this->data['template']);
     $newfolder->commit();
     if ($this->archivetype == 'zip') {
         $folderindex = $folder == '.' ? $this->data['template']->title . '/' : $folder . $this->data['template']->title . '/';
     } else {
         $folderindex = ($folder == '.' ? '' : $folder . '/') . $this->data['template']->title;
     }
     $this->data['folderids'][$folderindex] = $newfolder->get('id');
     $this->data['folderscreated']++;
 }
Пример #7
0
function pieform_element_filebrowser_createfolder(Pieform $form, $element, $data)
{
    global $USER;
    $parentfolder = $data['folder'] ? (int) $data['folder'] : null;
    $institution = $form->get_property('institution');
    $group = $form->get_property('group');
    $result = array();
    $data = (object) array('parent' => $parentfolder, 'owner' => null, 'title' => $data['title']);
    if ($parentfolder) {
        $parentartefact = artefact_instance_from_id($parentfolder);
        if (!$USER->can_edit_artefact($parentartefact)) {
            return array('error' => true, 'message' => get_string('cannoteditfolder', 'artefact.file'));
        } else {
            if ($parentartefact->get('locked')) {
                return array('error' => true, 'message' => get_string('cannoteditfoldersubmitted', 'artefact.file'));
            }
        }
    }
    if ($institution) {
        $data->institution = $institution;
    } else {
        if ($group) {
            require_once get_config('libroot') . 'group.php';
            if (!$parentfolder) {
                $role = group_user_access($group);
                if (!$role) {
                    return array('error' => true, 'message' => get_string('usernotingroup', 'mahara'));
                }
                // Use default grouptype artefact permissions to check if the
                // user can create a folder in the group's root directory
                $permissions = group_get_default_artefact_permissions($group);
                if (!$permissions[$role]->edit) {
                    return array('error' => true, 'message' => get_string('cannoteditfolder', 'artefact.file'));
                }
            }
            $data->group = $group;
        } else {
            $data->owner = $USER->get('id');
        }
    }
    if ($oldid = ArtefactTypeFileBase::file_exists($data->title, $data->owner, $parentfolder, $institution, $group)) {
        return array('error' => true, 'message' => get_string('fileexists', 'artefact.file'));
    }
    $f = new ArtefactTypeFolder(0, $data);
    $f->set('dirty', true);
    $f->commit();
    return array('error' => false, 'message' => get_string('foldercreated', 'artefact.file'), 'highlight' => $f->get('id'), 'newlist' => pieform_element_filebrowser_build_filelist($form, $element, $parentfolder, $f->get('id')));
}
Пример #8
0
 public function create_folder($folder)
 {
     $newfolder = new ArtefactTypeFolder(0, $this->data['template']);
     $newfolder->commit();
     $folderindex = ($folder == '.' ? '' : $folder . '/') . $this->data['template']->title;
     $this->data['folderids'][$folderindex] = $newfolder->get('id');
     $this->data['folderscreated']++;
 }
Пример #9
0
 /**
  * Creates a folder artefact based on the given entry.
  *
  * @param SimpleXMLElement $entry    The entry to base the folder's data on
  * @param PluginImportLeap $importer The importer
  * @param int $parent                The ID of the parent artefact for this folder
  * @throws ImportException If the given entry is not detected as being a folder
  * @return int The ID of the folder artefact created
  */
 private static function create_folder(SimpleXMLElement $entry, PluginImportLeap $importer, $parent = null)
 {
     $config = self::get_folder_entry_data($entry, $importer, $parent);
     $folder = new ArtefactTypeFolder();
     $folder->set('title', $config['content']['title']);
     $folder->set('description', $config['content']['description']);
     if ($config['content']['ctime']) {
         $folder->set('ctime', $config['content']['ctime']);
     }
     if ($config['content']['mtime']) {
         $folder->set('mtime', $config['content']['mtime']);
     }
     $folder->set('owner', $config['owner']);
     $folder->set('tags', $config['content']['tags']);
     if ($config['parent']) {
         $folder->set('parent', $config['parent']);
     }
     $folder->commit();
     return $folder->get('id');
 }