app\controllers\TaskController::actionSubmit PHP Method

actionSubmit() public method

提交任务
public actionSubmit ( $projectId = null ) : string
$projectId 没有projectId则显示列表
return string
    public function actionSubmit($projectId = null)
    {
        // 为了方便用户更改表名,避免表名直接定死
        $projectTable = Project::tableName();
        $groupTable = Group::tableName();
        if (!$projectId) {
            // 显示所有项目列表
            $projects = Project::find()->leftJoin(Group::tableName(), "`{$groupTable}`.`project_id` = `{$projectTable}`.`id`")->where(["`{$projectTable}`.status" => Project::STATUS_VALID, "`{$groupTable}`.`user_id`" => $this->uid])->asArray()->all();
            return $this->render('select-project', ['projects' => $projects]);
        }
        $task = new Task();
        $conf = Project::getConf($projectId);
        if (!$conf) {
            throw new \Exception(yii::t('task', 'unknown project'));
        }
        if (\Yii::$app->request->getIsPost()) {
            $group = Group::find()->where(['user_id' => $this->uid, 'project_id' => $projectId])->count();
            if (!$group) {
                throw new \Exception(yii::t('task', 'you are not the member of project'));
            }
            if ($task->load(\Yii::$app->request->post())) {
                // 是否需要审核
                $status = $conf->audit == Project::AUDIT_YES ? Task::STATUS_SUBMIT : Task::STATUS_PASS;
                $task->user_id = $this->uid;
                $task->project_id = $projectId;
                $task->status = $status;
                if ($task->save()) {
                    return $this->redirect('@web/task/');
                }
            }
        }
        $tpl = $conf->repo_type == Project::REPO_GIT ? 'submit-git' : 'submit-svn';
        return $this->render($tpl, ['task' => $task, 'conf' => $conf]);
    }