Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

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

Vault class for a discussion list.

Copyright: 2019 Andrew Nicols <andrew@nicols.co.uk>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 564 lines (22 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: discussion_list  - X-Ref

Discussion list vault.

This should be the only place that accessed the database.

This uses the repository pattern. See:
https://designpatternsphp.readthedocs.io/en/latest/More/Repository/README.html

get_table_alias()   X-Ref
Get the table alias.

return: string

get_favourite_alias()   X-Ref
Get the favourite table alias

return: string

generate_get_records_sql(string $wheresql = null, ?string $sortsql = null, ?int $userid = null)   X-Ref
Build the SQL to be used in get_records_sql.

param: string|null $wheresql Where conditions for the SQL
param: string|null $sortsql Order by conditions for the SQL
param: int|null $userid The ID of the user we are performing this query for
return: string

generate_count_records_sql(string $wheresql = null)   X-Ref
Build the SQL to be used in count_records_sql.

param: string|null $wheresql Where conditions for the SQL
return: string

get_preprocessors()   X-Ref
Get a list of preprocessors to execute on the DB results before being converted
into entities.

return: array

from_db_records(array $results)   X-Ref
Convert the DB records into discussion list entities.

param: array $results The DB records
return: discussion_list[]

get_keyfield(?int $sortmethod)   X-Ref
Get the field to sort by.

param: int|null $sortmethod
return: string

get_sort_direction(?int $sortmethod)   X-Ref
Get the sort direction.

param: int|null $sortmethod
return: string

get_sort_order(?int $sortmethod, bool $includefavourites = true)   X-Ref
Get the sort order SQL for a sort method.

param: int|null  $sortmethod
param: bool|null $includefavourites
return: string

get_hidden_post_sql(bool $includehiddendiscussions, ?int $includepostsforuser)   X-Ref
Fetch any required SQL to respect timed posts.

param: bool        $includehiddendiscussions Whether to include hidden discussions or not
param: int|null    $includepostsforuser Which user to include posts for, if any
return: array       The SQL and parameters to include

get_from_forum_id(int $forumid,bool $includehiddendiscussions,?int $includepostsforuser,?int $sortorder,int $limit,int $offset)   X-Ref
Get each discussion, first post, first and last post author for the given forum, considering timed posts, and
pagination.

param: int         $forumid The forum to fetch the discussion set for
param: bool        $includehiddendiscussions Whether to include hidden discussions or not
param: int|null    $includepostsforuser Which user to include posts for, if any
param: int         $sortorder The sort order to use
param: int         $limit The number of discussions to fetch
param: int         $offset The record offset
return: array       The set of data fetched

get_from_forum_id_and_group_id(int $forumid,array $groupids,bool $includehiddendiscussions,?int $includepostsforuser,?int $sortorder,int $limit,int $offset)   X-Ref
Get each discussion, first post, first and last post author for the given forum, and the set of groups to display
considering timed posts, and pagination.

param: int         $forumid The forum to fetch the discussion set for
param: int[]       $groupids The list of real groups to filter on
param: bool        $includehiddendiscussions Whether to include hidden discussions or not
param: int|null    $includepostsforuser Which user to include posts for, if any
param: int         $sortorder The sort order to use
param: int         $limit The number of discussions to fetch
param: int         $offset The record offset
return: array       The set of data fetched

get_total_discussion_count_from_forum_id(int $forumid,bool $includehiddendiscussions,?int $includepostsforuser)   X-Ref
Count the number of discussions in the forum.

param: int $forumid Id of the forum to count discussions in
param: bool $includehiddendiscussions Include hidden dicussions in the count?
param: int|null $includepostsforuser Include discussions created by this user in the count
return: int

get_total_discussion_count_from_forum_id_and_group_id(int $forumid,array $groupids,bool $includehiddendiscussions,?int $includepostsforuser)   X-Ref
Count the number of discussions in all groups and the list of groups provided.

param: int $forumid Id of the forum to count discussions in
param: int[] $groupids List of group ids to include in the count (discussions in all groups will always be counted)
param: bool $includehiddendiscussions Include hidden dicussions in the count?
param: int|null $includepostsforuser Include discussions created by this user in the count
return: int

get_favourite_sql(int $userid)   X-Ref
Get the standard favouriting sql.

param: int $userid The ID of the user we are getting the sql for
return: [$sql, $params] An array comprising of the sql and any associated params