Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
mod_glossary_entry_query_builder Class Reference

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.
 

Detailed Description

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.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Since
Moodle 3.1

Constructor & Destructor Documentation

◆ __construct()

mod_glossary_entry_query_builder::__construct (   $glossary = null)

Constructor.

Parameters
object$glossaryThe glossary.

Member Function Documentation

◆ add_field()

mod_glossary_entry_query_builder::add_field (   $field,
  $table,
  $alias = null 
)

Add a field to select.

Parameters
string$fieldThe field, or *.
string$tableThe table name, without the prefix 'glossary_'.
string$aliasAn alias for the field.

◆ add_user_fields()

mod_glossary_entry_query_builder::add_user_fields ( )

Adds the user fields.

Return values
void

◆ build_query()

mod_glossary_entry_query_builder::build_query (   $count = false)
protected

Internal method to build the query.

Parameters
bool$countQuery to count?
Return values
stringThe SQL statement.

◆ count_records()

mod_glossary_entry_query_builder::count_records ( )

Count the records.

Return values
intThe number of records.

◆ filter_by_author_letter()

mod_glossary_entry_query_builder::filter_by_author_letter (   $letter,
  $firstnamefirst = false 
)

Filter the author by letter.

Parameters
string$letterThe letter.
bool$firstnamefirstWhether or not the firstname is first in the author's name.

◆ filter_by_author_non_letter()

mod_glossary_entry_query_builder::filter_by_author_non_letter (   $firstnamefirst = false)

Filter the author by special characters.

Parameters
bool$firstnamefirstWhether or not the firstname is first in the author's name.

◆ filter_by_concept_letter()

mod_glossary_entry_query_builder::filter_by_concept_letter (   $letter)

Filter the concept by letter.

Parameters
string$letterThe letter.

◆ filter_by_concept_non_letter()

mod_glossary_entry_query_builder::filter_by_concept_non_letter ( )

Filter the concept by special characters.

Return values
void

◆ filter_by_letter()

mod_glossary_entry_query_builder::filter_by_letter (   $letter,
  $finalfield 
)
protected

Filter a field using a letter.

Parameters
string$letterThe letter.
string$finalfieldThe SQL statement representing the field.

◆ filter_by_non_approved()

mod_glossary_entry_query_builder::filter_by_non_approved (   $constant,
  $userid = null 
)

Filter non approved entries.

Parameters
string$constantOne of the NON_APPROVED_* constants.
int$useridThe user ID when relevant, otherwise current user.

◆ filter_by_non_letter()

mod_glossary_entry_query_builder::filter_by_non_letter (   $finalfield)
protected

Filter a field by special characters.

Parameters
string$finalfieldThe SQL statement representing the field.

◆ filter_by_term()

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().

Parameters
string$termWhat the concept or aliases should be.

◆ get_fullname_field()

static mod_glossary_entry_query_builder::get_fullname_field (   $firstnamefirst = false)
static

Convenience method to get get the SQL statement for the full name.

Parameters
bool$firstnamefirstWhether or not the firstname is first in the author's name.
Return values
stringThe SQL statement.

◆ get_records()

mod_glossary_entry_query_builder::get_records ( )

Get the records.

Return values
array

◆ get_recordset()

mod_glossary_entry_query_builder::get_recordset ( )

Get the recordset.

Return values
moodle_recordset

◆ get_user_from_record()

static mod_glossary_entry_query_builder::get_user_from_record (   $record)
static

Retrieve a user object from a record.

This comes handy when self::add_user_fields was used.

Parameters
stdClass$recordThe record.
Return values
stdClassA user object.

◆ join_alias()

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.

Return values
void

◆ join_category()

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...

Parameters
int$categoryidThe category ID, or GLOSSARY_SHOW_* constant.

◆ join_user()

mod_glossary_entry_query_builder::join_user (   $strict = false)

Join the user table.

Parameters
bool$strictWhen strict uses a JOIN rather than a LEFT JOIN.

◆ limit()

mod_glossary_entry_query_builder::limit (   $from,
  $num 
)

Limit the number of records to fetch.

Parameters
int$fromFetch from.
int$numNumber to fetch.

◆ normalize_direction()

mod_glossary_entry_query_builder::normalize_direction (   $direction)
protected

Normalise a direction.

This ensures that the value is either ASC or DESC.

Parameters
string$directionThe desired direction.
Return values
stringASC or DESC.

◆ order_by()

mod_glossary_entry_query_builder::order_by (   $field,
  $table,
  $direction = '' 
)

Order by a field.

Parameters
string$fieldThe field, or *.
string$tableThe table name, without the prefix 'glossary_'.
string$directionASC, or DESC.

◆ order_by_author()

mod_glossary_entry_query_builder::order_by_author (   $firstnamefirst = false,
  $direction = '' 
)

Order by author name.

Parameters
bool$firstnamefirstWhether or not the firstname is first in the author's name.
string$directionASC, or DESC.

◆ resolve_field()

static mod_glossary_entry_query_builder::resolve_field (   $field,
  $table 
)
staticprotected

Convenience method to transform a field into SQL statement.

Parameters
string$fieldThe field, or *.
string$tableThe table name, without the prefix 'glossary_'.
Return values
stringSQL statement.

◆ where()

mod_glossary_entry_query_builder::where (   $field,
  $table,
  $value 
)

Simple where conditions.

Parameters
string$fieldThe field, or *.
string$tableThe table name, without the prefix 'glossary_'.
mixed$valueThe value to be equal to.

The documentation for this class was generated from the following file: