Search moodle.org's
Developer Documentation

See Release Notes

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

Post vault class.

Copyright: 2019 Ryan Wyllie <ryan@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 551 lines (21 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: post  - X-Ref

Post vault class.

This should be the only place that accessed the database.

This class should not return any objects other than post_entity objects. The class
may contain some utility count methods which return integers.

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

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 user ID
return: string

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

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

get_from_discussion_id(stdClass $user,int $discussionid,bool $canseeprivatereplies,string $orderby = 'created ASC')   X-Ref
Get the post ids for the given discussion.

param: stdClass $user The user to check the unread count for
param: int $discussionid The discussion to load posts for
param: bool $canseeprivatereplies Whether this user can see all private replies or not
param: string $orderby Order the results
return: post_entity[]

get_from_discussion_ids(stdClass $user,array $discussionids,bool $canseeprivatereplies,string $orderby = '')   X-Ref
Get the list of posts for the given discussions.

param: stdClass $user The user to load posts for.
param: int[] $discussionids The list of discussion ids to load posts for
param: bool $canseeprivatereplies Whether this user can see all private replies or not
param: string $orderby Order the results
return: post_entity[]

get_from_filters(stdClass $user,array $filters,bool $canseeprivatereplies,string $orderby = '')   X-Ref
The method returns posts based on a set of filters.

param: stdClass $user Only used when restricting private replies
param: array $filters Export filters, valid filters are:
param: bool $canseeprivatereplies Whether this user can see all private replies or not
param: string $orderby Order the results
return: post_entity[]

get_replies_to_post(stdClass $user,post_entity $post,bool $canseeprivatereplies,string $orderby = 'created ASC')   X-Ref
Load a list of replies to the given post. This will load all descendants of the post.
That is, all direct replies and replies to those replies etc.

The return value will be a flat array of posts in the requested order.

param: stdClass    $user The user to check the unread count for
param: post_entity $post The post to load replies for
param: bool        $canseeprivatereplies Whether this user can see all private replies or not
param: string $orderby How to order the replies
return: post_entity[]

get_reply_count_for_discussion_ids(stdClass $user, array $discussionids, bool $canseeprivatereplies)   X-Ref
Get a mapping of replies to the specified discussions.

param: stdClass    $user The user to check the unread count for
param: int[]       $discussionids The list of discussions to fetch counts for
param: bool        $canseeprivatereplies Whether this user can see all private replies or not
return: int[]       The number of replies for each discussion returned in an associative array

get_reply_count_for_post_id_in_discussion_id(stdClass $user, int $postid, int $discussionid, bool $canseeprivatereplies)   X-Ref
Get a mapping of replies to the specified discussions.

param: stdClass    $user The user to check the unread count for
param: int         $postid The post to collect replies to
param: int         $discussionid The list of discussions to fetch counts for
param: bool        $canseeprivatereplies Whether this user can see all private replies or not
return: int         The number of replies for each discussion returned in an associative array

count_children_from_parent_recursively(array $postparents, int $postid)   X-Ref
Count the children whose parent matches the current record recursively.

param: array   $postparents The full mapping of posts.
param: int     $postid The ID to check for
return: int     $count

get_unread_count_for_discussion_ids(stdClass $user, array $discussionids, bool $canseeprivatereplies)   X-Ref
Get a mapping of unread post counts for the specified discussions.

param: stdClass    $user The user to fetch counts for
param: int[]       $discussionids The list of discussions to fetch counts for
param: bool        $canseeprivatereplies Whether this user can see all private replies or not
return: int[]       The count of unread posts for each discussion returned in an associative array

get_latest_posts_for_discussion_ids(stdClass $user, array $discussionids, bool $canseeprivatereplies)   X-Ref
Get a mapping of the most recent post record in each discussion based on post creation time.

param: stdClass $user
param: array $discussionids
param: bool $canseeprivatereplies
return: array

get_private_reply_sql(stdClass $user, bool $canseeprivatereplies, $posttablealias = "p")   X-Ref
Get the SQL where and additional parameters to use to restrict posts to private reply posts.

param: stdClass    $user The user to fetch counts for
param: bool        $canseeprivatereplies Whether this user can see all private replies or not
return: array       The SQL WHERE clause, and parameters to use in the SQL.

get_first_post_for_discussion_ids(array $discussionids)   X-Ref
Get a mapping of the first post in each discussion based on post creation time.

param: int[]         $discussionids The list of discussions to fetch counts for
return: post_entity[] The post object of the first post for each discussions returned in an associative array

get_posts_in_discussion_for_user_id(int $discussionid,int $userid,bool $canseeprivatereplies,string $orderby = 'created ASC')   X-Ref
Get the posts for the given user.

param: int $discussionid The discussion to fetch posts for
param: int $userid The user to fetch posts for
param: bool $canseeprivatereplies Whether this user can see all private replies or not
param: string $orderby Order the results
return: post_entity[]