Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Class: capability  - X-Ref

Capability manager for the forum.

Defines all the business rules for what a user can and can't do in the forum.

__construct(forum_entity $forum,legacy_forum_data_mapper $forumdatamapper,legacy_discussion_data_mapper $discussiondatamapper,legacy_post_data_mapper $postdatamapper)   X-Ref
Constructor.

param: forum_entity $forum The forum entity to manage capabilities for.
param: legacy_forum_data_mapper $forumdatamapper Legacy forum data mapper
param: legacy_discussion_data_mapper $discussiondatamapper Legacy discussion data mapper
param: legacy_post_data_mapper $postdatamapper Legacy post data mapper

can_subscribe_to_forum(stdClass $user)   X-Ref
Can the user subscribe to this forum?

param: stdClass $user The user to check
return: bool

can_create_discussions(stdClass $user, int $groupid = null)   X-Ref
Can the user create discussions in this forum?

param: stdClass $user The user to check
param: int|null $groupid The current activity group id
return: bool

can_access_all_groups(stdClass $user)   X-Ref
Can the user access all groups?

param: stdClass $user The user to check
return: bool

can_access_group(stdClass $user, int $groupid)   X-Ref
Can the user access the given group?

param: stdClass $user The user to check
param: int $groupid The id of the group that the forum is set to
return: bool

can_post_to_my_groups(stdClass $user)   X-Ref
Can the user post to their groups?

param: stdClass $user The user to check
return: bool

can_view_discussions(stdClass $user)   X-Ref
Can the user view discussions in this forum?

param: stdClass $user The user to check
return: bool

can_move_discussions(stdClass $user)   X-Ref
Can the user move discussions in this forum?

param: stdClass $user The user to check
return: bool

can_pin_discussions(stdClass $user)   X-Ref
Can the user pin discussions in this forum?

param: stdClass $user The user to check
return: bool

can_split_discussions(stdClass $user)   X-Ref
Can the user split discussions in this forum?

param: stdClass $user The user to check
return: bool

can_export_discussions(stdClass $user)   X-Ref
Can the user export (see portfolios) discussions in this forum?

param: stdClass $user The user to check
return: bool

can_manually_control_post_read_status(stdClass $user)   X-Ref
Can the user manually mark posts as read/unread in this forum?

param: stdClass $user The user to check
return: bool

must_post_before_viewing_discussion(stdClass $user, discussion_entity $discussion)   X-Ref
Is the user required to post in the discussion before they can view it?

param: stdClass $user The user to check
param: discussion_entity $discussion The discussion to check
return: bool

can_subscribe_to_discussion(stdClass $user, discussion_entity $discussion)   X-Ref
Can the user subscribe to the give discussion?

param: stdClass $user The user to check
param: discussion_entity $discussion The discussion to check
return: bool

can_move_discussion(stdClass $user, discussion_entity $discussion)   X-Ref
Can the user move the discussion in this forum?

param: stdClass $user The user to check
param: discussion_entity $discussion The discussion to check
return: bool

can_pin_discussion(stdClass $user, discussion_entity $discussion)   X-Ref
Is the user pin the discussion?

param: stdClass $user The user to check
param: discussion_entity $discussion The discussion to check
return: bool

can_post_in_discussion(stdClass $user, discussion_entity $discussion)   X-Ref
Can the user post in this discussion?

param: stdClass $user The user to check
param: discussion_entity $discussion The discussion to check
return: bool

can_favourite_discussion(stdClass $user)   X-Ref
Can the user favourite the discussion

param: stdClass $user The user to check
return: bool

can_view_discussion(stdClass $user, discussion_entity $discussion)   X-Ref
Can the user view the content of a discussion?

param: stdClass $user The user to check
param: discussion_entity $discussion The discussion to check
return: bool

can_view_post(stdClass $user, discussion_entity $discussion, post_entity $post)   X-Ref
Can the user view the content of the post in this discussion?

param: stdClass $user The user to check
param: discussion_entity $discussion The discussion to check
param: post_entity $post The post the user wants to view
return: bool

can_view_post_shell(stdClass $user, post_entity $post)   X-Ref
Can the user view the post at all?
In some situations the user can view the shell of a post without being able to view its content.

param: stdClass $user The user to check
param: post_entity $post The post the user wants to view
return: bool

can_view_any_private_reply(stdClass $user)   X-Ref
Whether the user can view any private reply in the forum.

param: stdClass $user The user to check
return: bool

can_edit_post(stdClass $user, discussion_entity $discussion, post_entity $post)   X-Ref
Can the user edit the post in this discussion?

param: stdClass $user The user to check
param: discussion_entity $discussion The discussion to check
param: post_entity $post The post the user wants to edit
return: bool

validate_delete_post(stdClass $user, discussion_entity $discussion, post_entity $post,bool $hasreplies = false)   X-Ref
Verifies is the given user can delete a post.

param: stdClass $user The user to check
param: discussion_entity $discussion The discussion to check
param: post_entity $post The post the user wants to delete
param: bool $hasreplies Whether the post has replies
return: bool

can_delete_post(stdClass $user, discussion_entity $discussion, post_entity $post,bool $hasreplies = false)   X-Ref
Can the user delete the post in this discussion?

param: stdClass $user The user to check
param: discussion_entity $discussion The discussion to check
param: post_entity $post The post the user wants to delete
param: bool $hasreplies Whether the post has replies
return: bool

can_split_post(stdClass $user, discussion_entity $discussion, post_entity $post)   X-Ref
Can the user split the post in this discussion?

param: stdClass $user The user to check
param: discussion_entity $discussion The discussion to check
param: post_entity $post The post the user wants to split
return: bool

can_reply_to_post(stdClass $user, discussion_entity $discussion, post_entity $post)   X-Ref
Can the user reply to the post in this discussion?

param: stdClass $user The user to check
param: discussion_entity $discussion The discussion to check
param: post_entity $post The post the user wants to reply to
return: bool

can_reply_privately_to_post(stdClass $user, post_entity $post)   X-Ref
Can the user reply privately to the specified post?

param: stdClass $user The user to check
param: post_entity $post The post the user wants to reply to
return: bool

can_export_post(stdClass $user, post_entity $post)   X-Ref
Can the user export (see portfolios) the post in this discussion?

param: stdClass $user The user to check
param: post_entity $post The post the user wants to export
return: bool

get_forum()   X-Ref
Get the forum entity for this capability manager.

return: forum_entity

get_forum_record()   X-Ref
Get the legacy forum record for this forum.

return: stdClass

get_context()   X-Ref
Get the context for this capability manager.

return: context

get_discussion_record(discussion_entity $discussion)   X-Ref
Get the legacy discussion record for the given discussion entity.

param: discussion_entity $discussion The discussion to convert
return: stdClass

get_post_record(post_entity $post)   X-Ref
Get the legacy post record for the given post entity.

param: post_entity $post The post to convert
return: stdClass

can_view_participants(stdClass $user, discussion_entity $discussion)   X-Ref
Can the user view the participants of this discussion?

param: stdClass $user The user to check
param: discussion_entity $discussion The discussion to check
return: bool

can_view_hidden_posts(stdClass $user)   X-Ref
Can the user view hidden posts in this forum?

param: stdClass $user The user to check
return: bool

can_manage_forum(stdClass $user)   X-Ref
Can the user manage this forum?

param: stdClass $user The user to check
return: bool

can_manage_tags(stdClass $user)   X-Ref
Can the user manage tags on the site?

param: stdClass $user The user to check
return: bool

can_self_enrol(stdClass $user)   X-Ref
Checks whether the user can self enrol into the course.
Mimics the checks on the add button in deprecatedlib/forum_print_latest_discussions

param: stdClass $user
return: bool

can_export_forum(stdClass $user)   X-Ref
Checks whether the user can export the whole forum (discussions and posts).

param: stdClass $user The user object.
return: bool True if the user can export the forum or false otherwise.

can_grade(stdClass $grader, stdClass $gradee = null)   X-Ref
Check whether the supplied grader can grade the gradee.

param: stdClass $grader The user grading
param: stdClass $gradee The user being graded
return: bool