SExamPushTopicsSetting.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: chenye
  5. * Date: 2018/5/29
  6. * Time: 09:58
  7. * 班级表
  8. */
  9. class SExamPushTopicsSetting extends MyActiveRecord
  10. {
  11. public static function model($className = __CLASS__)
  12. {
  13. return parent::model($className);
  14. }
  15. public function tableName()
  16. {
  17. return 'exam_push_topics_setting';
  18. }
  19. /**
  20. * 保存试题推送
  21. */
  22. public function updateSetting($examId,$examGroupId,$topics){
  23. $sql = "select exam_id from exam_push_topics_setting where exam_id = {$examId}";
  24. $info = $this->getCommandBuilder()->createSqlCommand($sql)->queryColumn();
  25. if($info){
  26. $rs=$this->getCommandBuilder()->createSqlCommand("update exam_push_topics_setting set topic_ids='".$topics."',datetime='".time()."' where exam_id='".$examId."'")->execute();
  27. }else{
  28. $rs=$this->getCommandBuilder()->createSqlCommand("insert into exam_push_topics_setting(`exam_group_id`,`exam_id`,`topic_ids`,`datetime`) values('".$examGroupId."','".$examId."','".$topics."','".time()."')")->execute();
  29. }
  30. return $rs;
  31. }
  32. /**
  33. * 批量保存试题推送
  34. */
  35. public function updateSettingBatch($examIds,$examGroupId,$topics){
  36. if(!$examIds || !is_array($examIds)) return false;
  37. if($topics){
  38. $topics=jsonEncode($topics);
  39. $sql="replace into exam_push_topics_setting(`exam_group_id`,`exam_id`,`topic_ids`,`datetime`) values ";
  40. $value=array();
  41. foreach ($examIds as $id){
  42. $value[]="('".$examGroupId."','".$id."','".$topics."','".time()."')";
  43. }
  44. $rs=$this->getCommandBuilder()->createSqlCommand($sql.implode(',',$value))->execute();
  45. }else{
  46. $sql="delete from exam_push_topics_setting where exam_id in(".implode(',',$examIds).")";
  47. $rs=$this->getCommandBuilder()->createSqlCommand($sql)->execute();
  48. }
  49. return $rs;
  50. }
  51. /**
  52. * 读取试题推送设置
  53. */
  54. public function getTopicSetting($examGroupId){
  55. $sql="select exam_id,topic_ids from exam_push_topics_setting where exam_group_id='".$examGroupId."'";
  56. $info = $this->getCommandBuilder()->createSqlCommand($sql)->queryAll();
  57. return $info;
  58. }
  59. }