public function actionTestChapter() { $query = TestChapter::find()->where(['>', 'majorJobId', 0]); $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['pageSize'], 'totalCount' => $query->count()]); $model = $query->offset($pagination->offset)->limit($pagination->limit)->all(); return $this->render('test-chapter', ['models' => $model, 'pages' => $pagination]); }
public function actionCreateDetail($id) { $request = Yii::$app->request; /** @var $examTemplate \common\models\ExamTemplate*/ $examTemplate = ExamTemplate::findOne($id); if ($request->isPost) { //保存数据之前 删除所有原来的数据 且必须是模板未启用的状态下才能删除 if ($examTemplate->state == ExamTemplate::STATE_DISABLE) { ExamTemplateDetail::deleteAllByExamTemplateId($examTemplate->examTemplateId); } else { CommonFunctions::createAlertMessage("模板启用状态下删除题目出错", 'error'); return $this->redirect(['exam-template/index']); } //保存题目数量和分数 $examTemplate->pa1 = $request->post("number_pa1") . "|" . $request->post("score_pa1"); $examTemplate->pa2 = $request->post("number_pa2") . "|" . $request->post("score_pa2"); $examTemplate->pa3 = $request->post("number_pa3") . "|" . $request->post("score_pa3"); $examTemplate->pa4 = $request->post("number_pa4") . "|" . $request->post("score_pa4"); $examTemplate->pb1 = $request->post("number_pb1") . "|" . $request->post("score_pb1"); $examTemplate->pb2 = $request->post("number_pb2") . "|" . $request->post("score_pb2"); $examTemplate->pb3 = $request->post("number_pb3") . "|" . $request->post("score_pb3"); $examTemplate->pb4 = $request->post("number_pb4") . "|" . $request->post("score_pb4"); if (!$examTemplate->save()) { CommonFunctions::createAlertMessage("题目保存出错", 'error'); return $this->redirect(['exam-template/index']); } $testChapters = TestChapter::find()->where(['majorJobId' => $examTemplate->majorJobId])->all(); foreach ($testChapters as $testChapter) { $testNumber_1 = $request->post("danxuan_" . $testChapter->testChapterId); $testNumber_2 = $request->post("duoxuan_" . $testChapter->testChapterId); $testNumber_3 = $request->post("panduan_" . $testChapter->testChapterId); $testNumber_4 = $request->post("anli_" . $testChapter->testChapterId); if ($testNumber_1 && $testNumber_1 != 0) { ExamTemplateDetail::saveOne($id, $testChapter->preTypeId, $testChapter->testChapterId, 1, $testNumber_1); } if ($testNumber_2 && $testNumber_2 != 0) { ExamTemplateDetail::saveOne($id, $testChapter->preTypeId, $testChapter->testChapterId, 2, $testNumber_2); } if ($testNumber_3 && $testNumber_3 != 0) { ExamTemplateDetail::saveOne($id, $testChapter->preTypeId, $testChapter->testChapterId, 3, $testNumber_3); } if ($testNumber_4 && $testNumber_4 != 0) { ExamTemplateDetail::saveOne($id, $testChapter->preTypeId, $testChapter->testChapterId, 4, $testNumber_4); } } CommonFunctions::createAlertMessage("模板组题完成", 'success'); return $this->redirect(['exam-template/index']); } $testChapters_1 = TestChapter::find()->where(['majorJobId' => $examTemplate->majorJobId, 'preTypeId' => 1])->all(); $testChapters_2 = TestChapter::find()->where(['majorJobId' => $examTemplate->majorJobId, 'preTypeId' => 2])->all(); $examTemplateDetails = ExamTemplateDetail::findByExamTemplate($examTemplate->examTemplateId); $examTemplateDetails = ExamTemplateDetail::remakeArray($examTemplateDetails); return $this->render('create-detail', ['examTemplate' => $examTemplate, 'testChapters_1' => $testChapters_1, 'testChapters_2' => $testChapters_2, 'examTemplateDetails' => $examTemplateDetails]); }