src/Biz/Testpaper/Pattern/QuestionTypePattern.php
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
<?php
namespace Biz\Testpaper\Pattern;
use AppBundle\Common\ArrayToolkit;
use Codeages\Biz\Framework\Context\Biz;
class QuestionTypePattern implements TestpaperPatternInterface
{
protected $biz;
public function __construct(Biz $biz)
{
$this->biz = $biz;
}
public function getTestpaperQuestions($testpaper, $options)
{
$questions = $this->getQuestions($options);
shuffle($questions);
$typedQuestions = ArrayToolkit::group($questions, 'type');
$canBuildResult = $this->canBuildWithQuestions($options, $typedQuestions);
if ($canBuildResult['status'] == 'no') {
return array('status' => 'error', 'missing' => $canBuildResult['missing']);
}
$items = array();
foreach ($options['counts'] as $type => $needCount) {
$needCount = intval($needCount);
if ($needCount == 0) {
continue;
}
if ($options['mode'] == 'difficulty') {
$difficultiedQuestions = ArrayToolkit::group($typedQuestions[$type], 'difficulty');
// 按难度百分比选取Question
$selectedQuestions = $this->selectQuestionsWithDifficultlyPercentage($difficultiedQuestions, $needCount, $options['percentages']);
// 选择的Question不足的话,补足
$selectedQuestions = $this->fillQuestionsToNeedCount($selectedQuestions, $typedQuestions[$type], $needCount);
$itemsOfType = $this->convertQuestionsToItems($testpaper, $selectedQuestions, $needCount, $options);
} else {
$itemsOfType = $this->convertQuestionsToItems($testpaper, $typedQuestions[$type], $needCount, $options);
}
$items = array_merge($items, $itemsOfType);
}
return array('status' => 'ok', 'items' => $items);
}
public function canBuild($options)
{
$questions = $this->getQuestions($options);
$typedQuestions = ArrayToolkit::group($questions, 'type');
return $this->canBuildWithQuestions($options, $typedQuestions);
}
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。