/** * Look for a file * * @param string $search_text The search text entered, which contains tokens * representing either file name or file content * @param int $page The page we are showing the contents for * @param int $categories An array of category ids to filter on (i.e. results * must be in one or more to be included), or NULL to not filter * by category * @return array A data structure equivalent to the return value of "get_listing", * containing the filter listing */ function search($search_text, $page = 1, $categories = NULL) { global $CFG, $COURSE, $OUTPUT, $USER; require_once($CFG->dirroot.'/repository/elisfiles/lib/lib.php'); $ret = array(); $shared = 0; $oid = 0; // Set id if (!empty($USER->id)) { $uid = $USER->id; $cid = 0; } if (!empty($COURSE->id)) { $cid = $COURSE->id; $uid = 0; } // setting userid... if ($this->context->contextlevel === CONTEXT_USER) { $userid = $USER->id; } else { $userid = 0; } $courseid = $COURSE->id; $uuid = false; if ($ruuid = $this->elis_files->get_repository_location($courseid, $userid, $shared, $oid)) { $uuid = $ruuid; } else if ($duuid = $this->elis_files->get_default_browsing_location($courseid, $userid, $shared, $oid)) { $uuid = $duuid; } $uuuid = $this->elis_files->get_user_store($USER->id); if ($uuid == $uuuid) { $uid = $USER->id; } else { $uid = 0; } $canedit = self::check_editing_permissions($COURSE->id, $shared, $oid, $uuid, $uid); $ret['canedit'] = $canedit; $ret['detailcols'] = array(array('field'=>'created', 'title'=>get_string('datecreated','repository_elisfiles')), array('field'=>'modified', 'title'=>get_string('datemodified','repository_elisfiles')), array('field'=>'owner', 'title'=>get_string('modifiedby','repository_elisfiles')) ); $ret['dynload'] = true; $ret['nologin'] = true; $ret['showselectedactions'] = true; $ret['showcurrentactions'] = false; // do not show current actions for search results because we are not in a folder // Can only have either course or user id set if (!empty($cid) && !empty($uid)) { $cid = 0; } // Set permissible browsing locations $ret['locations'] = array(); $this->elis_files->file_browse_options($cid, $uid, $shared, $oid, $ret['locations']); $ret['list'] = array(); // Obtain the list of matching files $query = $this->get_search_query($search_text, $categories); $response = elis_files_utils_invoke_service('/moodle/lucenesearch?searchquery='.rawurlencode($query)); $sxml = RLsimpleXMLelement($response); if ($sxml and $entries = $sxml->xpath('//entry')) { foreach ($entries as $entry) { // Include shared and oid parameters $uuid = (string)$entry->uuid; if ($properties = $this->elis_files->get_info($uuid)) { if (strcmp($properties->type, "cmis:folder") !== 0 && strcmp($properties->type, "folder") !== 0) { $params = array('path'=>$uuid, 'shared'=>(boolean)$shared, 'oid'=>(int)$oid, 'cid'=>(int)$cid, 'uid'=>(int)$uid); $encodedpath = base64_encode(serialize($params)); $filesize = isset($properties->filesize) ? $properties->filesize : ''; $created = isset($properties->created) ? $properties->created : ''; $modified = isset($properties->modified) ? $properties->modified : ''; $owner = isset($properties->owner) ? $properties->owner : ''; $alfresco_version = elis_files_get_repository_version(); if ($alfresco_version == '3.2.1') { $thumbnail = $OUTPUT->pix_url(file_extension_icon($entry->filename, 90))->out(false); } else { $thumbnail = $OUTPUT->pix_url(file_extension_icon($entry->icon, 90))->out(false); } $ret['list'][] = array('title'=>$properties->title, 'path'=>$encodedpath, 'size' => $filesize, 'thumbnail' => $thumbnail, 'datecreated'=>$created, 'datemodified'=>$modified, 'author'=>$owner, 'source'=>$uuid); } } } } return $ret; }
/** * 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 elis_files_category_search($categories) { $return = new stdClass; $return->folders = array(); $return->files = array(); $nodes = array(); foreach ($categories as $category) { $cattitle = elis_files_ISO_9075_map($category->title); $response = elis_files_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 = elis_files_node_properties($uuid); $type = elis_files_get_type($node->uuid); if ($type == ELIS_files::$type_folder) { $return->folders[] = $node; } else if ($type == ELIS_files::$type_document) { $return->files[] = $node; } } } return $return; }