芝麻web文件管理V1.00
编辑当前文件:/home2/sdektunc/public_html/cepali/search/tests/fixtures/mock_search_area.php
. namespace core_mocksearch\search; /** * Component implementing search for testing purposes. * * @package core_search * @category phpunit * @copyright David Monllao {@link http://www.davidmonllao.com} * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die; class mock_search_area extends \core_search\base { /** @var float If set, waits when doing the indexing query (seconds) */ protected $indexingdelay = 0; /** * Multiple context level so we can test get_areas_user_accesses. * @var int[] */ protected static $levels = [CONTEXT_COURSE, CONTEXT_USER]; /** * To make things easier, base class required config stuff. * * @return bool */ public function is_enabled() { return true; } public function get_recordset_by_timestamp($modifiedfrom = 0) { global $DB; if ($this->indexingdelay) { \testable_core_search::fake_current_time( \core_search\manager::get_current_time() + $this->indexingdelay); } $sql = "SELECT * FROM {temp_mock_search_area} WHERE timemodified >= ? ORDER BY timemodified ASC"; return $DB->get_recordset_sql($sql, array($modifiedfrom)); } /** * A helper function that will turn a record into 'data array', for use with document building. */ public function convert_record_to_doc_array($record) { $docdata = (array)unserialize($record->info); $docdata['areaid'] = $this->get_area_id(); $docdata['itemid'] = $record->id; $docdata['modified'] = $record->timemodified; return $docdata; } public function get_document($record, $options = array()) { global $USER; $info = unserialize($record->info); // Prepare associative array with data from DB. $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname); $doc->set('title', $info->title); $doc->set('content', $info->content); $doc->set('description1', $info->description1); $doc->set('description2', $info->description2); $doc->set('contextid', $info->contextid); $doc->set('courseid', $info->courseid); $doc->set('userid', $info->userid); $doc->set('owneruserid', $info->owneruserid); $doc->set('modified', $record->timemodified); return $doc; } public function attach_files($document) { global $DB; if (!$record = $DB->get_record('temp_mock_search_area', array('id' => $document->get('itemid')))) { return; } $info = unserialize($record->info); foreach ($info->attachfileids as $fileid) { $document->add_stored_file($fileid); } } public function uses_file_indexing() { return true; } public function check_access($id) { global $DB, $USER; if ($record = $DB->get_record('temp_mock_search_area', array('id' => $id))) { $info = unserialize($record->info); if (in_array($USER->id, $info->denyuserids)) { return \core_search\manager::ACCESS_DENIED; } return \core_search\manager::ACCESS_GRANTED; } return \core_search\manager::ACCESS_DELETED; } public function get_doc_url(\core_search\document $doc) { return new \moodle_url('/index.php'); } public function get_context_url(\core_search\document $doc) { return new \moodle_url('/index.php'); } public function get_visible_name($lazyload = false) { return 'Mock search area'; } /** * Sets a fake delay to simulate time taken doing the indexing query. * * @param float $seconds Delay in seconds for each time indexing query is called */ public function set_indexing_delay($seconds) { $this->indexingdelay = $seconds; } }