Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

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

H5P activity attempt object

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

Defines 1 class


Class: attempt  - X-Ref

Class attempt for H5P activity

__construct(stdClass $record)   X-Ref
Create a new attempt object.

param: stdClass $record the h5pactivity_attempts record

new_attempt(stdClass $user, stdClass $cm)   X-Ref
Create a new user attempt in a specific H5P activity.

param: stdClass $user a user record
param: stdClass $cm a course_module record
return: attempt|null a new attempt object or null if fail

last_attempt(stdClass $user, stdClass $cm)   X-Ref
Get the last user attempt in a specific H5P activity.

If no previous attempt exists, it generates a new one.

param: stdClass $user a user record
param: stdClass $cm a course_module record
return: attempt|null a new attempt object or null if some problem accured

delete_all_attempts(stdClass $cm, stdClass $user = null)   X-Ref
Wipe all attempt data for specific course_module and an optional user.

param: stdClass $cm a course_module record
param: stdClass $user a user record

delete_attempt(attempt $attempt)   X-Ref
Delete a specific attempt.

param: attempt $attempt the attempt object to delete

save_statement(statement $statement, string $subcontent = '')   X-Ref
Save a new result statement into the attempt.

It also updates the rawscore and maxscore if necessary.

param: statement $statement the xAPI statement object
param: string $subcontent = '' optional subcontent identifier
return: bool if it can save the statement into db

save()   X-Ref
Update the current attempt record into DB.

return: bool true if update is succesful

set_score(?int $rawscore, ?int $maxscore)   X-Ref
Set the attempt score.

param: int|null $rawscore the attempt rawscore
param: int|null $maxscore the attempt maxscore

set_duration(?int $duration)   X-Ref
Set the attempt duration.

param: int|null $duration the attempt duration

set_completion(?int $completion)   X-Ref
Set the attempt completion.

param: int|null $completion the attempt completion

set_success(?int $success)   X-Ref
Set the attempt success.

param: int|null $success the attempt success

delete_results()   X-Ref
Delete the current attempt results from the DB.


count_results()   X-Ref
Return de number of results stored in this attempt.

return: int the number of results stored in this attempt.

get_results()   X-Ref
Return all results stored in this attempt.

return: stdClass[] results records.

get_additionals(stdClass $definition, stdClass $context)   X-Ref
Get additional data for some interaction types.

param: stdClass $definition the statement object definition data
param: stdClass $context the statement optional context
return: string JSON encoded additional information

get_description_from_definition(stdClass $definition)   X-Ref
Extract the result description from statement object definition.

In principle, H5P package can send a multilang description but the reality
is that most activities only send the "en_US" description if any and the
activity does not have any control over it.

param: stdClass $definition the statement object definition
return: string The available description if any

get_correctpattern_from_definition(stdClass $definition)   X-Ref
Extract the correct pattern from statement object definition.

The correct pattern depends on the type of content and the plugin
has no control over it so we just store it in case that the statement
data have it.

param: stdClass $definition the statement object definition
return: string The correct pattern if any

get_attempt()   X-Ref
Return the attempt number.

return: int the attempt number

get_id()   X-Ref
Return the attempt ID.

return: int the attempt id

get_userid()   X-Ref
Return the attempt user ID.

return: int the attempt userid

get_timecreated()   X-Ref
Return the attempt H5P timecreated.

return: int the attempt timecreated

get_timemodified()   X-Ref
Return the attempt H5P timemodified.

return: int the attempt timemodified

get_h5pactivityid()   X-Ref
Return the attempt H5P activity ID.

return: int the attempt userid

get_maxscore()   X-Ref
Return the attempt maxscore.

return: int the maxscore value

get_rawscore()   X-Ref
Return the attempt rawscore.

return: int the rawscore value

get_duration()   X-Ref
Return the attempt duration.

return: int|null the duration value

get_completion()   X-Ref
Return the attempt completion.

return: int|null the completion value

get_success()   X-Ref
Return the attempt success.

return: int|null the success value

get_scaled()   X-Ref
Return the attempt scaled.

return: int|null the scaled value

get_scoreupdated()   X-Ref
Return if the attempt has been modified.

Note: adding a result only add track information unless the statement does
not specify subcontent. In this case this will update also the statement.

return: bool if the attempt score have been modified