MoodCommentsModel.class.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace Home\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 MoodCommentsModel extends CommonModel
  12. {
  13. // 数据自动校验
  14. protected $_validate = array(
  15. // 添加
  16. array('content', 'CheckContent', '{%bubble_comments_content_error}', 1, 'callback', 1),
  17. array('mood_id', 'CheckMoodId', '{%bubble_comments_mood_id_error}', 1, 'callback', 1),
  18. array('reply_id', 'CheckReplyId', '{%bubble_comments_reply_id_error}', 2, 'callback', 1),
  19. array('parent_id', 'CheckParentId', '{%bubble_comments_parent_id_error}', 2, 'callback', 1),
  20. );
  21. /**
  22. * [CheckContent 评论内容校验]
  23. * @author Devil
  24. * @blog http://gong.gg/
  25. * @version 0.0.1
  26. * @datetime 2016-12-13T19:29:30+0800
  27. * @param [string] $value [校验值]
  28. */
  29. public function CheckContent($value)
  30. {
  31. $len = Utf8Strlen($value);
  32. return ($len > 0 && $len <= 255);
  33. }
  34. /**
  35. * [CheckMoodId 说说是否存在]
  36. * @author Devil
  37. * @blog http://gong.gg/
  38. * @version 0.0.1
  39. * @datetime 2016-12-10T14:09:40+0800
  40. * @param [string] $value [校验值]
  41. */
  42. public function CheckMoodId($value)
  43. {
  44. $id = $this->db(0)->table('__MOOD__')->where(array('id'=>$value))->getField('id');
  45. return !empty($id);
  46. }
  47. /**
  48. * [CheckReplyId 被回复的评论是否存在]
  49. * @author Devil
  50. * @blog http://gong.gg/
  51. * @version 0.0.1
  52. * @datetime 2016-12-10T14:09:40+0800
  53. * @param [string] $value [校验值]
  54. */
  55. public function CheckReplyId($value)
  56. {
  57. if(empty($value))
  58. {
  59. return true;
  60. }
  61. $id = $this->db(0)->where(array('id'=>$value))->getField('id');
  62. return !empty($id);
  63. }
  64. /**
  65. * [CheckParentId 被回复的父评论是否存在]
  66. * @author Devil
  67. * @blog http://gong.gg/
  68. * @version 0.0.1
  69. * @datetime 2016-12-10T14:09:40+0800
  70. * @param [string] $value [校验值]
  71. */
  72. public function CheckParentId($value)
  73. {
  74. if(empty($value))
  75. {
  76. return true;
  77. }
  78. $id = $this->db(0)->where(array('id'=>$value))->getField('id');
  79. return !empty($id);
  80. }
  81. }
  82. ?>