CourseModel.class.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace Admin\Model;
  3. use Think\Model;
  4. /**
  5. * 教师课程模型
  6. * @author Devil
  7. * @blog http://gong.gg/
  8. * @version 0.0.1
  9. * @datetime 2016-12-01T21:51:08+0800
  10. */
  11. class CourseModel extends CommonModel
  12. {
  13. // 数据自动校验
  14. protected $_validate = array(
  15. // 添加,编辑
  16. array('teacher_id', 'IsExistTeacher', '{%course_teacher_tips}', 1, 'callback', 3),
  17. array('class_id', 'IsExistClass', '{%course_class_tips}', 1, 'callback', 3),
  18. array('subject_id', 'IsExistSubject', '{%course_subject_tips}', 1, 'callback', 3),
  19. array('week_id', 'IsExistWeek', '{%course_week_tips}', 1, 'callback', 3),
  20. array('interval_id', 'IsExistInterval', '{%course_interval_tips}', 1, 'callback', 3),
  21. array('room_id', 'IsExistRoom', '{%course_room_tips}', 1, 'callback', 3),
  22. );
  23. /**
  24. * [IsExistTeacher 教师是否存在]
  25. * @author Devil
  26. * @blog http://gong.gg/
  27. * @version 0.0.1
  28. * @datetime 2016-12-10T14:09:40+0800
  29. * @return [boolean] [存在true, 不存在false]
  30. */
  31. public function IsExistTeacher()
  32. {
  33. $temp = $this->db(0)->table('__TEACHER__')->field(array('id'))->find(I('teacher_id'));
  34. return !empty($temp);
  35. }
  36. /**
  37. * [IsExistClass 班级id是否存在]
  38. * @author Devil
  39. * @blog http://gong.gg/
  40. * @version 0.0.1
  41. * @datetime 2016-12-21T22:13:52+0800
  42. * @return [boolean] [存在true, 不存在false]
  43. */
  44. public function IsExistClass()
  45. {
  46. // 当用户操作自身的情况下不需要校验
  47. $class = $this->db(0)->table('__CLASS__')->field(array('id', 'pid'))->find(I('class_id'));
  48. if(empty($class))
  49. {
  50. return false;
  51. }
  52. if($class['pid'] == 0)
  53. {
  54. // 是否存在子级
  55. $count = $this->db(0)->table('__CLASS__')->where(array('pid'=>$class['id']))->count();
  56. return ($count == 0);
  57. } else {
  58. // 父级是否存在
  59. $count = $this->db(0)->table('__CLASS__')->where(array('id'=>$class['pid']))->count();
  60. return ($count > 0);
  61. }
  62. }
  63. /**
  64. * [IsExistRoom 教室id是否存在]
  65. * @author Devil
  66. * @blog http://gong.gg/
  67. * @version 0.0.1
  68. * @datetime 2016-12-21T22:13:52+0800
  69. * @return [boolean] [存在true, 不存在false]
  70. */
  71. public function IsExistRoom()
  72. {
  73. // 当用户操作自身的情况下不需要校验
  74. $class = $this->db(0)->table('__ROOM__')->field(array('id', 'pid'))->find(I('room_id'));
  75. if(empty($class))
  76. {
  77. return false;
  78. }
  79. if($class['pid'] == 0)
  80. {
  81. // 是否存在子级
  82. $count = $this->db(0)->table('__ROOM__')->where(array('pid'=>$class['id']))->count();
  83. return ($count == 0);
  84. } else {
  85. // 父级是否存在
  86. $count = $this->db(0)->table('__ROOM__')->where(array('id'=>$class['pid']))->count();
  87. return ($count > 0);
  88. }
  89. }
  90. /**
  91. * [IsExistSubject 教师关联的科目是否存在]
  92. * @author Devil
  93. * @blog http://gong.gg/
  94. * @version 0.0.1
  95. * @datetime 2016-12-10T14:09:40+0800
  96. * @return [boolean] [存在true, 不存在false]
  97. */
  98. public function IsExistSubject()
  99. {
  100. $temp = $this->db(0)->table('__TEACHER_SUBJECT__')->alias('AS ts')->join('__SUBJECT__ AS s ON ts.subject_id = s.id')->where(array('s.id'=>I('subject_id')))->field(array('s.id AS id'))->find();
  101. return !empty($temp);
  102. }
  103. /**
  104. * [IsExistWeek 周天是否存在]
  105. * @author Devil
  106. * @blog http://gong.gg/
  107. * @version 0.0.1
  108. * @datetime 2016-12-10T14:09:40+0800
  109. * @return [boolean] [存在true, 不存在false]
  110. */
  111. public function IsExistWeek()
  112. {
  113. $temp = $this->db(0)->table('__WEEK__')->field(array('id'))->find(I('week_id'));
  114. return !empty($temp);
  115. }
  116. /**
  117. * [IsExistInterval 时段是否存在]
  118. * @author Devil
  119. * @blog http://gong.gg/
  120. * @version 0.0.1
  121. * @datetime 2016-12-10T14:09:40+0800
  122. * @return [boolean] [存在true, 不存在false]
  123. */
  124. public function IsExistInterval()
  125. {
  126. $temp = $this->db(0)->table('__INTERVAL__')->field(array('id'))->find(I('interval_id'));
  127. return !empty($temp);
  128. }
  129. }
  130. ?>