Beispiel #1
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);
}
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')));
}
Beispiel #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');
 }
Beispiel #4
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');
 }