src/Biz/Testpaper/Builder/HomeworkBuilder.php

(开头部分) 1KB

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

<?php

namespace Biz\Testpaper\Builder;

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

class HomeworkBuilder implements TestpaperBuilderInterface
{
    protected $biz;

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

    public function build($fields)
    {
        if (!isset($fields['questionIds'])) {
            throw CommonException::ERROR_PARAMETER_MISSING();
        }
        $questionIds = $fields['questionIds'];

        $fields['status'] = 'open';
        $fields['pattern'] = 'questionType';
        $fields['type'] = 'homework';

        $fields = $this->filterFields($fields);

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

        $this->createQuestionItems($homework['id'], $questionIds);

        return $homework;
    }

    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, 'homework');
        $items = $this->getTestpaperService()->findItemsByTestId($test['id']);
        if (!$items) {
            return array();
        }

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

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

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

AI 解读 AI

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

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