1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- /**
- * Created by PhpStorm.
- * User: chenye
- * Date: 2018/5/29
- * Time: 09:58
- * 班级表
- */
- class SExtendSubject extends MyActiveRecord
- {
- public static function model($className = __CLASS__)
- {
- return parent::model($className);
- }
- public function tableName()
- {
- return 'extend_subject';
- }
- public function insertExtendSubject($subjectIds){
- if(!$subjectIds){
- return false;
- }
- $sql="replace into extend_subject(`subject_id`,`subject_name`) values ";
- $values=array();
- foreach ($subjectIds as $key => $val){
- $values[]="('".$key."','".$val."')";
- }
- $sql.=implode(',',$values);
- if($this->getDbConnection()->createCommand($sql)->execute()){
- return true;
- }
- return false;
- }
- //校验科目是否已使用
- public function checkSubjectUsed($subjectId){
- if(!$subjectId){
- return false;
- }
- //查询绑定教师
- $sql="select teacher_id from teacher where subjects ='{$subjectId}' limit 1";
- $teacher=$this->getDbConnection()->createCommand($sql)->queryRow();
- if($teacher){
- return true;
- }
- //查询班级
- $sql="select class_id from class_subject_relation where subject_id ='{$subjectId}' limit 1";
- $classTeacher=$this->getDbConnection()->createCommand($sql)->queryRow();
- if($classTeacher){
- return true;
- }
- //走班设置
- $sql="select subject_id from classified where subject_id ='{$subjectId}' limit 1";
- $classified=$this->getDbConnection()->createCommand($sql)->queryRow();
- if($classified){
- return true;
- }
- //考试
- $sql="select exam_id from exam where subject_id ='{$subjectId}' limit 1";
- $exam=$this->getDbConnection()->createCommand($sql)->queryRow();
- if($exam){
- return true;
- }
- //知了考试
- $sql="select zl_exam_id from zl_exam where find_in_set('".$subjectId."',zl_subject_ids) limit 1";
- $exam=$this->getDbConnection()->createCommand($sql)->queryRow();
- if($exam){
- return true;
- }
- return false;
- }
- //删除自定义科目
- public function delExtendSubject($subjectId){
- if(!$subjectId){
- return false;
- }
- if($this->getDbConnection()->createCommand("delete from extend_subject where subject_id='{$subjectId}'")->execute()){
- return true;
- }
- return false;
- }
- }
|