public static function CheckAnswers($answers_array,$user_id) { $result = 1; foreach ($answers_array as $key=>$value) { $right_answ = UsersAnswers::model()->findByAttributes(array( 'Question_ID'=>$key, 'User_ID' => $user_id )); if (sha1($value)==$right_answ->Hashed_Answer) { $result= $result*1; } else { $result= $result*0; } } return $result; }
public static function getCountUserQuestions ($user_id){ $answers = UsersAnswers::model()->with('questions')->findAllByAttributes(array( 'User_ID'=>$user_id )); $questions = array(); foreach ($answers as $answer) { $questions[]= array('Question_ID'=>$answer->questions->Question_ID,'Text'=>$answer->questions->Text,'Hint'=>$answer->Hint); } return count($questions); }