NavigationModel.class.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 NavigationModel extends CommonModel
  12. {
  13. // 数据自动校验
  14. protected $_validate = array(
  15. // 自定义导航
  16. array('name', 'CheckName', '{%navheader_name_format}', 1, 'callback', 5),
  17. array('url', 'CheckUrl', '{%navheader_url_format}', 1, 'callback', 5),
  18. array('is_show', array(0,1), '{%common_show_tips}', 1, 'in', 5),
  19. array('is_new_window_open', array(0,1), '{%common_new_window_open_tips}', 1, 'in', 5),
  20. // 文章分类导航
  21. array('value', 'CheckArticleClassValue', '{%navheader_article_class_id_format}', 1, 'callback', 6),
  22. array('is_show', array(0,1), '{%common_show_tips}', 1, 'in', 6),
  23. array('is_new_window_open', array(0,1), '{%common_new_window_open_tips}', 1, 'in', 6),
  24. // 自定义页面导航
  25. array('value', 'CheckCustomViewValue', '{%navheader_customview_id_format}', 1, 'callback', 7),
  26. array('is_show', array(0,1), '{%common_show_tips}', 1, 'in', 7),
  27. array('is_new_window_open', array(0,1), '{%common_new_window_open_tips}', 1, 'in', 7),
  28. // 删除校验是否存在子级
  29. array('id', 'IsExistSon', '{%common_is_exist_son_error}', 1, 'callback', 4),
  30. );
  31. /**
  32. * [CheckName 导航名称校验]
  33. * @author Devil
  34. * @blog http://gong.gg/
  35. * @version 0.0.1
  36. * @datetime 2016-12-13T19:29:30+0800
  37. */
  38. public function CheckName()
  39. {
  40. $len = Utf8Strlen(I('name'));
  41. return ($len >= 2 && $len <= 16);
  42. }
  43. /**
  44. * [CheckUrl url地址校验]
  45. * @author Devil
  46. * @blog http://gong.gg/
  47. * @version 0.0.1
  48. * @datetime 2016-12-13T15:12:32+0800
  49. */
  50. public function CheckUrl()
  51. {
  52. return (preg_match('/'.L('common_regex_url').'/', I('url')) == 1) ? true : false;
  53. }
  54. /**
  55. * [CheckArticleClassValue 文章分类id校验]
  56. * @author Devil
  57. * @blog http://gong.gg/
  58. * @version 0.0.1
  59. * @datetime 2016-12-13T15:12:32+0800
  60. */
  61. public function CheckArticleClassValue()
  62. {
  63. return ($this->db(0)->table('__ARTICLE_CLASS__')->where(array('id'=>I('value')))->count() == 1);
  64. }
  65. /**
  66. * [CheckCustomViewValue 自定义页面id校验]
  67. * @author Devil
  68. * @blog http://gong.gg/
  69. * @version 0.0.1
  70. * @datetime 2016-12-13T15:12:32+0800
  71. */
  72. public function CheckCustomViewValue()
  73. {
  74. return ($this->db(0)->table('__CUSTOM_VIEW__')->where(array('id'=>I('value')))->count() == 1);
  75. }
  76. /**
  77. * [IsExistSon 校验节点下是否存在子级数据]
  78. * @author Devil
  79. * @blog http://gong.gg/
  80. * @version 0.0.1
  81. * @datetime 2016-12-10T14:09:40+0800
  82. */
  83. public function IsExistSon()
  84. {
  85. return ($this->db(0)->where(array('pid'=>I('id')))->count() == 0);
  86. }
  87. }
  88. ?>