Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

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.

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

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

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

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

return: post_entity[]
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

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

return: post_entity[]
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

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

return: post_entity[]
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

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.

return: post_entity[]
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

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

return: int[]       The number of replies for each discussion returned in an associative array
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

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.

return: int         The number of replies for each discussion returned in an associative array
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

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

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

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.

return: int[]       The count of unread posts for each discussion returned in an associative array
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

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.

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

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.

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

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.

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

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.

return: post_entity[]
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