本文整理匯總了PHP中question_engine::load_used_variants方法的典型用法代碼示例。如果您正苦於以下問題:PHP question_engine::load_used_variants方法的具體用法?PHP question_engine::load_used_variants怎麽用?PHP question_engine::load_used_variants使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類question_engine
的用法示例。
在下文中一共展示了question_engine::load_used_variants方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: test_load_used_variants
public function test_load_used_variants()
{
$this->resetAfterTest();
$generator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat = $generator->create_question_category();
$questiondata1 = $generator->create_question('shortanswer', null, array('category' => $cat->id));
$questiondata2 = $generator->create_question('shortanswer', null, array('category' => $cat->id));
$questiondata3 = $generator->create_question('shortanswer', null, array('category' => $cat->id));
$quba = question_engine::make_questions_usage_by_activity('test', context_system::instance());
$quba->set_preferred_behaviour('deferredfeedback');
$question1 = question_bank::load_question($questiondata1->id);
$question3 = question_bank::load_question($questiondata3->id);
$quba->add_question($question1);
$quba->add_question($question1);
$quba->add_question($question3);
$quba->start_all_questions();
question_engine::save_questions_usage_by_activity($quba);
$this->assertEquals(array($questiondata1->id => array(1 => 2), $questiondata2->id => array(), $questiondata3->id => array(1 => 1)), question_engine::load_used_variants(array($questiondata1->id, $questiondata2->id, $questiondata3->id), new qubaid_list(array($quba->get_id()))));
}