Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 39 and 401]

Entry query builder.

Copyright: 2015 Frédéric Massart - FMCorz.net
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 473 lines (16 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: mod_glossary_entry_query_builder  - X-Ref

Entry query builder class.

The purpose of this class is to avoid duplicating SQL statements to fetch entries
which are very similar with each other. This builder is not meant to be smart, it
will not out rule any previously set condition, or join, etc...

You should be using this builder just like you would be creating your SQL query. Only
some methods are shorthands to avoid logic duplication and common mistakes.

__construct($glossary = null)   X-Ref
Constructor.

param: object $glossary The glossary.

add_field($field, $table, $alias = null)   X-Ref
Add a field to select.

param: string $field The field, or *.
param: string $table The table name, without the prefix 'glossary_'.
param: string $alias An alias for the field.

add_user_fields()   X-Ref
Adds the user fields.

return: void

build_query($count = false)   X-Ref
Internal method to build the query.

param: bool $count Query to count?
return: string The SQL statement.

count_records()   X-Ref
Count the records.

return: int The number of records.

filter_by_letter($letter, $finalfield)   X-Ref
Filter a field using a letter.

param: string $letter     The letter.
param: string $finalfield The SQL statement representing the field.

filter_by_non_letter($finalfield)   X-Ref
Filter a field by special characters.

param: string $finalfield The SQL statement representing the field.

filter_by_author_letter($letter, $firstnamefirst = false)   X-Ref
Filter the author by letter.

param: string  $letter         The letter.
param: bool    $firstnamefirst Whether or not the firstname is first in the author's name.

filter_by_author_non_letter($firstnamefirst = false)   X-Ref
Filter the author by special characters.

param: bool $firstnamefirst Whether or not the firstname is first in the author's name.

filter_by_concept_letter($letter)   X-Ref
Filter the concept by letter.

param: string  $letter         The letter.

filter_by_concept_non_letter()   X-Ref
Filter the concept by special characters.

return: void

filter_by_non_approved($constant, $userid = null)   X-Ref
Filter non approved entries.

param: string $constant One of the NON_APPROVED_* constants.
param: int    $userid   The user ID when relevant, otherwise current user.

filter_by_term($term)   X-Ref
Filter by concept or alias.

This requires the alias table to be joined in the query. See {@link self::join_alias()}.

param: string $term What the concept or aliases should be.

get_fullname_field($firstnamefirst = false)   X-Ref
Convenience method to get get the SQL statement for the full name.

param: bool $firstnamefirst Whether or not the firstname is first in the author's name.
return: string The SQL statement.

get_records()   X-Ref
Get the records.

return: array

get_recordset()   X-Ref
Get the recordset.

return: moodle_recordset

get_user_from_record($record)   X-Ref
Retrieve a user object from a record.

This comes handy when {@link self::add_user_fields} was used.

param: stdClass $record The record.
return: stdClass A user object.

join_alias()   X-Ref
Join the alias table.

Note that this may cause the same entry to be returned more than once. You might want
to add a distinct on the entry id.

return: void

join_category($categoryid)   X-Ref
Join on the category tables.

Depending on the category passed the joins will be different. This is due to the display
logic that assumes that when displaying all categories the non categorised entries should
not be returned, etc...

param: int $categoryid The category ID, or GLOSSARY_SHOW_* constant.

join_user($strict = false)   X-Ref
Join the user table.

param: bool $strict When strict uses a JOIN rather than a LEFT JOIN.

limit($from, $num)   X-Ref
Limit the number of records to fetch.

param: int $from Fetch from.
param: int $num  Number to fetch.

normalize_direction($direction)   X-Ref
Normalise a direction.

This ensures that the value is either ASC or DESC.

param: string $direction The desired direction.
return: string ASC or DESC.

order_by($field, $table, $direction = '')   X-Ref
Order by a field.

param: string $field The field, or *.
param: string $table The table name, without the prefix 'glossary_'.
param: string $direction ASC, or DESC.

order_by_author($firstnamefirst = false, $direction = '')   X-Ref
Order by author name.

param: bool   $firstnamefirst Whether or not the firstname is first in the author's name.
param: string $direction ASC, or DESC.

resolve_field($field, $table)   X-Ref
Convenience method to transform a field into SQL statement.

param: string $field The field, or *.
param: string $table The table name, without the prefix 'glossary_'.
return: string SQL statement.

where($field, $table, $value)   X-Ref
Simple where conditions.

param: string $field The field, or *.
param: string $table The table name, without the prefix 'glossary_'.
param: mixed $value The value to be equal to.