Moodle APIs
3.8
Moodle 3.8.6 (Build: 20201109)
|
Entry query builder class. More...
Public Member Functions | |
__construct ($glossary=null) | |
Constructor. More... | |
add_field ($field, $table, $alias=null) | |
Add a field to select. More... | |
add_user_fields () | |
Adds the user fields. More... | |
count_records () | |
Count the records. More... | |
filter_by_author_letter ($letter, $firstnamefirst=false) | |
Filter the author by letter. More... | |
filter_by_author_non_letter ($firstnamefirst=false) | |
Filter the author by special characters. More... | |
filter_by_concept_letter ($letter) | |
Filter the concept by letter. More... | |
filter_by_concept_non_letter () | |
Filter the concept by special characters. More... | |
filter_by_non_approved ($constant, $userid=null) | |
Filter non approved entries. More... | |
filter_by_term ($term) | |
Filter by concept or alias. More... | |
get_records () | |
Get the records. More... | |
get_recordset () | |
Get the recordset. More... | |
join_alias () | |
Join the alias table. More... | |
join_category ($categoryid) | |
Join on the category tables. More... | |
join_user ($strict=false) | |
Join the user table. More... | |
limit ($from, $num) | |
Limit the number of records to fetch. More... | |
order_by ($field, $table, $direction='') | |
Order by a field. More... | |
order_by_author ($firstnamefirst=false, $direction='') | |
Order by author name. More... | |
where ($field, $table, $value) | |
Simple where conditions. More... | |
Static Public Member Functions | |
static | get_fullname_field ($firstnamefirst=false) |
Convenience method to get get the SQL statement for the full name. More... | |
static | get_user_from_record ($record) |
Retrieve a user object from a record. More... | |
Public Attributes | |
const | ALIAS_ALIAS = 'ga' |
Alias for table glossary_alias. | |
const | ALIAS_CATEGORIES = 'gc' |
Alias for table glossary_categories. | |
const | ALIAS_ENTRIES = 'ge' |
Alias for table glossary_entries. | |
const | ALIAS_ENTRIES_CATEGORIES = 'gec' |
Alias for table glossary_entries_categories. | |
const | ALIAS_USER = 'u' |
Alias for table user. | |
const | NON_APPROVED_ALL = 'na_all' |
Including all the entries. | |
const | NON_APPROVED_NONE = 'na_none' |
Include none of the entries to approve. | |
const | NON_APPROVED_ONLY = 'na_only' |
Including only the entries to be approved. | |
const | NON_APPROVED_SELF = 'na_self' |
Including my entries to be approved. | |
Protected Member Functions | |
build_query ($count=false) | |
Internal method to build the query. More... | |
filter_by_letter ($letter, $finalfield) | |
Filter a field using a letter. More... | |
filter_by_non_letter ($finalfield) | |
Filter a field by special characters. More... | |
normalize_direction ($direction) | |
Normalise a direction. More... | |
Static Protected Member Functions | |
static | resolve_field ($field, $table) |
Convenience method to transform a field into SQL statement. More... | |
Protected Attributes | |
array | $fields = array() |
Raw SQL statements representing the fields to select. | |
string | $from |
Raw SQL statement representing the FROM clause. | |
object | $glossary |
The glossary we are fetching from. | |
array | $joins = array() |
Raw SQL statements representing the JOINs to make. | |
int | $limitfrom = 0 |
The number of records to fetch from. | |
int | $limitnum = 0 |
The number of records to fetch. | |
array | $order = array() |
Raw SQL statements representing the ORDER clause. | |
array | $params = array() |
List of SQL parameters. | |
array | $where = array() |
Raw SQL statements representing the WHERE clause. | |
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.
mod_glossary_entry_query_builder::__construct | ( | $glossary = null | ) |
Constructor.
object | $glossary | The glossary. |
mod_glossary_entry_query_builder::add_field | ( | $field, | |
$table, | |||
$alias = null |
|||
) |
Add a field to select.
string | $field | The field, or *. |
string | $table | The table name, without the prefix 'glossary_'. |
string | $alias | An alias for the field. |
mod_glossary_entry_query_builder::add_user_fields | ( | ) |
Adds the user fields.
void |
|
protected |
Internal method to build the query.
bool | $count | Query to count? |
string | The SQL statement. |
mod_glossary_entry_query_builder::count_records | ( | ) |
Count the records.
int | The number of records. |
mod_glossary_entry_query_builder::filter_by_author_letter | ( | $letter, | |
$firstnamefirst = false |
|||
) |
Filter the author by letter.
string | $letter | The letter. |
bool | $firstnamefirst | Whether or not the firstname is first in the author's name. |
mod_glossary_entry_query_builder::filter_by_author_non_letter | ( | $firstnamefirst = false | ) |
Filter the author by special characters.
bool | $firstnamefirst | Whether or not the firstname is first in the author's name. |
mod_glossary_entry_query_builder::filter_by_concept_letter | ( | $letter | ) |
Filter the concept by letter.
string | $letter | The letter. |
mod_glossary_entry_query_builder::filter_by_concept_non_letter | ( | ) |
Filter the concept by special characters.
void |
|
protected |
Filter a field using a letter.
string | $letter | The letter. |
string | $finalfield | The SQL statement representing the field. |
mod_glossary_entry_query_builder::filter_by_non_approved | ( | $constant, | |
$userid = null |
|||
) |
Filter non approved entries.
string | $constant | One of the NON_APPROVED_* constants. |
int | $userid | The user ID when relevant, otherwise current user. |
|
protected |
Filter a field by special characters.
string | $finalfield | The SQL statement representing the field. |
mod_glossary_entry_query_builder::filter_by_term | ( | $term | ) |
Filter by concept or alias.
This requires the alias table to be joined in the query. See self::join_alias().
string | $term | What the concept or aliases should be. |
|
static |
Convenience method to get get the SQL statement for the full name.
bool | $firstnamefirst | Whether or not the firstname is first in the author's name. |
string | The SQL statement. |
mod_glossary_entry_query_builder::get_records | ( | ) |
Get the records.
array |
mod_glossary_entry_query_builder::get_recordset | ( | ) |
Get the recordset.
moodle_recordset |
|
static |
Retrieve a user object from a record.
This comes handy when self::add_user_fields was used.
stdClass | $record | The record. |
stdClass | A user object. |
mod_glossary_entry_query_builder::join_alias | ( | ) |
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.
void |
mod_glossary_entry_query_builder::join_category | ( | $categoryid | ) |
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...
int | $categoryid | The category ID, or GLOSSARY_SHOW_* constant. |
mod_glossary_entry_query_builder::join_user | ( | $strict = false | ) |
Join the user table.
bool | $strict | When strict uses a JOIN rather than a LEFT JOIN. |
mod_glossary_entry_query_builder::limit | ( | $from, | |
$num | |||
) |
Limit the number of records to fetch.
int | $from | Fetch from. |
int | $num | Number to fetch. |
|
protected |
Normalise a direction.
This ensures that the value is either ASC or DESC.
string | $direction | The desired direction. |
string | ASC or DESC. |
mod_glossary_entry_query_builder::order_by | ( | $field, | |
$table, | |||
$direction = '' |
|||
) |
Order by a field.
string | $field | The field, or *. |
string | $table | The table name, without the prefix 'glossary_'. |
string | $direction | ASC, or DESC. |
mod_glossary_entry_query_builder::order_by_author | ( | $firstnamefirst = false , |
|
$direction = '' |
|||
) |
Order by author name.
bool | $firstnamefirst | Whether or not the firstname is first in the author's name. |
string | $direction | ASC, or DESC. |
|
staticprotected |
Convenience method to transform a field into SQL statement.
string | $field | The field, or *. |
string | $table | The table name, without the prefix 'glossary_'. |
string | SQL statement. |
mod_glossary_entry_query_builder::where | ( | $field, | |
$table, | |||
$value | |||
) |
Simple where conditions.
string | $field | The field, or *. |
string | $table | The table name, without the prefix 'glossary_'. |
mixed | $value | The value to be equal to. |