Search area for block_html blocks.
More...
|
string const | CACHE_INSTANCES = 'base_block_instances' |
| Cache name used for block instances.
|
|
|
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).
|
|
Search area for block_html blocks.
- Copyright
- 2017 The Open University
- License
- http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
◆ attach_files()
block_html\search\content::attach_files |
( |
|
$document | ) |
|
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.
- Parameters
-
document | $document | The current document |
- Return values
-
Reimplemented from core_search\base.
◆ check_access()
core_search\base_block::check_access |
( |
|
$id | ) |
|
|
inherited |
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.
- Parameters
-
- Return values
-
int | manager:ACCESS_xx constant |
Reimplemented from core_search\base.
◆ clear_static()
static core_search\base_block::clear_static |
( |
| ) |
|
|
staticinherited |
◆ get_area_id()
core_search\base::get_area_id |
( |
| ) |
|
|
inherited |
Returns the area id.
- Return values
-
◆ get_block_instance()
core_search\base_block::get_block_instance |
( |
|
$id, |
|
|
|
$strictness = MUST_EXIST |
|
) |
| |
|
protectedinherited |
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).
- Parameters
-
int | $id | ID of block instance |
int | $strictness | MUST_EXIST or IGNORE_MISSING |
- Return values
-
false|mixed | Block instance data (may be false if strictness is IGNORE_MISSING) |
◆ get_block_name()
core_search\base_block::get_block_name |
( |
| ) |
|
|
inherited |
Gets the block name only.
- Return values
-
string | Block name e.g. 'html' |
◆ get_category_names()
core_search\base_block::get_category_names |
( |
| ) |
|
|
inherited |
Returns a list of category names associated with the area.
- Return values
-
Reimplemented from core_search\base.
◆ get_component_name()
core_search\base::get_component_name |
( |
| ) |
|
|
inherited |
◆ get_component_type()
core_search\base::get_component_type |
( |
| ) |
|
|
inherited |
Returns the component type.
It might be a plugintype or 'core' for core subsystems.
- Return values
-
◆ get_config()
core_search\base::get_config |
( |
| ) |
|
|
inherited |
Returns all the search area configuration.
- Return values
-
◆ get_config_var_name()
core_search\base::get_config_var_name |
( |
| ) |
|
|
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.
- Return values
-
string | Config var path including the plugin (or component) and the varname |
◆ get_context_restriction_sql()
core_search\base_block::get_context_restriction_sql |
( |
\context |
$context = null , |
|
|
|
$blocktable = 'bi' , |
|
|
|
$paramtype = SQL_PARAMS_QM |
|
) |
| |
|
protectedinherited |
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.
- Parameters
-
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) |
- Return values
-
array | Array with SQL and parameters |
- Exceptions
-
◆ get_context_url()
Returns a url to the document context.
- Parameters
-
- Return values
-
Reimplemented from core_search\base.
◆ get_contexts_to_reindex()
core_search\base_block::get_contexts_to_reindex |
( |
| ) |
|
|
inherited |
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).
- Return values
-
Iterator | Iterator of contexts to reindex |
- Exceptions
-
Reimplemented from core_search\base.
◆ get_contexts_to_reindex_extra_sql()
core_search\base_block::get_contexts_to_reindex_extra_sql |
( |
| ) |
|
|
protectedinherited |
This can be used in subclasses to change ordering within the get_contexts_to_reindex function.
It returns 2 values:
- Extra SQL joins (tables block_instances 'bi' and context 'x' already exist).
- An ORDER BY value which must use aggregate functions, by default 'MAX(bi.timemodified) DESC'.
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.
- Return values
-
string[] | Array with 2 elements; extra joins for the query, and ORDER BY value |
◆ get_course_level_context_restriction_sql()
core_search\base::get_course_level_context_restriction_sql |
( |
\context |
$context = null , |
|
|
|
$coursetable, |
|
|
|
$paramtype = SQL_PARAMS_QM |
|
) |
| |
|
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.
- Parameters
-
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) |
- Return values
-
array | Array with SQL and parameters; both null if no need to query |
- Exceptions
-
◆ get_doc_icon()
core_search\base_block::get_doc_icon |
( |
document |
$doc | ) |
|
|
inherited |
Returns an icon instance for the document.
- Parameters
-
- Return values
-
Reimplemented from core_search\base.
◆ get_doc_url()
Returns a url to the document, it might match self::get_context_url().
- Parameters
-
- Return values
-
Reimplemented from core_search\base.
◆ get_document()
block_html\search\content::get_document |
( |
|
$record, |
|
|
|
$options = array() |
|
) |
| |
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.
- Parameters
-
stdClass | $record | A record containing, at least, the indexed document id and a modified timestamp |
array | $options | Options for document creation |
- Return values
-
Reimplemented from core_search\base.
◆ get_document_display_title()
Returns the document title to display.
Allow to customize the document title string to display.
- Parameters
-
- Return values
-
string | Document title to display in the search results page |
◆ get_document_recordset()
core_search\base_block::get_document_recordset |
( |
|
$modifiedfrom = 0 , |
|
|
context |
$context = null |
|
) |
| |
|
inherited |
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.
- Parameters
-
int | $modifiedfrom | Return only records modified after this date |
context | null | $context | Context to find blocks within |
- Return values
-
false|moodle_recordset|null | |
Reimplemented from core_search\base.
◆ get_indexing_restrictions()
core_search\base_block::get_indexing_restrictions |
( |
| ) |
|
|
protectedinherited |
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 ['', []].
- Return values
-
array | 2-element array of SQL restriction and params for it |
◆ get_last_indexing_duration()
core_search\base::get_last_indexing_duration |
( |
| ) |
|
|
inherited |
Gets the length of time spent indexing this area (the last time it was indexed).
- Return values
-
int|bool | Time in seconds spent indexing this area last time, false if never indexed |
◆ get_levels()
static core_search\base::get_levels |
( |
| ) |
|
|
staticinherited |
Returns context levels property.
- Return values
-
◆ get_recordset_by_timestamp()
core_search\base::get_recordset_by_timestamp |
( |
|
$modifiedfrom = 0 | ) |
|
|
inherited |
Returns a recordset ordered by modification date ASC.
Each record can include any data self::get_document might need but it must:
- Include an 'id' field: Unique identifier (in this area's scope) of a document to index in the search engine If the indexed content field can contain embedded files, the 'id' value should match the filearea itemid.
- Only return data modified since $modifiedfrom, including $modifiedform to prevent some records from not being indexed (e.g. your-timemodified-fieldname >= $modifiedfrom)
- Order the returned data by time modified in ascending order, as core_search::manager will need to store the modified time of the last indexed document.
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.
- Parameters
-
- Return values
-
◆ get_search_fileareas()
core_search\base::get_search_fileareas |
( |
| ) |
|
|
inherited |
Return the context info required to index files for this search area.
Should be onerridden by each search area.
- Return values
-
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.
◆ get_settingnames()
static core_search\base::get_settingnames |
( |
| ) |
|
|
staticinherited |
Return a list of all required setting names.
- Return values
-
◆ get_visible_name()
core_search\base::get_visible_name |
( |
|
$lazyload = false | ) |
|
|
inherited |
Returns the area visible name.
- Parameters
-
bool | $lazyload | Usually false, unless when in admin settings. |
- Return values
-
◆ is_enabled()
core_search\base::is_enabled |
( |
| ) |
|
|
inherited |
Is the search component enabled by the system administrator?
- Return values
-
◆ is_supported_page_type_at_course_context()
static core_search\base_block::is_supported_page_type_at_course_context |
( |
|
$pagetype | ) |
|
|
staticprotectedinherited |
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.
- Parameters
-
- Return values
-
◆ supports_get_document_recordset()
core_search\base::supports_get_document_recordset |
( |
| ) |
|
|
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.
◆ uses_file_indexing()
block_html\search\content::uses_file_indexing |
( |
| ) |
|
Returns true if this area uses file indexing.
- Return values
-
Reimplemented from core_search\base.
◆ $levels
The context levels the search area is working on.
This can be overwriten by the search area if it works at multiple levels.
The documentation for this class was generated from the following file: