Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]

Exported post builder class.

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

Defines 1 class


Class: exported_posts  - X-Ref

Exported post builder class.

This class is an implementation of the builder pattern (loosely). It is responsible
for taking a set of related forums, discussions, and posts and generate the exported
version of the posts.

It encapsulates the complexity involved with exporting posts. All of the relevant
additional resources will be loaded by this class in order to ensure the exporting
process can happen.

See this doc for more information on the builder pattern:
https://designpatternsphp.readthedocs.io/en/latest/Creational/Builder/README.html

__construct(renderer_base $renderer,legacy_data_mapper_factory $legacydatamapperfactory,exporter_factory $exporterfactory,vault_factory $vaultfactory,rating_manager $ratingmanager)   X-Ref
Constructor.

param: renderer_base $renderer Core renderer
param: legacy_data_mapper_factory $legacydatamapperfactory Legacy data mapper factory
param: exporter_factory $exporterfactory Exporter factory
param: vault_factory $vaultfactory Vault factory
param: rating_manager $ratingmanager Rating manager

build(stdClass $user,array $forums,array $discussions,array $posts)   X-Ref
Build the exported posts for a given set of forums, discussions, and posts.

This will typically be used for a list of posts in the same discussion/forum however
it does support exporting any arbitrary list of posts as long as the caller also provides
a unique list of all discussions for the list of posts and all forums for the list of discussions.

Increasing the number of different forums being processed will increase the processing time
due to processing multiple contexts (for things like capabilities, files, etc). The code attempts
to load the additional resources as efficiently as possible but there is no way around some of
the additional overhead.

Note: Some posts will be removed as part of the build process according to capabilities.
A one-to-one mapping should not be expected.

param: stdClass $user The user to export the posts for.
param: forum_entity[] $forums A list of all forums that each of the $discussions belong to
param: discussion_entity[] $discussions A list of all discussions that each of the $posts belong to
param: post_entity[] $posts The list of posts to export.
return: stdClass[] List of exported posts in the same order as the $posts array.

group_posts_by_discussion(array $forums, array $discussions, array $posts)   X-Ref
Group the posts by which discussion they belong to in order for them to be processed
in chunks by the exporting.

Returns a list of groups where each group has a forum, discussion, and list of posts.
E.g.
[
[
'forum' => <forum_entity>,
'discussion' => <discussion_entity>,
'posts' => [
<post_entity in discussion>,
<post_entity in discussion>,
<post_entity in discussion>
]
]
]

param: forum_entity[] $forums A list of all forums that each of the $discussions belong to, indexed by id.
param: discussion_entity[] $discussions A list of all discussions that each of the $posts belong to, indexed by id.
param: post_entity[] $posts The list of posts to process.
return: array List of grouped posts. Each group has a discussion, forum, and posts.

get_authors_for_posts(array $posts)   X-Ref
Load the list of authors for the given posts.

The list of authors will be indexed by the author id.

param: post_entity[] $posts The list of posts to process.
return: author_entity[]

get_author_context_ids(array $authorids)   X-Ref
Get the user context ids for each of the authors.

param: int[] $authorids The list of author ids to fetch context ids for.
return: int[] Context ids indexed by author id

get_attachments_for_posts(array $groupedposts)   X-Ref
Load the list of all attachments for the posts. The list of attachments will be
indexed by the post id.

param: array $groupedposts List of posts grouped by discussions.
return: stored_file[]

get_author_groups_from_posts(array $groupedposts)   X-Ref
Get the groups for each author of the given posts.

The results are grouped by course and then author id because the groups are
contextually related to the course, e.g. a single author can be part of two different
sets of groups in two different courses.

param: array $groupedposts List of posts grouped by discussions.
return: array List of groups indexed by forum id and then author id.

get_tags_from_posts(array $posts)   X-Ref
Get the list of tags for each of the posts. The tags will be returned in an
array indexed by the post id.

param: post_entity[] $posts The list of posts to load tags for.
return: array Sets of tags indexed by post id.

get_ratings_from_posts(stdClass $user, array $groupedposts)   X-Ref
Get the list of ratings for each post. The ratings are returned in an array
indexed by the post id.

param: stdClass $user The user viewing the ratings.
param: array $groupedposts List of posts grouped by discussions.
return: array Sets of ratings indexed by post id.

get_read_receipts_from_posts(stdClass $user, array $groupedposts)   X-Ref
Get the read receipt collections for the given viewing user and each forum. The
receipt collections will only be loaded for posts in forums that the user is tracking.

The receipt collections are returned in an array indexed by the forum ids.

param: stdClass $user The user viewing the posts.
param: array $groupedposts List of posts grouped by discussions.

sort_exported_posts(array $posts, array $exportedposts)   X-Ref
Sort the list of exported posts back into the same order as the given posts.
The ordering of the exported posts can often deviate from the given posts due
to the process of exporting them so we need to sort them back into the order
that the calling code expected.

param: post_entity[] $posts The posts in the expected order.
param: stdClass[] $exportedposts The list of exported posts in any order.
return: stdClass[] Sorted exported posts.