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 actionSearch()
 {
     Url::remember();
     //记录当前页,为更新数据后还是跳转到当前页做记录
     $request = Yii::$app->request;
     $query = Yii::$app->session->getFlash('query');
     if ($request->isPost) {
         $type = $request->post('type');
         $content = $request->post('content');
     } else {
         $type = $request->get('type');
         $content = trim($request->get('content'));
     }
     if ($type || !$query) {
         switch ($type) {
             case 'testLibraryId':
                 $query = TestLibrary::find()->where(['testLibraryId' => $content]);
                 break;
             case 'testType':
                 $table_a = TestLibrary::tableName();
                 $table_b = TestType::tableName();
                 $query = TestLibrary::find()->leftJoin($table_b, "{$table_a}.testTypeId={$table_b}.testTypeId")->where(['like', "{$table_b}.name", $content]);
                 break;
             case 'province':
                 $table_a = TestLibrary::tableName();
                 $table_b = Province::tableName();
                 $query = TestLibrary::find()->leftJoin($table_b, "{$table_a}.provinceId={$table_b}.provinceId")->where(['like', "{$table_b}.name", $content]);
                 break;
             case 'majorJob':
                 $table_a = TestLibrary::tableName();
                 $table_b = MajorJob::tableName();
                 $query = TestLibrary::find()->leftJoin($table_b, "{$table_a}.majorJobId={$table_b}.majorJobId")->where(['like', $table_b . ".name", $content]);
                 break;
             case 'testChapter':
                 $table_a = TestLibrary::tableName();
                 $table_b = TestChapter::tableName();
                 $query = TestLibrary::find()->leftJoin($table_b, "{$table_a}.testChapterId={$table_b}.testChapterId")->where(['like', $table_b . ".name", $content]);
                 break;
             case 'question':
             case 'problem':
             case 'options':
                 $query = TestLibrary::find()->where(['like', $type, $content]);
                 break;
             default:
                 $query = TestLibrary::find();
                 break;
         }
     }
     Yii::$app->session->setFlash('query', $query);
     $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['pageSize'], 'totalCount' => $query->count()]);
     $model = $query->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('index', ['models' => $model, 'pages' => $pagination]);
 }
Example #3
0
 public function getTestChapter()
 {
     return $this->hasOne(TestChapter::className(), ['testChapterId' => 'testChapterId']);
 }
 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]);
 }