ClassModel.class.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 ClassModel extends CommonModel
  12. {
  13. // 数据自动校验
  14. protected $_validate = array(
  15. // 添加,编辑
  16. array('name', 'CheckName', '{%common_name_format}', 1, 'callback', 3),
  17. array('is_enable', array(0,1), '{%common_enable_tips}', 1, 'in', 3),
  18. array('sort', 'CheckSort', '{%common_sort_error}', 1, 'function', 3),
  19. array('pid', 'CheckMyPid', '{%common_pid_eq_myid_format}', 1, 'callback', 2),
  20. // 删除校验是否存在子级
  21. array('id', 'IsExistSon', '{%common_is_exist_son_error}', 1, 'callback', 5),
  22. );
  23. /**
  24. * [CheckName 班级名称校验]
  25. * @author Devil
  26. * @blog http://gong.gg/
  27. * @version 0.0.1
  28. * @datetime 2016-12-13T19:29:30+0800
  29. */
  30. public function CheckName()
  31. {
  32. $len = Utf8Strlen(I('name'));
  33. return ($len >= 2 && $len <= 16);
  34. }
  35. /**
  36. * [CheckMyPid pid是否是当前节点校验]
  37. * @author Devil
  38. * @blog http://gong.gg/
  39. * @version 0.0.1
  40. * @datetime 2016-12-13T19:32:40+0800
  41. */
  42. public function CheckMyPid()
  43. {
  44. return (I('id') != I('pid'));
  45. }
  46. /**
  47. * [IsExistSon 校验节点下是否存在子级数据]
  48. * @author Devil
  49. * @blog http://gong.gg/
  50. * @version 0.0.1
  51. * @datetime 2016-12-10T14:09:40+0800
  52. */
  53. public function IsExistSon()
  54. {
  55. return ($this->db(0)->where(array('pid'=>I('id')))->count() == 0);
  56. }
  57. }
  58. ?>