src/ApiBundle/Api/Resource/TestpaperInfo/TestpaperInfo.php

(开头部分) 2KB

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

<?php

namespace ApiBundle\Api\Resource\TestpaperInfo;

use ApiBundle\Api\ApiRequest;
use ApiBundle\Api\Resource\AbstractResource;
use Biz\Activity\Service\ActivityService;
use Biz\Common\CommonException;
use Biz\Task\Service\TaskService;
use Biz\Task\TaskException;
use Biz\Testpaper\Service\TestpaperService;
use Biz\Testpaper\TestpaperException;
use Biz\User\UserException;

class TestpaperInfo extends AbstractResource
{
    public function get(ApiRequest $request, $testId)
    {
        $user = $this->getCurrentUser();
        if (!$user->isLogin()) {
            throw UserException::UN_LOGIN();
        }

        $testpaper = $this->getTestpaperService()->getTestpaper($testId);

        if (empty($testpaper)) {
            throw TestpaperException::NOTFOUND_TESTPAPER();
        }

        $items = $this->getTestpaperService()->showTestpaperItems($testId);
        $testpaper['metas']['question_type_seq'] = array_keys($items);
        $results = array(
            'testpaper' => $testpaper,
            'items' => $this->filterTestpaperItems($items),
        );

        $targetType = $request->query->get('targetType');
        $targetId = $request->query->get('targetId');
        if (empty($targetType) || empty($targetId)) {
            throw CommonException::ERROR_PARAMETER();
        }
        $method = 'handle'.$targetType;
        if (!method_exists($this, $method)) {
            throw CommonException::NOTFOUND_METHOD();
        }
        $this->$method($user, $testpaper, $targetId, $results);

        return $results;
    }

    protected function handleTask($user, $testpaper, $taskId, &$results)
    {
        $task = $this->getTaskService()->tryTakeTask($taskId);
        if (empty($task)) {
            throw TaskException::NOTFOUND_TASK();
        }
        $activity = $this->getActivityService()->getActivity($task['activityId'], true);
        if ('testpaper' != $activity['mediaType'] || $activity['ext']['mediaId'] != $testpaper['id']) {
            throw TestpaperException::NOT_TESTPAPER_TASK();
        }

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

AI 解读 AI

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

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