public function beforeFilter()
 {
     parent::beforeFilter();
     parent::requireManager();
 }
 /**
  * 给简答题答案批阅成绩
  */
 public function markAnsHistory($tryHistoryid)
 {
     parent::requireManager();
     if (empty($tryHistoryid)) {
         return false;
     }
     $this->set('tryHistoryid', $tryHistoryid);
     //获得考试记录
     $this->loadModel('TryHistory');
     $tryHistory = $this->TryHistory->findById($tryHistoryid);
     //考试记录不存在、或者此次并非考试
     if (empty($tryHistory) || $tryHistory['TryHistory']['try_type'] != 1) {
         return false;
     }
     //获得考试类别信息
     $this->loadModel('TestType');
     $testType = $this->TestType->findById($tryHistory['TryHistory']['test_type_id']);
     if (empty($testType)) {
         return false;
     }
     //获得学生信息
     $this->loadModel('Student');
     $student = $this->Student->find('first', array('conditions' => array('Student.id' => $tryHistory['TryHistory']['student_id']), 'joins' => $this->Student->fullJoins(), 'fields' => '*'));
     if (empty($student)) {
         return false;
     }
     //获得简答题答案记录
     $this->loadModel('AnsHistory');
     $conditions = array();
     $conditions['try_history_id'] = $tryHistoryid;
     $ansHistory = $this->AnsHistory->find('all', array('conditions' => $conditions));
     //获得题目信息
     $questions = array();
     if (!empty($ansHistory)) {
         $this->loadModel('Question');
         $qids = array();
         foreach ($ansHistory as $ans) {
             $qids[] = $ans['AnsHistory']['question_id'];
         }
         $questions = $this->Question->find('all', array('conditions' => array('id' => $qids)));
     }
     $ques = array();
     foreach ($questions as $q) {
         $ques[$q['Question']['id']] = $q;
     }
     if ($this->request->is('post') && $this->request->is('ajax')) {
         $this->autoRender = false;
         if ($tryHistory['TryHistory']['has_checked'] == 1) {
             return $this->json_error('该试卷简答题已经批改!');
         }
         $qids = $this->request->data('qids');
         //回答的id
         $scores = $this->request->data('scores');
         //评分
         $this->loadModel('AnsHistory');
         $ret = false;
         if (!empty($qids)) {
             $ans_score = 0;
             foreach ($qids as $i => $id) {
                 $data = array();
                 $score = intval($scores[$i]);
                 if ($score < 0) {
                     $score = 0;
                 } else {
                     if ($score > $testType['TestType']['ans_score']) {
                         $score = $testType['TestType']['ans_score'];
                     }
                 }
                 $data = array();
                 $data['score'] = $score;
                 $ans_score += $score;
                 $this->AnsHistory->id = $id;
                 $ret = $this->AnsHistory->save($data);
                 if (!$ret) {
                     break;
                 }
             }
         }
         if ($ret) {
             $this->loadModel('TryHistory');
             $this->TryHistory->id = $tryHistoryid;
             $data = array();
             $data['ans_score'] = $ans_score;
             $data['has_checked'] = 1;
             $ret = $this->TryHistory->save($data);
             if ($ret) {
                 return $this->json_success('批改成功!');
             }
         }
         return $this->json_error('批改失败!');
     }
     $this->set('testType', $testType);
     $this->set('student', $student);
     $this->set('tryHistory', $tryHistory);
     $this->set('ansHistory', $ansHistory);
     $this->set('questions', $ques);
 }