addCondition("exam_id = '". $examId ."'"); $criteria->order = 'paper_layer ASC, paper_id ASC'; $result = getAttributes($this->findAll($criteria)); } return $result; } public function getPaperIdsByExamId($examId) { $result = array(); $papers = $this->getPapersByExamId($examId); if ($papers) { foreach ($papers AS $paper) { $result[] = $paper['paper_id']; } } return $result; } public function getDetailByPaperId($paperId) { $result = array(); if ($paperId AND is_numeric($paperId)) { $criteria = new CDbCriteria(); $criteria->addCondition("paper_id = '". $paperId ."'"); $result = getAttribute($this->find($criteria)); } return $result; } public function getDetailByExamId_PaperLayer($examId, $paperLayer) { $result = array(); if ($examId AND is_numeric($examId)) { $criteria = new CDbCriteria(); $criteria->addCondition("exam_id = '". $examId ."' AND paper_layer = '". $paperLayer ."'"); $result = getAttribute($this->find($criteria)); } return $result; } /** * 获取试卷总分 * @param $paperIds * @return bool|CDbDataReader|int|mixed|string */ public function getPaperScore($paperIds){ $score = 0; if($paperIds && is_array($paperIds)){ $paperIds = array_values($paperIds); $sql = "select score from paper where paper_id = {$paperIds[0]}"; $score = $this->getCommandBuilder()->createSqlCommand($sql)->queryScalar(); } return $score; } /** * 获取考试对应的试卷id * @param $examIds * @return array */ public function getPaperIdsByExamIds($examIds){ $paperIds = $examRelIds = array(); if($examIds && is_array($examIds)){ $sql = "select paper_id,exam_id from paper where exam_id in (".implode(',',$examIds).")"; $paperInfo = $this->getCommandBuilder()->createSqlCommand($sql)->queryAll(); if($paperInfo){ foreach ($paperInfo as $item) { $paperIds[$item['exam_id']] = $item['paper_id']; $examRelIds[$item['paper_id']] = $item['exam_id']; } } } return array($paperIds,$examRelIds); } }