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.

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?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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?

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

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

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

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

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

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

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

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

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

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

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

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

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

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?

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

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.

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

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

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

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

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

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.

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

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?

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

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

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

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

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

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

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

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

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

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.

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

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

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

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

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

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

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

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

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

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

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

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

return: bool
param: stdClass $user

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

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

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

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