本文整理汇总了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()))));
}