/** * Displaying search results. * * @param \core_search\document Containing a single search response to be displayed.a * @return string HTML */ public function render_result(\core_search\document $doc) { $docdata = $doc->export_for_template($this); // Limit text fields size. $docdata['title'] = shorten_text($docdata['title'], static::SEARCH_RESULT_STRING_SIZE, true); $docdata['content'] = $docdata['content'] ? shorten_text($docdata['content'], static::SEARCH_RESULT_TEXT_SIZE, true) : ''; $docdata['description1'] = $docdata['description1'] ? shorten_text($docdata['description1'], static::SEARCH_RESULT_TEXT_SIZE, true) : ''; $docdata['description2'] = $docdata['description2'] ? shorten_text($docdata['description2'], static::SEARCH_RESULT_TEXT_SIZE, true) : ''; return $this->output->render_from_template('core_search/result', $docdata); }
/** * Link to the glossary. * * @param \core_search\document $doc * @return \moodle_url */ public function get_context_url(\core_search\document $doc) { $contextmodule = \context::instance_by_id($doc->get('contextid')); return new \moodle_url('/mod/glossary/view.php', array('id' => $contextmodule->instanceid)); }
/** * Link to the course. * * @param \core_search\document $doc * @return \moodle_url */ public function get_context_url(\core_search\document $doc) { return new \moodle_url('/course/view.php', array('id' => $doc->get('courseid'))); }
/** * Returns a url to the document context. * * @param \core_search\document $doc * @return moodle_url */ public function get_context_url(\core_search\document $doc) { return new \moodle_url('/user/profile.php', array('id' => $doc->get('itemid'))); }
/** * Apply any defaults to unset fields before export. Called after document building, but before export. * * Sub-classes of this should make sure to call parent::apply_defaults(). */ protected function apply_defaults() { parent::apply_defaults(); // We want to set the solr_filegroupingid to id if it isn't set. if (!isset($this->data['solr_filegroupingid'])) { $this->data['solr_filegroupingid'] = $this->data['id']; } }
/** * Link to the module instance. * * @param \core_search\document $doc * @return \moodle_url */ public function get_context_url(\core_search\document $doc) { $cminfo = $this->get_cm($this->get_module_name(), strval($doc->get('itemid')), $doc->get('courseid')); return new \moodle_url('/mod/' . $this->get_module_name() . '/view.php', array('id' => $cminfo->id)); }
public function get_doc_url(\core_search\document $doc) { // This is just an example, can vary a lot depending on what are you indexing. return new \moodle_url('/local/courseblog/view.php', array('post' => $doc->get('contextid'))); }
/** * Add the database entries attachments. * * @param \core_search\document $doc * @return void */ public function attach_files($doc) { global $DB; $entryid = $doc->get('itemid'); try { $entry = $this->get_entry($entryid); } catch (\dml_missing_record_exception $e) { debugging('Could not get record to attach files to ' . $doc->get('id'), DEBUG_DEVELOPER); return; } $cm = $this->get_cm('data', $entry->dataid, $doc->get('courseid')); $context = \context_module::instance($cm->id); // Get the files and attach them. $fs = get_file_storage(); $files = $fs->get_area_files($context->id, 'mod_data', 'content', $entryid, 'filename', false); foreach ($files as $file) { $doc->add_stored_file($file); } }
/** * Sorting the current(user1) and other(user2) user in the conversation. * * @param \core_search\document $doc * @return array() */ protected function get_current_other_users($doc) { global $USER; $users = array(); if ($USER->id == $doc->get('owneruserid') || get_class($this) === 'message_sent') { $users['currentuserid'] = $doc->get('owneruserid'); $users['otheruserid'] = $doc->get('userid'); } else { $users['currentuserid'] = $doc->get('userid'); $users['otheruserid'] = $doc->get('owneruserid'); } return $users; }