Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Search area base class for blocks. Note: Only blocks within courses are supported.

Copyright: 2017 The Open University
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 420 lines (18 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: base_block  - X-Ref

Search area base class for blocks.

Note: Only blocks within courses are supported.

get_block_name()   X-Ref
Gets the block name only.

return: string Block name e.g. 'html'

get_indexing_restrictions()   X-Ref
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: array 2-element array of SQL restriction and params for it

get_document_recordset($modifiedfrom = 0, \context $context = null)   X-Ref
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.

return: false|\moodle_recordset|null
param: int $modifiedfrom Return only records modified after this date
param: \context|null $context Context to find blocks within

get_doc_url(\core_search\document $doc)   X-Ref
No description

get_context_url(\core_search\document $doc)   X-Ref
No description

check_access($id)   X-Ref
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.

return: int manager:ACCESS_xx constant
param: int $id Document id

is_supported_page_type_at_course_context($pagetype)   X-Ref
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.

return: bool True if supported
param: string $pagetype Page type

get_block_instance($id, $strictness = MUST_EXIST)   X-Ref
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).

return: false|mixed Block instance data (may be false if strictness is IGNORE_MISSING)
param: int $id ID of block instance
param: int $strictness MUST_EXIST or IGNORE_MISSING

clear_static()   X-Ref
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.


get_context_restriction_sql(\context $context = null, $blocktable = 'bi',$paramtype = SQL_PARAMS_QM)   X-Ref
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.

return: array Array with SQL and parameters
param: \context|null $context Context to restrict the query
param: string $blocktable Alias of block_instances table
param: int $paramtype Type of SQL parameters to use (default question mark)

get_contexts_to_reindex_extra_sql()   X-Ref
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: string[] Array with 2 elements; extra joins for the query, and ORDER BY value

get_contexts_to_reindex()   X-Ref
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: \Iterator Iterator of contexts to reindex

get_doc_icon(document $doc)   X-Ref
Returns an icon instance for the document.

return: \core_search\document_icon
param: \core_search\document $doc

get_category_names()   X-Ref
Returns a list of category names associated with the area.

return: array