SClassExamPrinter.php 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Created by 上海互教教育科技有限公司.
  4. * User: 刘红伟
  5. * QQ : 454303753
  6. * Date: 2017/7/26 0026
  7. * Time: 上午 11:01
  8. */
  9. class SClassExamPrinter extends MyActiveRecord{
  10. public static function model($className = __CLASS__){
  11. return parent::model($className);
  12. }
  13. public function tableName(){
  14. return 'class_exam_printer';
  15. }
  16. public function getExamTime($examId){
  17. $sql = "select add_time from ".$this->tableName()." where exam_id = {$examId} and type = 0";
  18. return $this->getCommandBuilder()->createSqlCommand($sql)->queryScalar();
  19. }
  20. /**
  21. * 获取上一次考试id
  22. * @param $examId
  23. * @return bool|CDbDataReader|mixed|string
  24. */
  25. public function getPreExamId($examId,$subjectId,$classId){
  26. $examDate = $this->getExamTime($examId);
  27. if(in_array($subjectId, Yii::app()->params['mathSubjectId']))
  28. {
  29. $subjectCondition = ' e.subject_id in ('.implode(',',Yii::app()->params['mathSubjectId']).')';
  30. }else
  31. {
  32. $subjectCondition = ' e.subject_id = '.$subjectId;
  33. }
  34. $sql = "select cep.exam_id,e.exam_group_id from class_exam_printer as cep left join exam as e on e.exam_id = cep.exam_id where {$subjectCondition} and cep.add_time < {$examDate} and e.class_id = {$classId} and cep.type = 0 and e.status = 1 order by add_time desc";
  35. return $this->getCommandBuilder()->createSqlCommand($sql)->queryRow();
  36. }
  37. /**
  38. * 获取上一次考试id
  39. * @param $examId
  40. * @return bool|CDbDataReader|mixed|string
  41. */
  42. public function getTirdExamIds($examId,$subjectId,$classId){
  43. $examDate = $this->getExamTime($examId);
  44. $sql = "select cep.exam_id,cep.add_time from class_exam_printer as cep left join exam as e on e.exam_id = cep.exam_id where e.subject_id = {$subjectId} and cep.add_time <= {$examDate} and e.class_id = {$classId} and cep.type = 0 and e.status = 1 order by add_time desc limit 3";
  45. return $this->getCommandBuilder()->createSqlCommand($sql)->queryAll();
  46. }
  47. /**
  48. * (1)、如果这学校从来生成过数学个性化学习宝,他们依然会有标注任务,这种学校不能带有New标签。
  49. (2)、我们对于学校新使用定义的的情况1,该学校下,数学个性化学习宝(含试用和正式使用)的最早生成日期,与该份试卷的考试日期,差距在一个月内,即为学校新使用。
  50. 3)、我们对于学校新使用定义的情况2,该学校下,最近一次数学个性化学习宝的使用时间,与该份试卷的考试时间,间隔超过了3个月,我们认为该学校是长期未使用个性化学习宝,现在又用了,我们需要重点维护,也视为学校新使用。
  51. (4)、只要达到了上述的情况1或情况2,即显示new标签。
  52. * @return array|CDbDataReader
  53. */
  54. public function getNewLabel($examTime)
  55. {
  56. $isNewLabel = false;
  57. $month_time = 30 * 24 * 3600;
  58. $time = time();
  59. $sql = "select add_time from class_exam_printer where type = 2 order by add_time asc";
  60. $earliestTime = $this->getCommandBuilder()->createSqlCommand($sql)->queryScalar();
  61. if ($time - $earliestTime <= $month_time) {
  62. $isNewLabel = true;
  63. }
  64. if (!$isNewLabel) {
  65. $sql = "select add_time from class_exam_printer where type = 2 order by add_time desc";
  66. $nearestTime = $this->getCommandBuilder()->createSqlCommand($sql)->queryScalar();
  67. if ($nearestTime - $examTime > $month_time * 3) {
  68. $isNewLabel = true;
  69. }
  70. }
  71. return $isNewLabel;
  72. }
  73. }