示例#1
0
 public function getAnswers($project_id = null)
 {
     if ($project_id) {
         $eids = $this->getExamineesId($project_id);
         $pids = Utils::getIds($this->getPapers());
         $qans = QuestionAns::getAns($pids, $eids);
         return $this->makeAns($qans);
     } else {
         if ($this->answers == null) {
             $this->answers = $this->getAnswers($this->project_id);
         }
         return $this->answers;
     }
 }
示例#2
0
 /**
  * 根据paper_id和用户id的集合来查找所有符合条件的答案
  * 两个参数可以是单独的id,也可以是数组集合
  */
 public static function getAns($paper_id, $examinee_id)
 {
     $cond = '';
     if (is_array($paper_id)) {
         $cond .= 'paper_id IN ({paper_id:array})';
     } else {
         $cond .= 'paper_id = :paper_id:';
     }
     $cond .= ' AND ';
     if (is_array($examinee_id)) {
         $cond .= 'examinee_id IN ({examinee_id:array})';
     } else {
         $cond .= 'examinee_id = :examinee_id:';
     }
     $anss = QuestionAns::find(array($cond, 'bind' => array('paper_id' => $paper_id, 'examinee_id' => $examinee_id)));
     return $anss;
 }
示例#3
0
 /**
  * @usage 获取被试的试卷信息,判断试卷是否全部完成,成功则返回试卷信息
  * @param int $project_id
  * @param int $examinee_id
  * @throws Exception
  * @return unknown
  */
 protected static function getPapers($project_id, $examinee_id)
 {
     $project_detail_json = MemoryCache::getProjectDetail($project_id);
     $project_detail = json_decode($project_detail_json->exam_json, true);
     $papers_tmp = QuestionAns::find(array("examinee_id = :examinee_id:", 'bind' => array('examinee_id' => $examinee_id)));
     if (count($papers_tmp) != count($project_detail)) {
         throw new Exception(self::$error_state . '-答卷数量不正确-' . count($papers_tmp) . '-' . count($project_detail));
     }
     $papers_id_tmp = array();
     foreach ($papers_tmp as $value) {
         $papers_id_tmp[] = $value->paper_id;
     }
     $project_papers_id = array();
     foreach ($project_detail as $key => $value) {
         $project_papers_id[] = MemoryCache::getPaperDetail($key)->id;
     }
     if (!array_diff($papers_id_tmp, $project_papers_id)) {
         return $papers_tmp;
     } else {
         throw new Exception(self::$error_state . '-答卷信息与题库信息不符-' . print_r($papers_id_tmp, true) . print_r($project_papers_id, true));
     }
 }
示例#4
0
 /**
  * @usage 写入被试的答卷信息
  * @param int $examinee_id
  * @param string $paper_name
  * @param string $option_str
  * @param array $number_array
  * @throws Exception
  * @return boolean
  */
 public static function insertQuestionAns($examinee_id, $paper_name, $option_str, $number_array, $time)
 {
     $project_id = self::getProjectId($examinee_id);
     if (!$project_id) {
         return false;
     }
     $paper_name = strtoupper($paper_name);
     switch ($paper_name) {
         case 'EPQA':
             self::checkEPQA($option_str, $number_array, $project_id);
             break;
         case 'EPPS':
             self::checkEPPS($option_str, $number_array, $project_id);
             break;
         case 'CPI':
             self::checkCPI($option_str, $number_array, $project_id);
             break;
         case '16PF':
             self::checkKS($option_str, $number_array, $project_id);
             break;
         case 'SCL':
             self::checkSCL($option_str, $number_array, $project_id);
             break;
         case 'SPM':
             self::checkSPM($option_str, $number_array, $project_id);
             break;
         default:
             throw new Exception(self::$error_state . '-不存在试卷-' . $paper_name);
     }
     $paper_id = MemoryCache::getPaperDetail($paper_name)->id;
     try {
         // Create a transaction manager
         $manager = new TxManager();
         // Request a transaction
         $transaction = $manager->get();
         $question_ans = new QuestionAns();
         #将事务设置到每一次的new之后
         $question_ans->setTransaction($transaction);
         $question_ans->option = $option_str;
         $question_ans->paper_id = $paper_id;
         $question_ans->examinee_id = $examinee_id;
         $question_ans->question_number_list = implode("|", $number_array);
         $question_ans->time = $time;
         if ($question_ans->save() == false) {
             $transaction->rollback(self::$error_state . '-数据库插入失败-' . print_r($question_ans, true));
         }
         $transaction->commit();
         return true;
     } catch (TxFailed $e) {
         throw new Exception($e->getMessage());
     }
 }
示例#5
0
 protected static function getPapersByExamineeId($examinee_id)
 {
     $rt_list = QuestionAns::find(array("examinee_id = :examinee_id:", 'bind' => array('examinee_id' => $examinee_id)));
     if (empty(self::$factors_list_all)) {
         self::getFactorsAll($examinee_id);
     }
     if (count($rt_list) != count(self::$factors_list_all)) {
         throw new Exception(self::$error_state . '-答卷数量不正确-' . count($rt_list) . '-' . count(self::$factors_list_all));
     }
     $papers_id_tmp = array();
     foreach ($rt_list as $value) {
         $papers_id_tmp[] = $value->paper_id;
     }
     $project_papers_id = array();
     foreach (self::$factors_list_all as $key => $value) {
         $project_papers_id[] = MemoryCache::getPaperDetail($key)->id;
     }
     if (!array_diff($papers_id_tmp, $project_papers_id)) {
         return $rt_list;
     } else {
         throw new Exception(self::$error_state . '-答卷信息与题库信息不符-' . print_r($papers_id_tmp, true) . print_r($project_papers_id, true));
     }
 }