Exemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Exam::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['like', '_id', $this->_id])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'num', $this->num])->andFilterWhere(['like', 'people', $this->people])->andFilterWhere(['like', 'difficulty', $this->difficulty])->andFilterWhere(['like', 'addtime', $this->addtime])->andFilterWhere(['like', 'is_hot', $this->is_hot])->andFilterWhere(['like', 'is_news', $this->is_news])->andFilterWhere(['like', 'job', $this->job])->andFilterWhere(['like', 'zhishi', $this->zhishi])->andFilterWhere(['like', 'do_time', $this->do_time])->andFilterWhere(['like', 'sum_grade', $this->sum_grade])->andFilterWhere(['like', 'e_desc', $this->e_desc])->andFilterWhere(['like', 'company_id', $this->company_id])->andFilterWhere(['like', 'head_logo', $this->head_logo]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Exam::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'duration' => $this->duration, 'created_time' => $this->created_time, 'completed' => $this->completed, 'exam_date' => $this->exam_date, 'user_id' => $this->user_id]);
     $query->andFilterWhere(['like', 'subject', $this->subject]);
     return $dataProvider;
 }
Exemplo n.º 3
0
 public function actionIndex()
 {
     if (\Yii::$app->user->isGuest) {
         $this->redirect(array("login"));
     } else {
         $exam = Exam::find()->where("1=1")->one();
         // modify later
         if (Yii::$app->request->post()) {
             $post = Yii::$app->request->post();
             $answers = $post["Answers"];
             $transaction = Yii::$app->db->beginTransaction();
             try {
                 $userscore = new UserScore();
                 $userscore->finished_time = date("Y-m-d H:i:s");
                 $userscore->user_id = Yii::$app->user->identity->id;
                 $userscore->exam_id = $exam->id;
                 $userscore->score = 0;
                 $userAnswers = [];
                 $totalScore = 0;
                 foreach ($exam->getQuestions()->all() as $question) {
                     $userAnswer = new UserHasAnswer();
                     $userAnswer->user_id = Yii::$app->user->identity->id;
                     $userAnswer->answer_id = $answers[$question->id];
                     $userAnswer->exam_id = $exam->id;
                     $userAnswer->save();
                     $correctAnswer = Answer::find()->where("is_correct=:is_correct AND question_id=:question_id", [":is_correct" => 1, ":question_id" => $question->id])->one();
                     if ($userAnswer->answer_id === $correctAnswer->id) {
                         $userscore->score += $question->score;
                     }
                     $totalScore += $question->score;
                     $userAnswers[] = $userAnswer;
                 }
                 $userAnswer->save();
                 $transaction->commit();
                 //                    $this->redirect(["showScore"], ["userAnswers" => $userAnswers, "userScore" => $userscore]);
                 return $this->render("score_summary", ["userAnswers" => $userAnswers, "userScore" => $userscore, "totalScore" => $totalScore]);
             } catch (Exception $exc) {
                 $transaction->rollBack();
                 Yii::$app->session->setFlash("error", $exc->getTraceAsString());
             }
         }
         return $this->render('index', ["exam" => $exam]);
     }
 }
Exemplo n.º 4
0
 /**
  * 公司真题
  */
 public function getIndex()
 {
     //只显示职业方向和公司分类
     $cate_info = Category::where('cate_name', '职业方向')->orwhere('cate_name', '公司')->select(['_id', 'cate_name'])->get();
     foreach ($cate_info as $k => &$val) {
         $tmp_cate = Category::where('pid', (string) $val->_id)->select(['_id', 'cate_name'])->get();
         $val['two_cate'] = $tmp_cate;
     }
     //搜索最近5年的
     $datetime['title'] = '时间';
     for ($i = date("Y"); $i > date("Y") - 5; $i--) {
         $datetime['times'][] = $i;
     }
     //默认显示最新
     $url = array();
     //分页路径
     if (!empty($_GET['is_hot'])) {
         $id = $_GET['is_hot'];
         $where['is_hot'] = '1';
         $url['is_hot'] = 1;
     } else {
         $id = '';
         $where['is_news'] = '1';
     }
     //搜索
     $choose_cate = array();
     $par = array();
     if (!empty($_GET['par'])) {
         $par = explode('_', $_GET['par']);
         $url['par'] = $_GET['par'];
         $choose_cate = Category::whereIn('_id', $par)->select(['_id', 'cate_name'])->get();
         $exam_info = Exam::whereIn('job', $par)->orwhereIn('company_id', $par)->where($where)->paginate(3);
     } else {
         $exam_info = Exam::where($where)->paginate(3);
     }
     //查询公司logo
     foreach ($exam_info as $k => &$val) {
         $company_info = Category::where('_id', $val->company_id)->select(['logo'])->first();
         $val->company_logo = $company_info->logo;
     }
     $exam_info->setPath('index');
     return view('question.c_exam', ['exam_info' => $exam_info, 'cate_info' => $cate_info, 'choose_cate' => $choose_cate, 'datetime' => $datetime, 'id' => $id, 'par' => $par, 'url' => $url]);
 }
Exemplo n.º 5
0
 public function post_exam(Request $request)
 {
     if (Auth::user()->type == 'teacher') {
         if (Auth::user()->teacherinfo->packageinfo->exams - count(Auth::user()->exams) != 0) {
             Exam::create(['type' => $request->input('examtype'), 'tutorid' => Auth::user()->id, 'date' => $request->input('date'), 'time' => $request->input('time'), 'duration' => $request->input('duration'), 'mark' => $request->input('mark')]);
         }
     }
 }
Exemplo n.º 6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getExams()
 {
     return $this->hasMany(Exam::className(), ['user_id' => 'id']);
 }
Exemplo n.º 7
0
 /**
  * @param Exam $exam
  * @return mixed
  * @throws \Exception
  */
 public function destroy(Exam $exam)
 {
     $exam->delete();
 }
Exemplo n.º 8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getExam()
 {
     return $this->hasOne(Exam::className(), ['id' => 'exam_id']);
 }
Exemplo n.º 9
0
 /**
  * Finds the Exam model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $_id
  * @return Exam the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Exam::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 10
0
 /**
  * 试题广场
  */
 public function getIndex()
 {
     //只显示职业方向和公司分类
     $cate_info = Category::where('pid', '0')->select(['_id', 'cate_name'])->get();
     foreach ($cate_info as $k => &$val) {
         if ($val->cate_name == '知识点') {
             $tmp_cate = Category::where('pid', (string) $val->_id)->where('level', '2')->select(['_id', 'cate_name'])->get();
             $val['two_cate'] = $tmp_cate;
             foreach ($tmp_cate as $kk => &$vv) {
                 $tmp_zhishi = Category::where('pid', (string) $vv->_id)->select(['_id', 'cate_name'])->get();
                 $vv['zhishi'] = $tmp_zhishi;
             }
         } else {
             $tmp_cate = Category::where('pid', (string) $val->_id)->select(['_id', 'cate_name'])->get();
             $val['two_cate'] = $tmp_cate;
         }
     }
     //print_R($cate_info);die;
     $url = array();
     //默认显示最新
     if (!empty($_GET['is_hot'])) {
         $id = $_GET['is_hot'];
         $where['is_hot'] = '1';
         $url['is_hot'] = '1';
     } else {
         $id = '';
         $where['is_news'] = '1';
     }
     //搜索
     $choose_cate = array();
     $par = array();
     $par_arr = array();
     $q_type = array();
     if (!empty($_GET['par'])) {
         $par = explode('_', $_GET['par']);
         $par_arr = $par;
         $url['par'] = $_GET['par'];
         $choose_cate = Category::whereIn('_id', $par)->orwhereIn('cate_name', $par)->select(['_id', 'cate_name'])->get();
         foreach ($par as $k => $v) {
             $reg = "/^[\\x{4e00}-\\x{9fa5}]+\$/u";
             $res = preg_match($reg, $v);
             if ($res) {
                 $q_type[] = $par[$k];
                 unset($par[$k]);
             }
         }
         if ($par) {
             $exam_info = Exam::whereIn('job', $par)->orwhereIn('company_id', $par)->orwhereIn('zhishi', $par)->where($where)->get();
         } else {
             $exam_info = Exam::where($where)->get();
         }
     } else {
         $exam_info = Exam::where($where)->get();
     }
     $id_arr = array();
     foreach ($exam_info as $k => $val) {
         $id_arr[] = $val->_id;
     }
     if (!$q_type) {
         $question_info = Question::whereIn('e_id', $id_arr)->select(['q_title'])->paginate(10);
     } else {
         $question_info = Question::whereIn('e_id', $id_arr)->whereIn('q_type', $q_type)->select(['q_title'])->paginate(10);
     }
     //print_R($question_info);
     $question_info->setPath('index');
     return view('square.square', ['cate_info' => $cate_info, 'question_info' => $question_info, 'id' => $id, 'choose_cate' => $choose_cate, 'par_arr' => $par_arr, 'url' => $url]);
 }
Exemplo n.º 11
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(ExamRequest $request)
 {
     Exam::create($request->all());
     return "Saved!";
 }