本文整理匯總了PHP中question_usage_by_activity::get_attempt_iterator方法的典型用法代碼示例。如果您正苦於以下問題:PHP question_usage_by_activity::get_attempt_iterator方法的具體用法?PHP question_usage_by_activity::get_attempt_iterator怎麽用?PHP question_usage_by_activity::get_attempt_iterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類question_usage_by_activity
的用法示例。
在下文中一共展示了question_usage_by_activity::get_attempt_iterator方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: __construct
/**
* Constructor.
* @param question_usage_by_activity $quba the question usage we will be picking variants for.
* @param qubaid_condition $qubaids ids of the usages to consider when counting previous uses of each variant.
*/
public function __construct(\question_usage_by_activity $quba, \qubaid_condition $qubaids)
{
$questionidtoseed = array();
foreach ($quba->get_attempt_iterator() as $qa) {
$question = $qa->get_question();
if ($question->get_num_variants() > 1) {
$questionidtoseed[$question->id] = $question->get_variants_selection_seed();
}
}
if (empty($questionidtoseed)) {
return;
}
$this->variantsusecounts = array_fill_keys($questionidtoseed, array());
$variantsused = \question_engine::load_used_variants(array_keys($questionidtoseed), $qubaids);
foreach ($variantsused as $questionid => $usagecounts) {
$seed = $questionidtoseed[$questionid];
foreach ($usagecounts as $variant => $count) {
if (isset($this->variantsusecounts[$seed][$variant])) {
$this->variantsusecounts[$seed][$variant] += $count;
} else {
$this->variantsusecounts[$seed][$variant] = $count;
}
}
}
}
示例2: insert_questions_usage_by_activity
/**
* Store an entire {@link question_usage_by_activity} in the database,
* including all the question_attempts that comprise it.
* @param question_usage_by_activity $quba the usage to store.
*/
public function insert_questions_usage_by_activity(question_usage_by_activity $quba)
{
$record = new stdClass();
$record->contextid = $quba->get_owning_context()->id;
$record->component = $quba->get_owning_component();
$record->preferredbehaviour = $quba->get_preferred_behaviour();
$newid = $this->db->insert_record('question_usages', $record);
$quba->set_id_from_database($newid);
foreach ($quba->get_attempt_iterator() as $qa) {
$this->insert_question_attempt($qa, $quba->get_owning_context());
}
}
示例3: insert_questions_usage_by_activity
/**
* Store an entire {@link question_usage_by_activity} in the database,
* including all the question_attempts that comprise it.
*
* You should not call this method directly. You should use
* @link question_engine::save_questions_usage_by_activity()}.
*
* @param question_usage_by_activity $quba the usage to store.
*/
public function insert_questions_usage_by_activity(question_usage_by_activity $quba)
{
$record = new stdClass();
$record->contextid = $quba->get_owning_context()->id;
$record->component = $quba->get_owning_component();
$record->preferredbehaviour = $quba->get_preferred_behaviour();
$newid = $this->db->insert_record('question_usages', $record);
$quba->set_id_from_database($newid);
// Initially an array of array of question_attempt_step_objects.
// Built as a nested array for efficiency, then flattened.
$stepdata = array();
foreach ($quba->get_attempt_iterator() as $qa) {
$stepdata[] = $this->insert_question_attempt($qa, $quba->get_owning_context());
}
$stepdata = call_user_func_array('array_merge', $stepdata);
if ($stepdata) {
$this->insert_all_step_data($stepdata);
}
}