/** * Returns the document associated with this course. * * @param stdClass $record * @param array $options * @return \core_search\document */ public function get_document($record, $options = array()) { try { $context = \context_course::instance($record->id); } catch (\moodle_exception $ex) { // Notify it as we run here as admin, we should see everything. debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' . $ex->getMessage(), DEBUG_DEVELOPER); return false; } // Prepare associative array with data from DB. $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname); $doc->set('title', content_to_text($record->fullname, false)); $doc->set('content', content_to_text($record->summary, $record->summaryformat)); $doc->set('contextid', $context->id); $doc->set('courseid', $record->id); $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID); $doc->set('modified', $record->timemodified); $doc->set('description1', $record->shortname); // Check if this document should be considered new. if (isset($options['lastindexedtime']) && $options['lastindexedtime'] < $record->timecreated) { // If the document was created after the last index time, it must be new. $doc->set_is_new(true); } return $doc; }
/** * Returns the document associated with this post id. * * @param stdClass $record Post info. * @return \core_search\document */ public function get_document($record) { try { $cm = $this->get_cm('forum', $record->forumid, $record->courseid); $context = \context_module::instance($cm->id); } catch (\dml_missing_record_exception $ex) { // Notify it as we run here as admin, we should see everything. debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' . $ex->getMessage(), DEBUG_DEVELOPER); return false; } catch (\dml_exception $ex) { // Notify it as we run here as admin, we should see everything. debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER); return false; } // Prepare associative array with data from DB. $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname); $doc->set('title', $record->subject); $doc->set('content', content_to_text($record->message, $record->messageformat)); $doc->set('contextid', $context->id); $doc->set('type', \core_search\manager::TYPE_TEXT); $doc->set('courseid', $record->courseid); $doc->set('userid', $record->userid); $doc->set('modified', $record->modified); return $doc; }
/** * Returns the document associated with this activity. * * Overwriting base_activity method as page contents field is required, * description field is not. * * @param stdClass $record * @param array $options * @return \core_search\document */ public function get_document($record, $options = array()) { try { $cm = $this->get_cm($this->get_module_name(), $record->id, $record->course); $context = \context_module::instance($cm->id); } catch (\dml_missing_record_exception $ex) { // Notify it as we run here as admin, we should see everything. debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' . $ex->getMessage(), DEBUG_DEVELOPER); return false; } catch (\dml_exception $ex) { // Notify it as we run here as admin, we should see everything. debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER); return false; } // Prepare associative array with data from DB. $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname); $doc->set('title', content_to_text($record->name, false)); $doc->set('content', content_to_text($record->content, $record->contentformat)); $doc->set('contextid', $context->id); $doc->set('courseid', $record->course); $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID); $doc->set('modified', $record->timemodified); $doc->set('description1', content_to_text($record->intro, $record->introformat)); return $doc; }
public function get_document($record) { global $USER; // Prepare associative array with data from DB. $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname); $doc->set('title', $record->capability . ' roleid ' . $record->roleid); $doc->set('content', $record->capability . ' roleid ' . $record->roleid . ' message'); $doc->set('contextid', $record->contextid); $doc->set('type', \core_search\manager::TYPE_TEXT); $doc->set('courseid', SITEID); $doc->set('userid', $USER->id); $doc->set('modified', time()); return $doc; }
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('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 get_document($record, $options = array()) { global $DB; $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname); $doc->set('title', $record->title); $doc->set('content', $record->entry_text, false); $doc->set('description1', $record->author); $sql = "SELECT c.id, category FROM {local_courseblog_categories} c INNER JOIN {local_courseblog_post_cat} p ON c.id=p.category_id WHERE p.post_id=?"; $cat = $DB->get_records_sql_menu($sql, array($record->id)); $doc->set('description2', implode($cat, ", ")); $doc->set('contextid', $record->id); $doc->set('courseid', 1); $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID); $doc->set('modified', $record->post_date); return $doc; }
/** * Returns the documents associated with this glossary entry id. * * @param stdClass $entry glossary entry. * @param array $options * @return \core_search\document */ public function get_document($entry, $options = array()) { global $DB; $keywords = array(); if ($aliases = $DB->get_records('glossary_alias', array('entryid' => $entry->id))) { foreach ($aliases as $alias) { $keywords[] = $alias->alias; } } try { $cm = $this->get_cm('glossary', $entry->glossaryid, $entry->course); $context = \context_module::instance($cm->id); } catch (\dml_missing_record_exception $ex) { // Notify it as we run here as admin, we should see everything. debugging('Error retrieving mod_glossary ' . $entry->id . ' document, not all required data is available: ' . $ex->getMessage(), DEBUG_DEVELOPER); return false; } catch (\dml_exception $ex) { // Notify it as we run here as admin, we should see everything. debugging('Error retrieving mod_glossary' . $entry->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER); return false; } // Prepare associative array with data from DB. $doc = \core_search\document_factory::instance($entry->id, $this->componentname, $this->areaname); $doc->set('title', content_to_text($entry->concept, false)); $doc->set('content', content_to_text($entry->definition, $entry->definitionformat)); $doc->set('contextid', $context->id); $doc->set('courseid', $entry->course); $doc->set('userid', $entry->userid); $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID); $doc->set('modified', $entry->timemodified); // Check if this document should be considered new. if (isset($options['lastindexedtime']) && $options['lastindexedtime'] < $entry->timecreated) { // If the document was created after the last index time, it must be new. $doc->set_is_new(true); } // Adding keywords as extra info. if ($keywords) { // No need to pass through content_to_text here as this is just a list of keywords. $doc->set('description1', implode(' ', $keywords)); } return $doc; }
/** * Returns document instances for each record in the recordset. * * @param StdClass $record * @param array $options * @return core_search/document */ public function get_document($record, $options = array()) { $context = \context_system::instance(); // Prepare associative array with data from DB. $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname); // Assigning properties to our document. $doc->set('title', content_to_text(fullname($record), false)); $doc->set('contextid', $context->id); $doc->set('courseid', SITEID); $doc->set('itemid', $record->id); $doc->set('modified', $record->timemodified); $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID); $doc->set('content', content_to_text($record->description, $record->descriptionformat)); // Check if this document should be considered new. if (isset($options['lastindexedtime']) && $options['lastindexedtime'] < $record->timecreated) { // If the document was created after the last index time, it must be new. $doc->set_is_new(true); } return $doc; }
/** * Returns the documents associated with this glossary entry id. * * @param stdClass $entry glossary entry. * @param array $options * @return \core_search\document */ public function get_document($entry, $options = array()) { global $DB; try { $cm = $this->get_cm('data', $entry->dataid, $entry->course); $context = \context_module::instance($cm->id); } catch (\dml_missing_record_exception $ex) { // Notify it as we run here as admin, we should see everything. debugging('Error retrieving mod_data ' . $entry->id . ' document, not all required data is available: ' . $ex->getMessage(), DEBUG_DEVELOPER); return false; } catch (\dml_exception $ex) { // Notify it as we run here as admin, we should see everything. debugging('Error retrieving mod_data' . $entry->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER); return false; } // Prepare associative array with data from DB. $doc = \core_search\document_factory::instance($entry->id, $this->componentname, $this->areaname); $doc->set('contextid', $context->id); $doc->set('courseid', $entry->course); $doc->set('userid', $entry->userid); $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID); $doc->set('modified', $entry->timemodified); $indexfields = $this->get_fields_for_entries($entry); if (count($indexfields) < 2) { return false; } // All fields should be already returned as plain text by data_field_base::get_content_value. $doc->set('title', $indexfields[0]); $doc->set('content', $indexfields[1]); if (isset($indexfields[2])) { $doc->set('description1', $indexfields[2]); } if (isset($indexfields[3])) { $doc->set('description2', $indexfields[3]); } return $doc; }
/** * Returns the documents associated with this glossary entry id. * * @param stdClass $entry glossary entry. * @return \core_search\document */ public function get_document($entry) { global $DB; $keywords = array(); if ($aliases = $DB->get_records('glossary_alias', array('entryid' => $entry->id))) { foreach ($aliases as $alias) { $keywords[] = $alias->alias; } } try { $cm = $this->get_cm('glossary', $entry->glossaryid, $entry->course); $context = \context_module::instance($cm->id); } catch (\dml_missing_record_exception $ex) { // Notify it as we run here as admin, we should see everything. debugging('Error retrieving mod_glossary ' . $entry->id . ' document, not all required data is available: ' . $ex->getMessage(), DEBUG_DEVELOPER); return false; } catch (\dml_exception $ex) { // Notify it as we run here as admin, we should see everything. debugging('Error retrieving mod_glossary' . $entry->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER); return false; } // Prepare associative array with data from DB. $doc = \core_search\document_factory::instance($entry->id, $this->componentname, $this->areaname); $doc->set('title', $entry->concept); $doc->set('content', content_to_text($entry->definition, $entry->definitionformat)); $doc->set('contextid', $context->id); $doc->set('type', \core_search\manager::TYPE_TEXT); $doc->set('courseid', $entry->course); $doc->set('userid', $entry->userid); $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID); $doc->set('modified', $entry->timemodified); // Adding keywords as extra info. if ($keywords) { $doc->set('description1', implode(' ', $keywords)); } return $doc; }
/** * Returns the document for a particular page. * * @param \stdClass $record A record containing, at least, the indexed document id and a modified timestamp * @param array $options Options for document creation * @return \core_search\document */ public function get_document($record, $options = array()) { try { $cm = $this->get_cm('wiki', $record->wikiid, $record->courseid); $context = \context_module::instance($cm->id); } catch (\dml_missing_record_exception $ex) { // Notify it as we run here as admin, we should see everything. debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' . $ex->getMessage(), DEBUG_DEVELOPER); return false; } catch (\dml_exception $ex) { // Notify it as we run here as admin, we should see everything. debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER); return false; } // Make a page object without extra fields. $page = clone $record; unset($page->courseid); unset($page->wikiid); // Conversion based wiki_print_page_content(). // Check if we have passed the cache time. if ($page->timerendered + WIKI_REFRESH_CACHE_TIME < time()) { $content = wiki_refresh_cachedcontent($page); $page = $content['page']; } // Convert to text. $content = content_to_text($page->cachedcontent, FORMAT_MOODLE); // Prepare associative array with data from DB. $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname); $doc->set('title', content_to_text($record->title, false)); $doc->set('content', $content); $doc->set('contextid', $context->id); $doc->set('courseid', $record->courseid); $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID); $doc->set('modified', $record->timemodified); // Check if this document should be considered new. if (isset($options['lastindexedtime']) && $options['lastindexedtime'] < $record->timecreated) { // If the document was created after the last index time, it must be new. $doc->set_is_new(true); } return $doc; }
/** * Returns a document instance prepared to be rendered. * * @param \core_search\area\base $searcharea * @param array $docdata * @return \core_search\document */ protected function to_document(\core_search\area\base $searcharea, $docdata) { list($componentname, $areaname) = \core_search\manager::extract_areaid_parts($docdata['areaid']); $doc = \core_search\document_factory::instance($docdata['itemid'], $componentname, $areaname, $this); $doc->set_data_from_engine($docdata); $doc->set_doc_url($searcharea->get_doc_url($doc)); $doc->set_context_url($searcharea->get_context_url($doc)); // Uses the internal caches to get required data needed to render the document later. $course = $this->get_course($doc->get('courseid')); $doc->set_extra('coursefullname', $course->fullname); if ($doc->is_set('userid')) { $user = $this->get_user($doc->get('userid')); $doc->set_extra('userfullname', fullname($user)); } return $doc; }
/** * Returns the document associated with this activity. * * This default implementation for activities sets the activity name to title and the activity intro to * content. Any activity can overwrite this function if it is interested in setting other fields than the * default ones, or to fill description optional fields with extra stuff. * * @param stdClass $record * @param array $options * @return \core_search\document */ public function get_document($record, $options = array()) { try { $cm = $this->get_cm($this->get_module_name(), $record->id, $record->course); $context = \context_module::instance($cm->id); } catch (\dml_missing_record_exception $ex) { // Notify it as we run here as admin, we should see everything. debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' . $ex->getMessage(), DEBUG_DEVELOPER); return false; } catch (\dml_exception $ex) { // Notify it as we run here as admin, we should see everything. debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER); return false; } // Prepare associative array with data from DB. $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname); $doc->set('title', content_to_text($record->name, false)); $doc->set('content', content_to_text($record->intro, $record->introformat)); $doc->set('contextid', $context->id); $doc->set('courseid', $record->course); $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID); $doc->set('modified', $record->{static::MODIFIED_FIELD_NAME}); // Check if this document should be considered new. if (isset($options['lastindexedtime'])) { $createdfield = static::CREATED_FIELD_NAME; if (!empty($createdfield) && $options['lastindexedtime'] < $record->{$createdfield}) { // If the document was created after the last index time, it must be new. $doc->set_is_new(true); } } return $doc; }