SPaper.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * @author: CeeFee
  4. * @description: 考试
  5. */
  6. class SPaper extends MyActiveRecord
  7. {
  8. public static function model($className = __CLASS__)
  9. {
  10. return parent::model($className);
  11. }
  12. public function tableName()
  13. {
  14. return 'paper';
  15. }
  16. public function getPapersByExamId($examId)
  17. {
  18. $result = array();
  19. if ($examId AND is_numeric($examId))
  20. {
  21. $criteria = new CDbCriteria();
  22. $criteria->addCondition("exam_id = '". $examId ."'");
  23. $criteria->order = 'paper_layer ASC, paper_id ASC';
  24. $result = getAttributes($this->findAll($criteria));
  25. }
  26. return $result;
  27. }
  28. public function getPaperIdsByExamId($examId)
  29. {
  30. $result = array();
  31. $papers = $this->getPapersByExamId($examId);
  32. if ($papers)
  33. {
  34. foreach ($papers AS $paper)
  35. {
  36. $result[] = $paper['paper_id'];
  37. }
  38. }
  39. return $result;
  40. }
  41. public function getDetailByPaperId($paperId)
  42. {
  43. $result = array();
  44. if ($paperId AND is_numeric($paperId))
  45. {
  46. $criteria = new CDbCriteria();
  47. $criteria->addCondition("paper_id = '". $paperId ."'");
  48. $result = getAttribute($this->find($criteria));
  49. }
  50. return $result;
  51. }
  52. public function getDetailByExamId_PaperLayer($examId, $paperLayer)
  53. {
  54. $result = array();
  55. if ($examId AND is_numeric($examId))
  56. {
  57. $criteria = new CDbCriteria();
  58. $criteria->addCondition("exam_id = '". $examId ."' AND paper_layer = '". $paperLayer ."'");
  59. $result = getAttribute($this->find($criteria));
  60. }
  61. return $result;
  62. }
  63. /**
  64. * 获取试卷总分
  65. * @param $paperIds
  66. * @return bool|CDbDataReader|int|mixed|string
  67. */
  68. public function getPaperScore($paperIds){
  69. $score = 0;
  70. if($paperIds && is_array($paperIds)){
  71. $paperIds = array_values($paperIds);
  72. $sql = "select score from paper where paper_id = {$paperIds[0]}";
  73. $score = $this->getCommandBuilder()->createSqlCommand($sql)->queryScalar();
  74. }
  75. return $score;
  76. }
  77. /**
  78. * 获取考试对应的试卷id
  79. * @param $examIds
  80. * @return array
  81. */
  82. public function getPaperIdsByExamIds($examIds){
  83. $paperIds = $examRelIds = array();
  84. if($examIds && is_array($examIds)){
  85. $sql = "select paper_id,exam_id from paper where exam_id in (".implode(',',$examIds).")";
  86. $paperInfo = $this->getCommandBuilder()->createSqlCommand($sql)->queryAll();
  87. if($paperInfo){
  88. foreach ($paperInfo as $item) {
  89. $paperIds[$item['exam_id']] = $item['paper_id'];
  90. $examRelIds[$item['paper_id']] = $item['exam_id'];
  91. }
  92. }
  93. }
  94. return array($paperIds,$examRelIds);
  95. }
  96. }