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!')); } }
public function actionSessionResults() { $student_id = Yii::app()->request->getQuery("student_id", NULL); $session_id = Yii::app()->request->getQuery("session_id", NULL); $SessionListening = SessionListening::model()->findAll('session_id=:session_id', array('session_id' => $session_id)); $all_student = Student::model()->find('student_id=:student_id', array(':student_id' => $student_id)); $current = Current::model()->find('student_id=:student_id', array(':student_id' => $student_id)); $mod = Mod::model()->find('mod_id=:mod_id', array(':mod_id' => $current->mod_id)); $all = array(); foreach ($SessionListening as $session_listening_item) { $listening_id = $session_listening_item->listening->listening_id; $questions = Question::model()->findAll('listening_id=:listening_id', array('listening_id' => $listening_id)); foreach ($questions as $key => $question) { $your_answer_id = $this->getYourAnswerId($question->question_id, $student_id); $correct_answer_id = $question->question_correct_answer_id; if ($your_answer_id) { if ($your_answer_id == $correct_answer_id) { $all[$listening_id][$key] = 1; } else { $all[$listening_id][$key] = 0; } } else { $all[$listening_id][$key] = -1; } } } $this->render('sessionresult', array('sessionListening' => $SessionListening, 'all' => $all, 'all_student' => $all_student, 'mod' => $mod)); }