Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
question_engine_unit_of_work Class Reference

Implementation of the unit of work pattern for the question engine. More...

Inheritance diagram for question_engine_unit_of_work:
question_usage_observer testable_question_engine_unit_of_work

Public Member Functions

 __construct (question_usage_by_activity $quba)
 Constructor.
 
 notify_attempt_added (question_attempt $qa)
 Called when a new question attempt is added to this usage.
 
 notify_attempt_modified (question_attempt $qa)
 Called when the fields of a question attempt in this usage are modified.
 
 notify_attempt_moved (question_attempt $qa, $oldslot)
 Called when a question_attempt has been moved to a new slot.
 
 notify_metadata_added (question_attempt $qa, $name)
 Called when a new metadata variable is set on a question attempt in this usage.
 
 notify_metadata_modified (question_attempt $qa, $name)
 Called when a metadata variable on a question attempt in this usage is updated.
 
 notify_modified ()
 Called when a field of the question_usage_by_activity is changed.
 
 notify_step_added (question_attempt_step $step, question_attempt $qa, $seq)
 Called when a new step is added to a question attempt in this usage.
 
 notify_step_deleted (question_attempt_step $step, question_attempt $qa)
 Called when a new step is updated in a question attempt in this usage.
 
 notify_step_modified (question_attempt_step $step, question_attempt $qa, $seq)
 Called when a new step is updated in a question attempt in this usage.
 
 save (question_engine_data_mapper $dm)
 Write all the changes we have recorded to the database.
 

Protected Member Functions

 is_step_added (question_attempt_step $step)
 Determine if a step is new.
 
 is_step_deleted (question_attempt_step $step)
 
 is_step_modified (question_attempt_step $step)
 Determine if a step is modified.
 

Protected Attributes

question_attempt[] $attemptsadded = array()
 list of slot => that have been added to the usage.
 
question_attempt[] $attemptsdeleted = array()
 list of slot => that have been added to the usage.
 
question_attempt[] $attemptsmodified = array()
 list of slot => that were already in the usage, and which have been modified.
 
array $metadataadded = array()
 int slot => string name => question_attempt.
 
array $metadatamodified = array()
 int slot => string name => question_attempt.
 
boolean $modified = false
 whether any of the fields of the usage have been changed.
 
question_usage_by_activity $quba
 the usage being tracked.
 
array $stepsadded = array()
 of array(question_attempt_step, question_attempt id, seq number) of steps that have been added to question attempts in this usage.
 
question_attempt_step[] $stepsdeleted = array()
 list of question_attempt_step.id => question_attempt_step of steps that were previously stored in the database, but which are no longer required.
 
array $stepsmodified = array()
 of array(question_attempt_step, question_attempt id, seq number) of steps that have been modified in their attempt.
 

Detailed Description

Implementation of the unit of work pattern for the question engine.

See http://martinfowler.com/eaaCatalog/unitOfWork.html. This tracks all the changes to a question_usage_by_activity, and its constituent parts, so that the changes can be saved to the database when save() is called.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

question_engine_unit_of_work::__construct ( question_usage_by_activity $quba)

Constructor.

Parameters
question_usage_by_activity$qubathe usage to track.

Member Function Documentation

◆ is_step_added()

question_engine_unit_of_work::is_step_added ( question_attempt_step $step)
protected

Determine if a step is new.

If so get its array key.

Parameters
question_attempt_step$stepa step
Return values
int|falseif the step is in the list of steps to be added, return the key, otherwise return false.

◆ is_step_deleted()

question_engine_unit_of_work::is_step_deleted ( question_attempt_step $step)
protected
Parameters
question_attempt_step$stepa step
Return values
boolwhether the step is in the list of steps to be deleted.

◆ is_step_modified()

question_engine_unit_of_work::is_step_modified ( question_attempt_step $step)
protected

Determine if a step is modified.

If so get its array key.

Parameters
question_attempt_step$stepa step
Return values
int|falseif the step is in the list of steps to be modified, return the key, otherwise return false.

◆ notify_attempt_added()

question_engine_unit_of_work::notify_attempt_added ( question_attempt $qa)

Called when a new question attempt is added to this usage.

Parameters
question_attempt$qathe newly added question attempt.

Implements question_usage_observer.

◆ notify_attempt_modified()

question_engine_unit_of_work::notify_attempt_modified ( question_attempt $qa)

Called when the fields of a question attempt in this usage are modified.

Parameters
question_attempt$qathe newly added question attempt.

Implements question_usage_observer.

◆ notify_attempt_moved()

question_engine_unit_of_work::notify_attempt_moved ( question_attempt $qa,
$oldslot )

Called when a question_attempt has been moved to a new slot.

Parameters
question_attempt$qaThe question attempt that was moved.
int$oldslotThe previous slot number of that attempt.

Implements question_usage_observer.

◆ notify_metadata_added()

question_engine_unit_of_work::notify_metadata_added ( question_attempt $qa,
$name )

Called when a new metadata variable is set on a question attempt in this usage.

Parameters
question_attempt$qathe question attempt the metadata is being added to.
int$namethe name of the metadata variable added.

Implements question_usage_observer.

◆ notify_metadata_modified()

question_engine_unit_of_work::notify_metadata_modified ( question_attempt $qa,
$name )

Called when a metadata variable on a question attempt in this usage is updated.

Parameters
question_attempt$qathe question attempt where the metadata is being modified.
int$namethe name of the metadata variable modified.

Implements question_usage_observer.

◆ notify_modified()

question_engine_unit_of_work::notify_modified ( )

Called when a field of the question_usage_by_activity is changed.

Implements question_usage_observer.

◆ notify_step_added()

question_engine_unit_of_work::notify_step_added ( question_attempt_step $step,
question_attempt $qa,
$seq )

Called when a new step is added to a question attempt in this usage.

Parameters
question_attempt_step$stepthe new step.
question_attempt$qathe usage it is being added to.
int$seqthe sequence number of the new step.

Implements question_usage_observer.

◆ notify_step_deleted()

question_engine_unit_of_work::notify_step_deleted ( question_attempt_step $step,
question_attempt $qa )

Called when a new step is updated in a question attempt in this usage.

Parameters
question_attempt_step$stepthe step to delete.
question_attempt$qathe usage it is being added to.

Implements question_usage_observer.

◆ notify_step_modified()

question_engine_unit_of_work::notify_step_modified ( question_attempt_step $step,
question_attempt $qa,
$seq )

Called when a new step is updated in a question attempt in this usage.

Parameters
question_attempt_step$stepthe step that was updated.
question_attempt$qathe usage it is being added to.
int$seqthe sequence number of the new step.

Implements question_usage_observer.

◆ save()

question_engine_unit_of_work::save ( question_engine_data_mapper $dm)

Write all the changes we have recorded to the database.

Parameters
question_engine_data_mapper$dmthe mapper to use to update the database.

The documentation for this class was generated from the following file: