FractionImportModel.class.php 2.7 KB

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