src/Biz/Testpaper/Builder/TestpaperBuilder.php

(开头部分) 1KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php

namespace Biz\Testpaper\Builder;

use AppBundle\Common\ArrayToolkit;
use Codeages\Biz\Framework\Context\Biz;

class TestpaperBuilder implements TestpaperBuilderInterface
{
    protected $biz;

    public function __construct(Biz $biz)
    {
        $this->biz = $biz;
    }

    public function build($fields)
    {
        $fields = $this->filterFields($fields);

        $testpaper = $this->getTestpaperService()->createTestpaper($fields);

        $testpaperPattern = $this->getTestpaperService()->getTestpaperPattern($testpaper['pattern']);

        $testpaper['metas']['courseSetId'] = $testpaper['courseSetId'];

        $result = $testpaperPattern->getTestpaperQuestions($testpaper, $testpaper['metas']);

        if ('ok' != $result['status']) {
            throw new \RuntimeException("Build testpaper #{$result['id']} items error.");
        }

        $items = $this->createQuestionItems($result['items']);
        $this->updateTestpaperByItems($testpaper['id'], $items);

        return $testpaper;
    }

    public function canBuild($options)
    {
        $questions = $this->getQuestions($options);
        $typedQuestions = ArrayToolkit::group($questions, 'type');

        return $this->canBuildWithQuestions($options, $typedQuestions);
    }

    public function showTestItems($testId, $resultId = 0, $options = array())
    {
        $test = $this->getTestpaperService()->getTestpaperByIdAndType($testId, 'testpaper');
        $items = $this->getTestpaperService()->findItemsByTestId($test['id']);
        if (!$items) {
            return array();
        }

        $itemResults = array();
        if (!empty($resultId)) {
            $testpaperResult = $this->getTestpaperService()->getTestpaperResult($resultId);

            $itemResults = $this->getTestpaperService()->findItemResultsByResultId($testpaperResult['id'], true);
            $itemResults = ArrayToolkit::index($itemResults, 'questionId');

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。