12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- /**
- * Created by PhpStorm.
- * User: chenye
- * Date: 2018/5/29
- * Time: 09:58
- * 班级表
- */
- class SExamPushTopicsSetting extends MyActiveRecord
- {
- public static function model($className = __CLASS__)
- {
- return parent::model($className);
- }
- public function tableName()
- {
- return 'exam_push_topics_setting';
- }
- /**
- * 保存试题推送
- */
- public function updateSetting($examId,$examGroupId,$topics){
- $sql = "select exam_id from exam_push_topics_setting where exam_id = {$examId}";
- $info = $this->getCommandBuilder()->createSqlCommand($sql)->queryColumn();
- if($info){
- $rs=$this->getCommandBuilder()->createSqlCommand("update exam_push_topics_setting set topic_ids='".$topics."',datetime='".time()."' where exam_id='".$examId."'")->execute();
- }else{
- $rs=$this->getCommandBuilder()->createSqlCommand("insert into exam_push_topics_setting(`exam_group_id`,`exam_id`,`topic_ids`,`datetime`) values('".$examGroupId."','".$examId."','".$topics."','".time()."')")->execute();
- }
- return $rs;
- }
- /**
- * 批量保存试题推送
- */
- public function updateSettingBatch($examIds,$examGroupId,$topics){
- if(!$examIds || !is_array($examIds)) return false;
- if($topics){
- $topics=jsonEncode($topics);
- $sql="replace into exam_push_topics_setting(`exam_group_id`,`exam_id`,`topic_ids`,`datetime`) values ";
- $value=array();
- foreach ($examIds as $id){
- $value[]="('".$examGroupId."','".$id."','".$topics."','".time()."')";
- }
- $rs=$this->getCommandBuilder()->createSqlCommand($sql.implode(',',$value))->execute();
- }else{
- $sql="delete from exam_push_topics_setting where exam_id in(".implode(',',$examIds).")";
- $rs=$this->getCommandBuilder()->createSqlCommand($sql)->execute();
- }
- return $rs;
- }
- /**
- * 读取试题推送设置
- */
- public function getTopicSetting($examGroupId){
- $sql="select exam_id,topic_ids from exam_push_topics_setting where exam_group_id='".$examGroupId."'";
- $info = $this->getCommandBuilder()->createSqlCommand($sql)->queryAll();
- return $info;
- }
- }
|