public function actionResults()
 {
     $student_id = Yii::app()->request->getQuery("student_id", NULL);
     $current = Current::model()->find('student_id=:student_id', array(':student_id' => $student_id));
     $all_sessions = Session::model()->findAll('mod_id=:mod_id', array(':mod_id' => $current->mod_id));
     $all = array();
     foreach ($all_sessions as $key0 => $session) {
         $session_id = $session->session_id;
         $session_listenings = SessionListening::model()->findAll('session_id=:session_id', array(':session_id' => $session_id));
         $all[$key0]["session_id"] = $session->session_id;
         $all[$key0]["session_name"] = $session->session_name;
         $all[$key0]["session_order"] = $session->session_order;
         $all[$key0]["mod_id"] = $session->mod_id;
         $all[$key0]["listenings"] = array();
         foreach ($session_listenings as $key => $session_listening) {
             $temp_listening_id = $session_listening->listening_id;
             $listening = Listening::model()->find('listening_id=:listening_id', array(':listening_id' => $temp_listening_id));
             $all[$key0]["listenings"][$key] = array('listening_id' => $listening->listening_id, 'listening_name' => $listening->listening_name, 'listening_repeat_number' => $listening->listening_repeat_number, 'listening_learning_guide_availability' => $listening->listening_learning_guide_availability);
             $criteria = new CDbCriteria();
             $criteria->addCondition("listening_id=:listening_id");
             //$criteria->order='RAND()';
             $criteria->params = array(':listening_id' => $listening->listening_id);
             $questions = Question::model()->findAll($criteria);
             //$questions=Question::model()->findAll('listening_id=:listening_id',array('listening_id'=>$listening->listening_id));
             foreach ($questions as $key2 => $question) {
                 $all[$key0]["listenings"][$key]['questions'][$key2] = array('question_id' => $question->question_id, 'question_body' => $question->question_body, 'question_correct_answer_id' => $question->question_correct_answer_id);
                 $criteria = new CDbCriteria();
                 $criteria->addCondition("question_id=:question_id");
                 //$criteria->order='RAND()';
                 $criteria->params = array(':question_id' => $question->question_id);
                 $answers = Answer::model()->findAll($criteria);
                 //$answers=Answer::model()->findAll('question_id=:question_id',array(':question_id'=>$question->question_id));
                 foreach ($answers as $key3 => $answer) {
                     $all[$key0]["listenings"][$key]['questions'][$key2]['answers'][$key3] = array('answer_id' => $answer->answer_id, 'answer_body' => $answer->answer_body);
                 }
             }
         }
     }
     $this->render('results', array('all' => $all, 'student_id' => $student_id));
 }
Esempio n. 2
0
 public function actionPushLogin()
 {
     $student_username = Yii::app()->request->getPost("student_username", NULL);
     $student_password = Yii::app()->request->getPost("student_password", NULL);
     $student = Student::model()->find('student_username=:student_username', array(':student_username' => $student_username));
     if ($student) {
         if ($student->student_password == hash('sha512', $student_password . Yii::app()->params['salt'])) {
             $current = Current::model()->find('student_id=:student_id', array('student_id' => $student->student_id));
             $mod = Mod::model()->find('mod_id=:mod_id', array('mod_id' => $current->mod_id));
             $response = array('student_id' => $student->student_id, 'student_username' => $student->student_username, 'student_name' => $student->student_name, 'student_surname' => $student->student_surname, 'mod_name' => $mod->mod_name);
             $this->renderJSON($response);
         } else {
             $this->renderJSON(array('status' => 0, 'message' => 'either username or password is not correct!'));
         }
     } else {
         $this->renderJSON(array('status' => 0, 'message' => 'there is no such a user registered!'));
     }
 }
Esempio n. 3
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Current the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Current::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }