Exemple #1
0
/**
 * Perform a search for all content within a specific category.
 *
 * @param array $categories An array of category database records.
 * @return object An object containing an array of folders and file node references.
 */
function alfresco_category_search($categories)
{
    $return = new stdClass();
    $return->folders = array();
    $return->files = array();
    $nodes = array();
    foreach ($categories as $category) {
        /// Re-encoded special characters to ISO-9075 standard for Xpath.
        $search = array(':', '_', ' ');
        $replace = array('_x003A_', '_x005F_', '_x0020_');
        $cattitle = str_replace($search, $replace, $category->title);
        $response = alfresco_utils_invoke_service('/moodle/categorysearch/' . $cattitle);
        $sxml = RLsimpleXMLelement($response);
        if (empty($sxml)) {
            return false;
        }
        foreach ($sxml->node as $node) {
            if (!isset($nodes["{$node->uuid}"])) {
                $nodes["{$node->uuid}"] = "{$node->title}";
            }
        }
    }
    if (!empty($nodes)) {
        foreach ($nodes as $uuid => $title) {
            $node = alfresco_node_properties($uuid);
            $type = alfresco_get_type($node->uuid);
            if ($type == ALFRESCO_TYPE_FOLDER) {
                $return->folders[] = $node;
            } else {
                if ($type == ALFRESCO_TYPE_DOCUMENT) {
                    $return->files[] = $node;
                }
            }
        }
    }
    return $return;
}
 if (!$canedit) {
     print_error('youdonothaveaccesstothisfunctionality', 'repository_alfresco');
 }
 if (!empty($name) and confirm_sesskey()) {
     html_header($course, $wdir);
     // We need to get the last location we were browsing files from in order to upload the zip file there.
     if (($uuid = $repo->get_repository_location($id, $userid, $shared, $oid)) !== false) {
         $name = clean_filename($name);
         $filepath = $CFG->dataroot . '/temp/alfresco/' . $name;
         $destpath = $CFG->dataroot . '/temp/alfresco/zip-' . random_string(5) . '/';
         if (!is_dir($destpath)) {
             mkdir($destpath, $CFG->directorypermissions, true);
         }
         foreach ($USER->filelist as $fuuid) {
             $file = $repo->get_info($fuuid);
             if (alfresco_get_type($file->uuid) == 'folder') {
                 $dirfiles = $repo->download_dir($destpath, $fuuid);
                 if ($dirfiles !== false) {
                     $filelist[] = $destpath . $file->title;
                 }
             } else {
                 if ($repo->read_file($fuuid, $destpath . $file->title)) {
                     $filelist[] = $destpath . $file->title;
                 }
             }
         }
         if (!zip_files($filelist, $filepath)) {
             print_error('zipfileserror');
         }
         $repo->upload_file('', $filepath, $uuid);
         fulldelete($destpath);
 /**
  * Get navigation breadcrumbs for the current position in a repository file browser.
  *
  * @param string $uuid     Unique identifier for a node.
  * @param int    $courseid The course ID (optional).
  * @param int    $userid   The user ID (optional).
  * @param string $shared   Set to 'true' if this is for the shared storage area (optional).
  * @param string $oid      The cluster ID (optional).
  * @return array|bool An array of navigation link information or, False on error.
  */
 function get_nav_breadcrumbs($uuid, $courseid = 0, $userid = 0, $shared = '', $oid = '')
 {
     if (ALFRESCO_DEBUG_TRACE) {
         mtrace('get_nav_breadcrumbs(' . $uuid . ', ' . $courseid . ', ' . $userid . ', ' . $shared . ', ' . $oid . ')');
     }
     /// Get the "ending" UUID for the 'root' of navigation.
     if ((empty($courseid) || $courseid == SITEID) && empty($userid) && empty($shared) && empty($oid)) {
         $end = $this->get_root()->uuid;
     } else {
         if (empty($userid) && $shared == 'true') {
             $end = $this->suuid;
         } else {
             if (empty($userid) && empty($oid) && empty($shared) && !empty($courseid) && $courseid != SITEID) {
                 $end = $this->get_course_store($courseid);
             } else {
                 if (!empty($userid)) {
                     $end = $this->get_user_store($userid);
                 } else {
                     if (empty($userid) && !empty($oid)) {
                         $end = $this->get_organization_store($oid);
                     }
                 }
             }
         }
     }
     $stack = array();
     $node = $this->get_info($uuid);
     if (alfresco_get_type($uuid) == ALFRESCO_TYPE_FOLDER) {
         $nav = array('name' => $node->title, 'path' => $node->uuid);
         array_push($stack, $nav);
     } else {
         if (alfresco_get_type($uuid) != ALFRESCO_TYPE_DOCUMENT) {
             return false;
         }
     }
     if ($node->uuid == $end) {
         return false;
     }
     if (!($parent = $this->get_parent($node->uuid))) {
         return false;
     }
     while (!empty($parent->uuid) && $parent->uuid != $end) {
         $nav = array('name' => $parent->title, 'uuid' => $parent->uuid);
         array_push($stack, $nav);
         $parent = $this->get_parent($parent->uuid);
     }
     if (!empty($stack)) {
         return array_reverse($stack);
     }
     return false;
 }