api/src/Topxia/Api/Resource/HomeworkResult.php

(开头部分) 1KB

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

<?php

namespace Topxia\Api\Resource;

use Silex\Application;
use AppBundle\Common\ArrayToolkit;
use Symfony\Component\HttpFoundation\Request;

class HomeworkResult extends BaseResource
{
    public function post(Application $app, Request $request, $homeworkId)
    {
        //answer结构是否一致
        $answers = $request->request->all();
        $answers['usedTime'] = 0;

        $homework = $this->getTestpaperService()->getTestpaperByIdAndType($homeworkId, 'homework');

        $canTakeCourse = $this->getCourseService()->canTakeCourse($homework['courseId']);
        if (!$canTakeCourse) {
            return $this->error('500', '无权限访问!');
        }

        $conditions = array(
            'mediaId' => $homework['id'],
            'mediaType' => 'homework',
            'fromCourseId' => $homework['courseId'],
        );
        $activities = $this->getActivityService()->search($conditions, null, 0, 1);

        if (!$activities) {
            return $this->error('404', '该作业任务不存在!');
        }

        //homework里获取不到activityId,只能间接获取
        $lessonId = $activities[0]['id'];
        $result = $this->getTestpaperService()->startTestpaper($homework['id'], array('lessonId' => $lessonId, 'courseId' => $homework['courseId']));

        try {
            $this->getTestpaperService()->finishTest($result['id'], $answers);
        } catch (\Exception $e) {
            return $this->error('500', $e->getMessage());
        }

        return array(
            'id' => $result['id'],
        );
    }

    public function get(Application $app, Request $request, $lessonId)
    {
        $user = $this->getCurrentUser();
        $task = $this->getTaskService()->getTask($lessonId);

        if ($task['type'] != 'homework') {
            $conditions = array(
                'categoryId' => $task['categoryId'],
                'type' => 'homework',
                'mode' => 'homework',
            );

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

AI 解读 AI

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

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