Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2015
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. <?php
  2. namespace App\Model\Table;
  3.  
  4. use App\Model\Entity\School;
  5. use Cake\ORM\Query;
  6. use Cake\ORM\RulesChecker;
  7. use Cake\ORM\Table;
  8. use Cake\Validation\Validator;
  9.  
  10. /**
  11. * Schools Model
  12. *
  13. * @property \Cake\ORM\Association\HasMany $ClassLevels
  14. * @property \Cake\ORM\Association\HasMany $PsgGroups
  15. * @property \Cake\ORM\Association\HasMany $Registration
  16. * @property \Cake\ORM\Association\HasMany $SchoolCategories
  17. * @property \Cake\ORM\Association\HasMany $SchoolEvents
  18. * @property \Cake\ORM\Association\HasMany $Studentparents
  19. * @property \Cake\ORM\Association\HasMany $Students
  20. * @property \Cake\ORM\Association\HasMany $Teachers
  21. */
  22. class SchoolsTable extends Table
  23. {
  24.  
  25. /**
  26. * Initialize method
  27. *
  28. * @param array $config The configuration for the Table.
  29. * @return void
  30. */
  31. public function initialize(array $config)
  32. {
  33. parent::initialize($config);
  34.  
  35. $this->table('schools');
  36. $this->displayField('name');
  37. $this->primaryKey('id');
  38.  
  39. $this->hasMany('ClassLevels', [
  40. 'foreignKey' => 'school_id'
  41. ]);
  42. $this->hasMany('PsgGroups', [
  43. 'foreignKey' => 'school_id'
  44. ]);
  45. $this->hasMany('Registration', [
  46. 'foreignKey' => 'school_id'
  47. ]);
  48. $this->hasMany('SchoolCategories', [
  49. 'foreignKey' => 'school_id'
  50. ]);
  51. $this->hasMany('SchoolEvents', [
  52. 'foreignKey' => 'school_id'
  53. ]);
  54. $this->hasMany('Studentparents', [
  55. 'foreignKey' => 'school_id'
  56. ]);
  57. $this->hasMany('Students', [
  58. 'foreignKey' => 'school_id'
  59. ]);
  60. $this->hasMany('Teachers', [
  61. 'foreignKey' => 'school_id'
  62. ]);
  63. }
  64.  
  65. /**
  66. * Default validation rules.
  67. *
  68. * @param \Cake\Validation\Validator $validator Validator instance.
  69. * @return \Cake\Validation\Validator
  70. */
  71. public function validationDefault(Validator $validator)
  72. {
  73. $validator
  74. ->add('id', 'valid', ['rule' => 'numeric'])
  75. ->allowEmpty('id', 'create');
  76.  
  77. $validator
  78. ->allowEmpty('name');
  79.  
  80. $validator
  81. ->requirePresence('uen_number', 'create')
  82. ->notEmpty('uen_number');
  83.  
  84. $validator
  85. ->requirePresence('address1', 'create')
  86. ->notEmpty('address1');
  87.  
  88. $validator
  89. ->requirePresence('address2', 'create')
  90. ->notEmpty('address2');
  91.  
  92. $validator
  93. ->requirePresence('city', 'create')
  94. ->notEmpty('city');
  95.  
  96. $validator
  97. ->requirePresence('post_code', 'create')
  98. ->notEmpty('post_code');
  99.  
  100. $validator
  101. ->requirePresence('country', 'create')
  102. ->notEmpty('country');
  103.  
  104. $validator
  105. ->requirePresence('telephone', 'create')
  106. ->notEmpty('telephone');
  107.  
  108. $validator
  109. ->requirePresence('fax', 'create')
  110. ->notEmpty('fax');
  111.  
  112. $validator
  113. ->add('email', 'valid', ['rule' => 'email'])
  114. ->requirePresence('email', 'create')
  115. ->notEmpty('email');
  116.  
  117. $validator
  118. ->requirePresence('location', 'create')
  119. ->notEmpty('location');
  120.  
  121. $validator
  122. ->requirePresence('zone', 'create')
  123. ->notEmpty('zone');
  124.  
  125. $validator
  126. ->requirePresence('area', 'create')
  127. ->notEmpty('area');
  128.  
  129. $validator
  130. ->requirePresence('type', 'create')
  131. ->notEmpty('type');
  132.  
  133. $validator
  134. ->requirePresence('levels', 'create')
  135. ->notEmpty('levels');
  136.  
  137. $validator
  138. ->requirePresence('photo', 'create')
  139. ->notEmpty('photo');
  140.  
  141. // $validator
  142. // ->requirePresence('photo_dir', 'create')
  143. // ->notEmpty('photo_dir');
  144.  
  145. return $validator;
  146. }
  147.  
  148. /**
  149. * Returns a rules checker object that will be used for validating
  150. * application integrity.
  151. *
  152. * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
  153. * @return \Cake\ORM\RulesChecker
  154. */
  155. public function buildRules(RulesChecker $rules)
  156. {
  157. $rules->add($rules->isUnique(['email']));
  158. return $rules;
  159. }
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement