123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- <?php
- /**
- * @author: CeeFee
- * @description: 考试
- */
- class SPaper extends MyActiveRecord
- {
- public static function model($className = __CLASS__)
- {
- return parent::model($className);
- }
-
- public function tableName()
- {
- return 'paper';
- }
-
- public function getPapersByExamId($examId)
- {
- $result = array();
-
- if ($examId AND is_numeric($examId))
- {
- $criteria = new CDbCriteria();
- $criteria->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);
- }
- }
|