Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
mod_forum\local\vaults\post Class Reference

Post vault class. More...

Inheritance diagram for mod_forum\local\vaults\post:
mod_forum\local\vaults\db_table_vault

Public Member Functions

 get_first_post_for_discussion_ids (array $discussionids)
 Get a mapping of the first post in each discussion based on post creation time.
 
 get_from_discussion_id (stdClass $user, int $discussionid, bool $canseeprivatereplies, string $orderby='created ASC')
 Get the post ids for the given discussion.
 
 get_from_discussion_ids (stdClass $user, array $discussionids, bool $canseeprivatereplies, string $orderby='')
 Get the list of posts for the given discussions.
 
 get_from_filters (stdClass $user, array $filters, bool $canseeprivatereplies, string $orderby='')
 The method returns posts based on a set of filters.
 
 get_from_id (int $id)
 Get the entity for the given id.
 
 get_from_ids (array $ids)
 Get the list of entities for the given ids.
 
 get_latest_posts_for_discussion_ids (stdClass $user, array $discussionids, bool $canseeprivatereplies)
 Get a mapping of the most recent post record in each discussion based on post creation time.
 
 get_posts_in_discussion_for_user_id (int $discussionid, int $userid, bool $canseeprivatereplies, string $orderby='created ASC')
 Get the posts for the given user.
 
 get_replies_to_post (stdClass $user, post_entity $post, bool $canseeprivatereplies, string $orderby='created ASC')
 Load a list of replies to the given post.
 
 get_reply_count_for_discussion_ids (stdClass $user, array $discussionids, bool $canseeprivatereplies)
 Get a mapping of replies to the specified discussions.
 
 get_reply_count_for_post_id_in_discussion_id (stdClass $user, int $postid, int $discussionid, bool $canseeprivatereplies)
 Get a mapping of replies to the specified discussions.
 
 get_unread_count_for_discussion_ids (stdClass $user, array $discussionids, bool $canseeprivatereplies)
 Get a mapping of unread post counts for the specified discussions.
 

Protected Member Functions

 from_db_records (array $results)
 Convert the DB records into post entities.
 
 generate_get_records_sql (string $wheresql=null, string $sortsql=null, ?int $userid=null)
 Build the SQL to be used in get_records_sql.
 
 get_db ()
 Get the moodle database.
 
 get_entity_factory ()
 Get the entity factory.
 
 get_legacy_factory ()
 Get the legacy factory.
 
 get_preprocessors ()
 Get the list of preprocessors to run on the DB record results.
 
 get_table_alias ()
 Get the table alias.
 
 transform_db_records_to_entities (array $records)
 Execute the defined preprocessors on the DB record results and then convert them into entities.
 

Detailed Description

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

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

Member Function Documentation

◆ from_db_records()

mod_forum\local\vaults\post::from_db_records ( array $results)
protected

Convert the DB records into post entities.

Parameters
array$resultsThe DB records
Return values
post_entity[]

Reimplemented from mod_forum\local\vaults\db_table_vault.

◆ generate_get_records_sql()

mod_forum\local\vaults\post::generate_get_records_sql ( string $wheresql = null,
string $sortsql = null,
?int $userid = null )
protected

Build the SQL to be used in get_records_sql.

Parameters
string | null$wheresqlWhere conditions for the SQL
string | null$sortsqlOrder by conditions for the SQL
int | null$useridThe user ID
Return values
string

Reimplemented from mod_forum\local\vaults\db_table_vault.

◆ get_db()

mod_forum\local\vaults\db_table_vault::get_db ( )
protectedinherited

Get the moodle database.

Return values
moodle_database

◆ get_entity_factory()

mod_forum\local\vaults\db_table_vault::get_entity_factory ( )
protectedinherited

Get the entity factory.

Return values
entity_factory

◆ get_first_post_for_discussion_ids()

mod_forum\local\vaults\post::get_first_post_for_discussion_ids ( array $discussionids)

Get a mapping of the first post in each discussion based on post creation time.

Parameters
int[]$discussionidsThe list of discussions to fetch counts for
Return values
post_entity[]The post object of the first post for each discussions returned in an associative array

◆ get_from_discussion_id()

mod_forum\local\vaults\post::get_from_discussion_id ( stdClass $user,
int $discussionid,
bool $canseeprivatereplies,
string $orderby = 'created ASC' )

Get the post ids for the given discussion.

Parameters
stdClass$userThe user to check the unread count for
int$discussionidThe discussion to load posts for
bool$canseeprivaterepliesWhether this user can see all private replies or not
string$orderbyOrder the results
Return values
post_entity[]

◆ get_from_discussion_ids()

mod_forum\local\vaults\post::get_from_discussion_ids ( stdClass $user,
array $discussionids,
bool $canseeprivatereplies,
string $orderby = '' )

Get the list of posts for the given discussions.

Parameters
stdClass$userThe user to load posts for.
int[]$discussionidsThe list of discussion ids to load posts for
bool$canseeprivaterepliesWhether this user can see all private replies or not
string$orderbyOrder the results
Return values
post_entity[]

◆ get_from_filters()

mod_forum\local\vaults\post::get_from_filters ( stdClass $user,
array $filters,
bool $canseeprivatereplies,
string $orderby = '' )

The method returns posts based on a set of filters.

Parameters
stdClass$userOnly used when restricting private replies
array$filtersExport filters, valid filters are:

'discussionids' => array of discussion ids eg [1,2,3] 'userids' => array of user ids eg [1,2,3] 'from' => timestamp to filter posts from this date. 'to' => timestamp to filter posts till this date.

Parameters
bool$canseeprivaterepliesWhether this user can see all private replies or not
string$orderbyOrder the results
Return values
post_entity[]

◆ get_from_id()

mod_forum\local\vaults\db_table_vault::get_from_id ( int $id)
inherited

Get the entity for the given id.

Parameters
int$idIdentifier for the entity
Return values
object|null

◆ get_from_ids()

mod_forum\local\vaults\db_table_vault::get_from_ids ( array $ids)
inherited

Get the list of entities for the given ids.

Parameters
int[]$idsIdentifiers
Return values
array

◆ get_latest_posts_for_discussion_ids()

mod_forum\local\vaults\post::get_latest_posts_for_discussion_ids ( stdClass $user,
array $discussionids,
bool $canseeprivatereplies )

Get a mapping of the most recent post record in each discussion based on post creation time.

Parameters
stdClass$user
array$discussionids
bool$canseeprivatereplies
Return values
array
Exceptions
coding_exception
dml_exception

◆ get_legacy_factory()

mod_forum\local\vaults\db_table_vault::get_legacy_factory ( )
protectedinherited

Get the legacy factory.

Return values
object

◆ get_posts_in_discussion_for_user_id()

mod_forum\local\vaults\post::get_posts_in_discussion_for_user_id ( int $discussionid,
int $userid,
bool $canseeprivatereplies,
string $orderby = 'created ASC' )

Get the posts for the given user.

Parameters
int$discussionidThe discussion to fetch posts for
int$useridThe user to fetch posts for
bool$canseeprivaterepliesWhether this user can see all private replies or not
string$orderbyOrder the results
Return values
post_entity[]

◆ get_preprocessors()

mod_forum\local\vaults\db_table_vault::get_preprocessors ( )
protectedinherited

Get the list of preprocessors to run on the DB record results.

The preprocessors should be defined using an associative array. The key used to identify the preprocessor in this list will be used to identify the value of that preprocessor in the list of results when passed to the from_db_records function.

Return values
array

Reimplemented in mod_forum\local\vaults\discussion_list, and mod_forum\local\vaults\forum.

◆ get_replies_to_post()

mod_forum\local\vaults\post::get_replies_to_post ( stdClass $user,
post_entity $post,
bool $canseeprivatereplies,
string $orderby = 'created ASC' )

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.

Parameters
stdClass$userThe user to check the unread count for
post_entity$postThe post to load replies for
bool$canseeprivaterepliesWhether this user can see all private replies or not
string$orderbyHow to order the replies
Return values
post_entity[]

◆ get_reply_count_for_discussion_ids()

mod_forum\local\vaults\post::get_reply_count_for_discussion_ids ( stdClass $user,
array $discussionids,
bool $canseeprivatereplies )

Get a mapping of replies to the specified discussions.

Parameters
stdClass$userThe user to check the unread count for
int[]$discussionidsThe list of discussions to fetch counts for
bool$canseeprivaterepliesWhether this user can see all private replies or not
Return values
int[]The number of replies for each discussion returned in an associative array

◆ get_reply_count_for_post_id_in_discussion_id()

mod_forum\local\vaults\post::get_reply_count_for_post_id_in_discussion_id ( stdClass $user,
int $postid,
int $discussionid,
bool $canseeprivatereplies )

Get a mapping of replies to the specified discussions.

Parameters
stdClass$userThe user to check the unread count for
int$postidThe post to collect replies to
int$discussionidThe list of discussions to fetch counts for
bool$canseeprivaterepliesWhether this user can see all private replies or not
Return values
intThe number of replies for each discussion returned in an associative array

◆ get_table_alias()

mod_forum\local\vaults\post::get_table_alias ( )
protected

Get the table alias.

Return values
string

Reimplemented from mod_forum\local\vaults\db_table_vault.

◆ get_unread_count_for_discussion_ids()

mod_forum\local\vaults\post::get_unread_count_for_discussion_ids ( stdClass $user,
array $discussionids,
bool $canseeprivatereplies )

Get a mapping of unread post counts for the specified discussions.

Parameters
stdClass$userThe user to fetch counts for
int[]$discussionidsThe list of discussions to fetch counts for
bool$canseeprivaterepliesWhether this user can see all private replies or not
Return values
int[]The count of unread posts for each discussion returned in an associative array

◆ transform_db_records_to_entities()

mod_forum\local\vaults\db_table_vault::transform_db_records_to_entities ( array $records)
protectedinherited

Execute the defined preprocessors on the DB record results and then convert them into entities.

Parameters
stdClass[]$recordsList of DB results
Return values
array

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