/** * 查询测试类型名称,缓存24小时 * @param $testTypeId * @return mixed * @throws \Exception */ public static function findNameById($testTypeId) { $result = TestType::getDb()->cache(function () use($testTypeId) { return TestType::findOne($testTypeId); }, 24 * 3600); return $result->name; }
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]); }
public function actionTestType() { $models = TestType::findAllForObject(); return $this->render('test-type', ['models' => $models]); }
public function getTestType() { return $this->hasOne(TestType::className(), ['testTypeId' => 'testTypeId']); }
(<?php echo $questionNumber; ?> /<?php echo $session->get('totalNumber'); ?> ) </h3> </div> <div class="panel-heading"> <h3 class="panel-title"> <span><?php echo \common\models\PreType::findNameById($preTypeId); ?> |<?php echo \common\models\TestType::findNameById($testTypeId); ?> </span> <?php if ($examFlag) { //考试需要倒计时 ?> <span class="pull-right">剩余<span class="time">150</span>分钟</span> <?php } ?> </h3> <div class="clearfix"></div> </div> <?php if (!$examFlag) {