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.

Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400]

H5P activity manager class

Copyright: 2020 Ferran Recio <ferran@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 574 lines (20 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: manager  - X-Ref

Class manager for H5P activity

__construct(cm_info $coursemodule, stdClass $instance)   X-Ref
Class contructor.

param: cm_info $coursemodule course module info object
param: stdClass $instance H5Pactivity instance object.

create_from_instance(stdClass $instance)   X-Ref
Create a manager instance from an instance record.

return: manager
param: stdClass $instance a h5pactivity record

create_from_coursemodule($coursemodule)   X-Ref
Create a manager instance from an course_modules record.

return: manager
param: stdClass|cm_info $coursemodule a h5pactivity record

get_grading_methods()   X-Ref
Return the available grading methods.

return: string[] an array "option value" => "option description"

get_selected_attempt()   X-Ref
Return the selected attempt criteria.

return: string[] an array "grademethod value", "attempt description"

get_review_modes()   X-Ref
Return the available review modes.

return: string[] an array "option value" => "option description"

is_tracking_enabled(stdClass $user = null)   X-Ref
Check if tracking is enabled in a particular h5pactivity for a specific user.

return: bool if tracking is enabled in this activity
param: stdClass|null $user user record (default $USER)

can_view_all_attempts(stdClass $user = null)   X-Ref
Check if a user can see the activity attempts list.

return: bool if the user can see the attempts link
param: stdClass|null $user user record (default $USER)

can_view_own_attempts(stdClass $user = null)   X-Ref
Check if a user can see own attempts.

return: bool if the user can see the own attempts link
param: stdClass|null $user user record (default $USER)

get_users_scaled_score(int $userid = 0)   X-Ref
Return a relation of userid and the valid attempt's scaled score.

The returned elements contain a record
of userid, scaled value, attemptid and timemodified. In case the grading method is "GRADEAVERAGEATTEMPT"
the attemptid will be zero. In case that tracking is disabled or grading method is "GRADEMANUAL"
the method will return null.

return: array|null of userid, scaled value and, if exists, the attempt id
param: int $userid a specific userid or 0 for all user attempts.

count_attempts(int $userid = null)   X-Ref
Count the activity completed attempts.

If no user is provided the method will count all active users attempts.
Check get_active_users_join PHPdoc to a more detailed description of "active users".

return: int the total amount of attempts
param: int|null $userid optional user id (default null)

get_active_users_join(bool $allpotentialusers = false, $currentgroup = false)   X-Ref
Return the join to collect all activity active users.

The concept of active user is relative to the activity permissions. All users with
"mod/h5pactivity:view" are potential users but those with "mod/h5pactivity:reviewattempts"
are evaluators and they don't count as valid submitters.

Note that, in general, the active list has the same effect as checking for "mod/h5pactivity:submit"
but submit capability cannot be used because is a write capability and does not apply to frozen contexts.

return: sql_join the active users attempts join
param: bool $allpotentialusers if true, the join will return all active users, not only the ones with attempts.
param: int|bool $currentgroup False if groups not used, 0 for all groups, group id (int) to filter by specific group

count_users_attempts()   X-Ref
Return an array of all users and it's total attempts.

Note: this funciton only returns the list of users with attempts,
it does not check all participants.

return: array indexed count userid => total number of attempts

get_context()   X-Ref
Return the current context.

return: context_module

get_instance()   X-Ref
Return the current instance.

return: stdClass the instance record

get_coursemodule()   X-Ref
Return the current cm_info.

return: cm_info the course module

get_grader()   X-Ref
Return the specific grader object for this activity.

return: grader

get_report(int $userid = null, int $attemptid = null, $currentgroup = false)   X-Ref
Return the suitable report to show the attempts.

This method controls the access to the different reports
the activity have.

return: report|null available report (or null if no report available)
param: int $userid an opional userid to show
param: int $attemptid an optional $attemptid to show
param: int|bool $currentgroup False if groups not used, 0 for all groups, group id (int) to filter by specific group

get_attempt(int $attemptid)   X-Ref
Return a single attempt.

return: attempt
param: int $attemptid the attempt id

get_user_attempts(int $userid)   X-Ref
Return an array of all user attempts (including incompleted)

return: attempt[]
param: int $userid the user id

set_module_viewed(stdClass $course)   X-Ref
Trigger module viewed event and set the module viewed for completion.

return: void
param: stdClass $course course object