Moodle  2.2.1
http://www.collinsharper.com
question_engine_data_mapper Class Reference

Public Member Functions

 __construct ($db=null)
 insert_questions_usage_by_activity (question_usage_by_activity $quba)
 insert_question_attempt (question_attempt $qa, $context)
 insert_question_attempt_step (question_attempt_step $step, $questionattemptid, $seq, $context)
 update_question_attempt_step (question_attempt_step $step, $questionattemptid, $seq, $context)
 load_question_attempt_step ($stepid)
 load_question_attempt ($questionattemptid)
 load_questions_usage_by_activity ($qubaid)
 load_questions_usages_latest_steps (qubaid_condition $qubaids, $slots)
 load_questions_usages_question_state_summary (qubaid_condition $qubaids, $slots)
 load_questions_usages_where_question_in_state (qubaid_condition $qubaids, $summarystate, $slot, $questionid=null, $orderby= 'random', $params, $limitfrom=0, $limitnum=null)
 load_average_marks (qubaid_condition $qubaids, $slots=null)
 load_attempts_at_question ($questionid, qubaid_condition $qubaids)
 update_questions_usage_by_activity (question_usage_by_activity $quba)
 update_question_attempt (question_attempt $qa)
 delete_questions_usage_by_activities (qubaid_condition $qubaids)
 delete_steps ($stepids, $context)
 delete_previews ($questionid)
 update_question_attempt_flag ($qubaid, $questionid, $qaid, $slot, $newstate)
 in_summary_state_test ($summarystate, $equal=true, $prefix= 'summarystates')
 set_max_mark_in_attempts (qubaid_condition $qubaids, $slot, $newmaxmark)
 sum_usage_marks_subquery ($qubaid)
 question_attempt_latest_state_view ($alias, qubaid_condition $qubaids)
 questions_in_use (array $questionids, qubaid_condition $qubaids)

Protected Member Functions

 make_step_record (question_attempt_step $step, $questionattemptid, $seq)
 insert_step_data (question_attempt_step $step, $stepid, $context)
 delete_usage_records_for_mysql (qubaid_condition $qubaids)
 delete_attempt_steps_for_mysql ($test, $params)
 delete_response_files ($contextid, $itemidstest, $params)
 full_states_to_summary_state_sql ()
 latest_step_for_qa_subquery ($questionattemptid= 'qa.id')

Protected Attributes

 $db

Detailed Description

This class controls the loading and saving of question engine data to and from the database.

Definition at line 56 of file datalib.php.


Constructor & Destructor Documentation

__construct ( db = null)
Parameters:
moodle_database$dba database connectoin. Defaults to global $DB.

Definition at line 66 of file datalib.php.


Member Function Documentation

delete_attempt_steps_for_mysql ( test,
params 
) [protected]

This function is a work-around for poor MySQL performance with DELETE FROM x WHERE id IN (SELECT ...). We have to use a non-standard syntax to get good performance. See MDL-29520.

Parameters:
string$testsql fragment.
array$paramsused by $test.

Definition at line 778 of file datalib.php.

delete_previews ( questionid)

Delete all the previews for a given question.

Parameters:
int$questionidquestion id.

Definition at line 833 of file datalib.php.

Delete a question_usage_by_activity and all its associated question_attempts and question_attempt_steps from the database.

Parameters:
qubaid_condition$qubaidsidentifies which question useages to delete.

Definition at line 713 of file datalib.php.

Here is the call graph for this function:

delete_response_files ( contextid,
itemidstest,
params 
) [protected]

Delete all the files belonging to the response variables in the gives question attempt steps.

Parameters:
int$contextidthe context these attempts belong to.
string$itemidstesta bit of SQL that can be used in a WHERE itemid $itemidstest clause. Must use named params.
array$paramsany query parameters used in $itemidstest.

Definition at line 821 of file datalib.php.

Here is the call graph for this function:

delete_steps ( stepids,
context 
)

Delete all the steps for a question attempt.

Parameters:
int$qaidsquestion_attempt id.
context$contextthe context that the $quba belongs to.

Definition at line 792 of file datalib.php.

Here is the caller graph for this function:

This function is a work-around for poor MySQL performance with DELETE FROM x WHERE id IN (SELECT ...). We have to use a non-standard syntax to get good performance. See MDL-29520.

Parameters:
qubaid_condition$qubaidsidentifies which question useages to delete.

Definition at line 759 of file datalib.php.

Here is the call graph for this function:

Get all the WHEN 'x' THEN 'y' terms needed to convert the question_attempt_steps.state column to a summary state. Use this like CASE qas.state {$this->full_states_to_summary_state_sql()} END AS summarystate,

Parameters:
stringSQL fragment.

Definition at line 868 of file datalib.php.

Here is the call graph for this function:

in_summary_state_test ( summarystate,
equal = true,
prefix = 'summarystates' 
)

Get the SQL needed to test that question_attempt_steps.state is in a state corresponding to $summarystate.

Parameters:
string$summarystateone of inprogress, needsgrading, manuallygraded or autograded
bool$equalif false, do a NOT IN test. Default true.
Returns:
string SQL fragment.

Definition at line 884 of file datalib.php.

Here is the call graph for this function:

insert_question_attempt ( question_attempt qa,
context 
)

Store an entire question_attempt in the database, including all the question_attempt_steps that comprise it.

Parameters:
question_attempt$qathe question attempt to store.
context$contextthe context of the owning question_usage_by_activity.

Definition at line 100 of file datalib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

insert_question_attempt_step ( question_attempt_step step,
questionattemptid,
seq,
context 
)

Store a question_attempt_step in the database.

Parameters:
question_attempt_step$stepthe step to store.
int$questionattemptidthe question attept id this step belongs to.
int$seqthe sequence number of this stop.
context$contextthe context of the owning question_usage_by_activity.

Definition at line 171 of file datalib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Store an entire question_usage_by_activity in the database, including all the question_attempts that comprise it.

Parameters:
question_usage_by_activity$qubathe usage to store.

Definition at line 80 of file datalib.php.

Here is the call graph for this function:

insert_step_data ( question_attempt_step step,
stepid,
context 
) [protected]

Helper method used by insert_question_attempt_step and update_question_attempt_step

Parameters:
question_attempt_step$stepthe step to store.
int$stepidthe id of the step.
context$contextthe context of the owning question_usage_by_activity.

Definition at line 150 of file datalib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

latest_step_for_qa_subquery ( questionattemptid = 'qa.id') [protected]

Definition at line 973 of file datalib.php.

load_attempts_at_question ( questionid,
qubaid_condition qubaids 
)

Load a question_attempt from the database, including all its steps.

Parameters:
int$questionidthe question to load all the attempts fors.
qubaid_condition$qubaidsused to restrict which usages are included in the query. See qubaid_condition.
Returns:
array of question_attempts.

Definition at line 613 of file datalib.php.

Here is the call graph for this function:

load_average_marks ( qubaid_condition qubaids,
slots = null 
)

Load a question_usage_by_activity from the database, including all its question_attempts and all their steps.

Parameters:
qubaid_condition$qubaidsused to restrict which usages are included in the query. See qubaid_condition.
array$slotsif null, load info for all quesitions, otherwise only load the averages for the specified questions.

Definition at line 564 of file datalib.php.

Here is the call graph for this function:

load_question_attempt ( questionattemptid)

Load a question_attempt from the database, including all its steps.

Parameters:
int$questionattemptidthe id of the question attempt to load.
question_attemptthe question attempt that was loaded.

Definition at line 240 of file datalib.php.

Here is the call graph for this function:

Load a question_attempt_step from the database.

Parameters:
int$stepidthe id of the step to load.
question_attempt_stepthe step that was loaded.

Definition at line 204 of file datalib.php.

Here is the call graph for this function:

Load a question_usage_by_activity from the database, including all its question_attempts and all their steps.

Parameters:
int$qubaidthe id of the usage to load.
question_usage_by_activitythe usage that was loaded.

Definition at line 297 of file datalib.php.

Here is the call graph for this function:

Load information about the latest state of each question from the database.

Parameters:
qubaid_condition$qubaidsused to restrict which usages are included in the query. See qubaid_condition.
array$slotsA list of slots for the questions you want to konw about.
Returns:
array of records. See the SQL in this function to see the fields available.

Definition at line 357 of file datalib.php.

Here is the call graph for this function:

Load summary information about the state of each question in a group of attempts. This is used, for example, by the quiz manual grading report, to show how many attempts at each question need to be graded.

Parameters:
qubaid_condition$qubaidsused to restrict which usages are included in the query. See qubaid_condition.
array$slotsA list of slots for the questions you want to konw about.
Returns:
array The array keys are slot,qestionid. The values are objects with fields $slot, $questionid, $inprogress, $name, $needsgrading, $autograded, $manuallygraded and $all.

Definition at line 407 of file datalib.php.

Here is the call graph for this function:

load_questions_usages_where_question_in_state ( qubaid_condition qubaids,
summarystate,
slot,
questionid = null,
orderby = 'random',
params,
limitfrom = 0,
limitnum = null 
)

Get a list of usage ids where the question with slot $slot, and optionally also with question id $questionid, is in summary state $summarystate. Also return the total count of such states.

Only a subset of the ids can be returned by using $orderby, $limitfrom and $limitnum. A special value 'random' can be passed as $orderby, in which case $limitfrom is ignored.

Parameters:
qubaid_condition$qubaidsused to restrict which usages are included in the query. See qubaid_condition.
int$slotThe slot for the questions you want to konw about.
int$questionid(optional) Only return attempts that were of this specific question.
string$summarystatethe summary state of interest, or 'all'.
string$orderbythe column to order by.
array$paramsany params required by any of the SQL fragments.
int$limitfromimplements paging of the results. Ignored if $orderby = random or $limitnum is null.
int$limitnumimplements paging of the results. null = all.
Returns:
array with two elements, an array of usage ids, and a count of the total number.

Definition at line 492 of file datalib.php.

Here is the call graph for this function:

make_step_record ( question_attempt_step step,
questionattemptid,
seq 
) [protected]

Helper method used by insert_question_attempt_step and update_question_attempt_step

Parameters:
question_attempt_step$stepthe step to store.
int$questionattemptidthe question attept id this step belongs to.
int$seqthe sequence number of this stop.
Returns:
stdClass data to insert into the database.

Definition at line 133 of file datalib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Get a subquery that returns the latest step of every qa in some qubas. Currently, this is only used by the quiz reports. See quiz_attempt_report_table::add_latest_state_join().

Parameters:
string$aliasalias to use for this inline-view.
qubaid_condition$qubaidsrestriction on which question_usages we are interested in. This is important for performance.
Returns:
array with two elements, the SQL fragment and any params requried.

Definition at line 944 of file datalib.php.

Here is the call graph for this function:

questions_in_use ( array questionids,
qubaid_condition qubaids 
)
Parameters:
array$questionidsof question ids.
qubaid_condition$qubaidsids of the usages to consider.
Returns:
boolean whether any of these questions are being used by any of those usages.

Definition at line 987 of file datalib.php.

Here is the call graph for this function:

set_max_mark_in_attempts ( qubaid_condition qubaids,
slot,
newmaxmark 
)

Change the maxmark for the question_attempt with number in usage $slot for all the specified question_attempts.

Parameters:
qubaid_condition$qubaidsSelects which usages are updated.
int$slotthe number is usage to affect.
number$newmaxmarkthe new max mark to set.

Definition at line 897 of file datalib.php.

Here is the call graph for this function:

sum_usage_marks_subquery ( qubaid)

Return a subquery that computes the sum of the marks for all the questions in a usage. Which useage to compute the sum for is controlled bu the $qubaid parameter.

See quiz_update_all_attempt_sumgrades() for an example of the usage of this method.

Parameters:
string$qubaidSQL fragment that controls which usage is summed. This will normally be the name of a column in the outer query. Not that this SQL fragment must not contain any placeholders.
Returns:
string SQL code for the subquery.

Definition at line 916 of file datalib.php.

Update a question_attempts row to refect any changes in a question_attempt (but not any of its steps).

Parameters:
question_attempt$qathe question attempt that has changed.

Definition at line 693 of file datalib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

update_question_attempt_flag ( qubaid,
questionid,
qaid,
slot,
newstate 
)

Update the flagged state of a question in the database.

Parameters:
int$qubaidthe question usage id.
int$questionidthe question id.
int$sessionidthe question_attempt id.
bool$newstatethe new state of the flag. true = flagged.

Definition at line 853 of file datalib.php.

update_question_attempt_step ( question_attempt_step step,
questionattemptid,
seq,
context 
)

Update a question_attempt_step in the database.

Parameters:
question_attempt_step$qathe step to store.
int$questionattemptidthe question attept id this step belongs to.
int$seqthe sequence number of this stop.
context$contextthe context of the owning question_usage_by_activity.

Definition at line 187 of file datalib.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Update a question_usages row to refect any changes in a usage (but not any of its question_attempts.

Parameters:
question_usage_by_activity$qubathe usage that has changed.

Definition at line 678 of file datalib.php.

Here is the call graph for this function:

Here is the caller graph for this function:


Field Documentation

$db [protected]

Definition at line 61 of file datalib.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations