Moodle APIs
3.8
Moodle 3.8.6 (Build: 20201109)
|
Search area base class for blocks. More...
Public Member Functions | |
attach_files ($document) | |
Files related to the current document are attached, to the document object ready for indexing by Global Search. More... | |
check_access ($id) | |
Checks access for a document in this search area. More... | |
get_area_id () | |
Returns the area id. More... | |
get_block_name () | |
Gets the block name only. More... | |
get_category_names () | |
Returns a list of category names associated with the area. More... | |
get_component_name () | |
Returns the moodle component name. More... | |
get_component_type () | |
Returns the component type. More... | |
get_config () | |
Returns all the search area configuration. More... | |
get_config_var_name () | |
Returns the config var name. More... | |
get_context_url (\core_search\document $doc) | |
Returns a url to the document context. More... | |
get_contexts_to_reindex () | |
Gets a list of all contexts to reindex when reindexing this search area. More... | |
get_doc_icon (document $doc) | |
Returns an icon instance for the document. More... | |
get_doc_url (\core_search\document $doc) | |
Returns a url to the document, it might match self::get_context_url(). More... | |
get_document ($record, $options=array()) | |
Returns the document related with the provided record. More... | |
get_document_display_title (\core_search\document $doc) | |
Returns the document title to display. More... | |
get_document_recordset ($modifiedfrom=0, context $context=null) | |
Gets recordset of all blocks of this type modified since given time within the given context. More... | |
get_last_indexing_duration () | |
Gets the length of time spent indexing this area (the last time it was indexed). More... | |
get_recordset_by_timestamp ($modifiedfrom=0) | |
Returns a recordset ordered by modification date ASC. More... | |
get_search_fileareas () | |
Return the context info required to index files for this search area. More... | |
get_visible_name ($lazyload=false) | |
Returns the area visible name. More... | |
is_enabled () | |
Is the search component enabled by the system administrator? More... | |
set_enabled ($isenabled) | |
supports_get_document_recordset () | |
Checks if get_document_recordset is supported for this search area. More... | |
uses_file_indexing () | |
Returns true if this area uses file indexing. More... | |
Static Public Member Functions | |
static | clear_static () |
Clears static cache. More... | |
static | get_levels () |
Returns context levels property. More... | |
static | get_settingnames () |
Return a list of all required setting names. More... | |
Public Attributes | |
string const | CACHE_INSTANCES = 'base_block_instances' |
Cache name used for block instances. | |
Protected Member Functions | |
get_block_instance ($id, $strictness=MUST_EXIST) | |
Gets a block instance with given id. More... | |
get_context_restriction_sql (\context $context=null, $blocktable='bi', $paramtype=SQL_PARAMS_QM) | |
Helper function that gets SQL useful for restricting a search query given a passed-in context. More... | |
get_contexts_to_reindex_extra_sql () | |
This can be used in subclasses to change ordering within the get_contexts_to_reindex function. More... | |
get_course_level_context_restriction_sql (\context $context=null, $coursetable, $paramtype=SQL_PARAMS_QM) | |
Helper function that gets SQL useful for restricting a search query given a passed-in context, for data stored at course level. More... | |
get_indexing_restrictions () | |
Returns restrictions on which block_instances rows to return. More... | |
Static Protected Member Functions | |
static | is_supported_page_type_at_course_context ($pagetype) |
Checks if a page type is supported for blocks when at course (or also site) context. More... | |
Protected Attributes | |
string | $areaname = null |
The area name as defined in the class name. | |
string | $componentname = null |
The component frankenstyle name. | |
string | $componenttype = null |
The component type (core or the plugin type). | |
Static Protected Attributes | |
static array | $levels = [CONTEXT_BLOCK] |
The context levels the search area is working on. More... | |
Search area base class for blocks.
Note: Only blocks within courses are supported.
|
inherited |
Files related to the current document are attached, to the document object ready for indexing by Global Search.
The default implementation retrieves all files for the file areas returned by get_search_fileareas(). If you need to filter files to specific items per file area, you will need to override this method and explicitly provide the items.
document | $document | The current document |
void |
Reimplemented in core_search\base_activity, mod_forum\search\post, block_html\search\content, and mod_data\search\entry.
core_search\base_block::check_access | ( | $id | ) |
Checks access for a document in this search area.
If you override this function for a block, you should call this base class version first as it will check that the block is still visible to users in a supported location.
int | $id | Document id |
int | manager:ACCESS_xx constant |
Reimplemented from core_search\base.
|
static |
Clears static cache.
This function can be removed (with calls to it in the test script replaced with cache_helper::purge_all) if MDL-59427 is fixed.
|
inherited |
Returns the area id.
string |
|
protected |
Gets a block instance with given id.
Returns the fields id, pagetypepattern, subpagepattern from block_instances and also the cmid (if parent context is an activity module).
int | $id | ID of block instance |
int | $strictness | MUST_EXIST or IGNORE_MISSING |
false|mixed | Block instance data (may be false if strictness is IGNORE_MISSING) |
core_search\base_block::get_block_name | ( | ) |
Gets the block name only.
string | Block name e.g. 'html' |
core_search\base_block::get_category_names | ( | ) |
Returns a list of category names associated with the area.
array |
Reimplemented from core_search\base.
|
inherited |
Returns the moodle component name.
It might be the plugin name (whole frankenstyle name) or the core subsystem name.
string |
Reimplemented in core_user\search\user, core_course\search\section, core_course\search\customfield, and core_course\search\course.
|
inherited |
Returns the component type.
It might be a plugintype or 'core' for core subsystems.
string |
|
inherited |
Returns all the search area configuration.
array |
|
inherited |
Returns the config var name.
It depends on whether it is a moodle subsystem or a plugin as plugin-related config should remain in their own scope.
string | Config var path including the plugin (or component) and the varname |
|
protected |
Helper function that gets SQL useful for restricting a search query given a passed-in context.
The SQL returned will be one or more JOIN statements, surrounded by whitespace, which act as restrictions on the query based on the rows in the block_instances table.
We assume the block instances have already been restricted by blockname.
Returns null if there can be no results for this block within this context.
If named parameters are used, these will be named gcrs0, gcrs1, etc. The table aliases used in SQL also all begin with gcrs, to avoid conflicts.
context | null | $context | Context to restrict the query |
string | $blocktable | Alias of block_instances table |
int | $paramtype | Type of SQL parameters to use (default question mark) |
array | Array with SQL and parameters |
coding_exception | If called with invalid params |
core_search\base_block::get_context_url | ( | \core_search\document | $doc | ) |
Returns a url to the document context.
core_search\document | $doc |
moodle_url |
Reimplemented from core_search\base.
core_search\base_block::get_contexts_to_reindex | ( | ) |
Gets a list of all contexts to reindex when reindexing this search area.
For blocks, the default is to return all contexts for blocks of that type, that are on a course page, in order of time added (most recent first).
Iterator | Iterator of contexts to reindex |
moodle_exception | If any DB error |
Reimplemented from core_search\base.
|
protected |
This can be used in subclasses to change ordering within the get_contexts_to_reindex function.
It returns 2 values:
Note the query already includes a GROUP BY on the context fields, so if your joins result in multiple rows, you can use aggregate functions in the ORDER BY. See forum for an example.
string[] | Array with 2 elements; extra joins for the query, and ORDER BY value |
|
protectedinherited |
Helper function that gets SQL useful for restricting a search query given a passed-in context, for data stored at course level.
The SQL returned will be zero or more JOIN statements, surrounded by whitespace, which act as restrictions on the query based on the rows in a module table.
You can pass in a null or system context, which will both return an empty string and no params.
Returns an array with two nulls if there can be no results for a course within this context.
If named parameters are used, these will be named gclcrs0, gclcrs1, etc. The table aliases used in SQL also all begin with gclcrs, to avoid conflicts.
context | null | $context | Context to restrict the query |
string | $coursetable | Name of alias for course table e.g. 'c' |
int | $paramtype | Type of SQL parameters to use (default question mark) |
array | Array with SQL and parameters; both null if no need to query |
coding_exception | If called with invalid params |
core_search\base_block::get_doc_icon | ( | document | $doc | ) |
Returns an icon instance for the document.
core_search\document | $doc |
core_search |
Reimplemented from core_search\base.
core_search\base_block::get_doc_url | ( | \core_search\document | $doc | ) |
Returns a url to the document, it might match self::get_context_url().
core_search\document | $doc |
moodle_url |
Reimplemented from core_search\base.
|
abstractinherited |
Returns the document related with the provided record.
This method receives a record with the document id and other info returned by get_recordset_by_timestamp or get_recordset_by_contexts that might be useful here. The idea is to restrict database queries to minimum as this function will be called for each document to index. As an alternative, use cached data.
Internally it should use core_search\document to standarise the documents before sending them to the search engine.
Search areas should send plain text to the search engine, use the following function to convert any user input data to plain text: content_to_text
Valid keys for the options array are: indexfiles => File indexing is enabled if true. lastindexedtime => The last time this area was indexed. 0 if never indexed.
The lastindexedtime value is not set if indexing a specific context rather than the whole system.
stdClass | $record | A record containing, at least, the indexed document id and a modified timestamp |
array | $options | Options for document creation |
core_search |
Reimplemented in core_user\search\user, core_search\base_activity, mod_wiki\search\collaborative_page, mod_url\search\activity, mod_page\search\activity, mod_forum\search\post, mod_book\search\chapter, core_message\search\message_sent, core_message\search\message_received, core_message\search\base_message, core_course\search\section, core_course\search\customfield, core_course\search\course, block_html\search\content, mod_glossary\search\entry, and mod_data\search\entry.
|
inherited |
Returns the document title to display.
Allow to customize the document title string to display.
core_search\document | $doc |
string | Document title to display in the search results page |
core_search\base_block::get_document_recordset | ( | $modifiedfrom = 0 , |
|
context | $context = null |
||
) |
Gets recordset of all blocks of this type modified since given time within the given context.
See base class for detailed requirements. This implementation includes the key fields from block_instances.
This can be overridden to do something totally different if the block's data is stored in other tables.
If there are certain instances of the block which should not be included in the search index then you can override get_indexing_restrictions; by default this excludes rows with empty configdata.
int | $modifiedfrom | Return only records modified after this date |
context | null | $context | Context to find blocks within |
false|moodle_recordset|null |
Reimplemented from core_search\base.
|
protected |
Returns restrictions on which block_instances rows to return.
By default, excludes rows that have empty configdata.
If no restriction is required, you could return ['', []].
array | 2-element array of SQL restriction and params for it |
|
inherited |
Gets the length of time spent indexing this area (the last time it was indexed).
int|bool | Time in seconds spent indexing this area last time, false if never indexed |
|
staticinherited |
Returns context levels property.
int |
|
inherited |
Returns a recordset ordered by modification date ASC.
Each record can include any data self::get_document might need but it must:
Since Moodle 3.4, subclasses should instead implement get_document_recordset, which has an additional context parameter. This function continues to work for implementations which haven't been updated, or where the context parameter is not required.
int | $modifiedfrom |
moodle_recordset |
|
inherited |
Return the context info required to index files for this search area.
Should be onerridden by each search area.
array |
Reimplemented in core_user\search\user, core_search\base_activity, mod_workshop\search\activity, mod_wiki\search\collaborative_page, mod_resource\search\activity, mod_page\search\activity, mod_lesson\search\activity, mod_glossary\search\entry, mod_forum\search\post, mod_folder\search\activity, mod_book\search\chapter, mod_assign\search\activity, core_course\search\section, and core_course\search\course.
|
staticinherited |
Return a list of all required setting names.
array |
|
inherited |
Returns the area visible name.
bool | $lazyload | Usually false, unless when in admin settings. |
string |
|
inherited |
Is the search component enabled by the system administrator?
bool |
|
staticprotected |
Checks if a page type is supported for blocks when at course (or also site) context.
This function should be consistent with the SQL in get_recordset_by_timestamp.
string | $pagetype | Page type |
bool | True if supported |
|
inherited |
Checks if get_document_recordset is supported for this search area.
For many uses you can simply call get_document_recordset and see if it returns false, but this function is useful when you don't want to actually call the function right away.
|
inherited |
Returns true if this area uses file indexing.
bool |
Reimplemented in core_user\search\user, mod_workshop\search\activity, mod_wiki\search\collaborative_page, mod_wiki\search\activity, mod_url\search\activity, mod_survey\search\activity, mod_scorm\search\activity, mod_resource\search\activity, mod_quiz\search\activity, mod_page\search\activity, mod_lti\search\activity, mod_lesson\search\activity, mod_label\search\activity, mod_imscp\search\activity, mod_glossary\search\entry, mod_glossary\search\activity, mod_forum\search\post, mod_forum\search\activity, mod_folder\search\activity, mod_feedback\search\activity, mod_data\search\entry, mod_data\search\activity, mod_choice\search\activity, mod_chat\search\activity, mod_book\search\chapter, mod_book\search\activity, mod_assign\search\activity, core_course\search\section, core_course\search\course, and block_html\search\content.
|
staticprotected |
The context levels the search area is working on.
This can be overwriten by the search area if it works at multiple levels.