Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 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.

The forum module trait with additional generator helpers.

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

Defines 7 functions


Functions that are not part of a class:

helper_create_users($course, $count, $role = null)   X-Ref
Helper to create the required number of users in the specified course.
Users are enrolled as students by default.

param: stdClass $course The course object
param: integer $count The number of users to create
param: string  $role The role to assign users as
return: array The users created

helper_post_to_forum($forum, $author, $fields = array()   X-Ref
Create a new discussion and post within the specified forum, as the
specified author.

param: stdClass $forum The forum to post in
param: stdClass $author The author to post as
param: array $fields any other fields in discussion (name, message, messageformat, ...)
return: array An array containing the discussion object, and the post object

helper_update_post_time($post, $factor)   X-Ref
Update the post time for the specified post by $factor.

param: stdClass $post The post to update
param: int $factor The amount to update by

helper_update_subscription_time($user, $discussion, $factor)   X-Ref
Update the subscription time for the specified user/discussion by $factor.

param: stdClass $user The user to update
param: stdClass $discussion The discussion to update for this user
param: int $factor The amount to update by

helper_post_to_discussion($forum, $discussion, $author, array $options = [])   X-Ref
Create a new post within an existing discussion, as the specified author.

param: stdClass $forum The forum to post in
param: stdClass $discussion The discussion to post in
param: stdClass $author The author to post as
param: array $options Additional options to pass to `create_post`
return: stdClass The forum post

helper_reply_to_post($parent, $author, array $options = [])   X-Ref
Create a new post within an existing discussion, as the specified author.

param: stdClass $parent The post being replied to
param: stdClass $author The author to post as
param: array $options Additional options to pass to `create_post`
return: stdClass The forum post

get_role_id($roleshortname)   X-Ref
Gets the role id from it's shortname.

param: string $roleshortname
return: int