FractionModel.class.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 FractionModel extends CommonModel
  12. {
  13. // 数据自动校验
  14. protected $_validate = array(
  15. // 添加,编辑
  16. array('score', 'CheckScore', '{%fraction_score_format}', 1, 'callback', 3),
  17. array('score_id', 'IsExistScoreId', '{%fraction_score_id_error}', 1, 'callback', 3),
  18. array('subject_id', 'IsExistSubjectId', '{%fraction_subject_error}', 1, 'callback', 3),
  19. array('student_id', 'IsExistStudentId', '{%fraction_student_id_error}', 1, 'callback', 3),
  20. array('comment', 'CheckComment', '{%fraction_comment_format}', 1, 'callback', 3),
  21. );
  22. /**
  23. * [CheckComment 教师点评校验]
  24. * @author Devil
  25. * @blog http://gong.gg/
  26. * @version 0.0.1
  27. * @datetime 2016-12-13T19:29:30+0800
  28. */
  29. public function CheckComment()
  30. {
  31. return (Utf8Strlen(I('comment')) <= 255);
  32. }
  33. /**
  34. * [CheckScore 分数校验]
  35. * @author Devil
  36. * @blog http://gong.gg/
  37. * @version 0.0.1
  38. * @datetime 2016-12-13T19:29:30+0800
  39. */
  40. public function CheckScore()
  41. {
  42. return (preg_match('/'.L('common_regex_score').'/', I('score')) == 1) ? true : false;
  43. }
  44. /**
  45. * [IsExistScoreId 成绩分类id是否存在]
  46. * @author Devil
  47. * @blog http://gong.gg/
  48. * @version 0.0.1
  49. * @datetime 2016-12-10T14:09:40+0800
  50. * @return [boolean] [存在true, 不存在false]
  51. */
  52. public function IsExistScoreId()
  53. {
  54. $id = $this->db(0)->table('__SCORE__')->where(array('id'=>I('score_id')))->getField('id');
  55. return !empty($id);
  56. }
  57. /**
  58. * [IsExistSubjectId 科目分类id是否存在]
  59. * @author Devil
  60. * @blog http://gong.gg/
  61. * @version 0.0.1
  62. * @datetime 2016-12-10T14:09:40+0800
  63. * @return [boolean] [存在true, 不存在false]
  64. */
  65. public function IsExistSubjectId()
  66. {
  67. $id = $this->db(0)->table('__SUBJECT__')->where(array('id'=>I('subject_id')))->getField('id');
  68. return !empty($id);
  69. }
  70. /**
  71. * [IsExistStudentId 学生id是否存在]
  72. * @author Devil
  73. * @blog http://gong.gg/
  74. * @version 0.0.1
  75. * @datetime 2016-12-10T14:09:40+0800
  76. * @return [boolean] [存在true, 不存在false]
  77. */
  78. public function IsExistStudentId()
  79. {
  80. $id = $this->db(0)->table('__STUDENT__')->where(array('id'=>I('student_id')))->getField('id');
  81. return !empty($id);
  82. }
  83. }
  84. ?>