SExtendSubject.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: chenye
  5. * Date: 2018/5/29
  6. * Time: 09:58
  7. * 班级表
  8. */
  9. class SExtendSubject extends MyActiveRecord
  10. {
  11. public static function model($className = __CLASS__)
  12. {
  13. return parent::model($className);
  14. }
  15. public function tableName()
  16. {
  17. return 'extend_subject';
  18. }
  19. public function insertExtendSubject($subjectIds){
  20. if(!$subjectIds){
  21. return false;
  22. }
  23. $sql="replace into extend_subject(`subject_id`,`subject_name`) values ";
  24. $values=array();
  25. foreach ($subjectIds as $key => $val){
  26. $values[]="('".$key."','".$val."')";
  27. }
  28. $sql.=implode(',',$values);
  29. if($this->getDbConnection()->createCommand($sql)->execute()){
  30. return true;
  31. }
  32. return false;
  33. }
  34. //校验科目是否已使用
  35. public function checkSubjectUsed($subjectId){
  36. if(!$subjectId){
  37. return false;
  38. }
  39. //查询绑定教师
  40. $sql="select teacher_id from teacher where subjects ='{$subjectId}' limit 1";
  41. $teacher=$this->getDbConnection()->createCommand($sql)->queryRow();
  42. if($teacher){
  43. return true;
  44. }
  45. //查询班级
  46. $sql="select class_id from class_subject_relation where subject_id ='{$subjectId}' limit 1";
  47. $classTeacher=$this->getDbConnection()->createCommand($sql)->queryRow();
  48. if($classTeacher){
  49. return true;
  50. }
  51. //走班设置
  52. $sql="select subject_id from classified where subject_id ='{$subjectId}' limit 1";
  53. $classified=$this->getDbConnection()->createCommand($sql)->queryRow();
  54. if($classified){
  55. return true;
  56. }
  57. //考试
  58. $sql="select exam_id from exam where subject_id ='{$subjectId}' limit 1";
  59. $exam=$this->getDbConnection()->createCommand($sql)->queryRow();
  60. if($exam){
  61. return true;
  62. }
  63. //知了考试
  64. $sql="select zl_exam_id from zl_exam where find_in_set('".$subjectId."',zl_subject_ids) limit 1";
  65. $exam=$this->getDbConnection()->createCommand($sql)->queryRow();
  66. if($exam){
  67. return true;
  68. }
  69. return false;
  70. }
  71. //删除自定义科目
  72. public function delExtendSubject($subjectId){
  73. if(!$subjectId){
  74. return false;
  75. }
  76. if($this->getDbConnection()->createCommand("delete from extend_subject where subject_id='{$subjectId}'")->execute()){
  77. return true;
  78. }
  79. return false;
  80. }
  81. }