Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Model\Table;
- use App\Model\Entity\School;
- use Cake\ORM\Query;
- use Cake\ORM\RulesChecker;
- use Cake\ORM\Table;
- use Cake\Validation\Validator;
- /**
- * Schools Model
- *
- * @property \Cake\ORM\Association\HasMany $ClassLevels
- * @property \Cake\ORM\Association\HasMany $PsgGroups
- * @property \Cake\ORM\Association\HasMany $Registration
- * @property \Cake\ORM\Association\HasMany $SchoolCategories
- * @property \Cake\ORM\Association\HasMany $SchoolEvents
- * @property \Cake\ORM\Association\HasMany $Studentparents
- * @property \Cake\ORM\Association\HasMany $Students
- * @property \Cake\ORM\Association\HasMany $Teachers
- */
- class SchoolsTable extends Table
- {
- /**
- * Initialize method
- *
- * @param array $config The configuration for the Table.
- * @return void
- */
- public function initialize(array $config)
- {
- parent::initialize($config);
- $this->table('schools');
- $this->displayField('name');
- $this->primaryKey('id');
- $this->hasMany('ClassLevels', [
- 'foreignKey' => 'school_id'
- ]);
- $this->hasMany('PsgGroups', [
- 'foreignKey' => 'school_id'
- ]);
- $this->hasMany('Registration', [
- 'foreignKey' => 'school_id'
- ]);
- $this->hasMany('SchoolCategories', [
- 'foreignKey' => 'school_id'
- ]);
- $this->hasMany('SchoolEvents', [
- 'foreignKey' => 'school_id'
- ]);
- $this->hasMany('Studentparents', [
- 'foreignKey' => 'school_id'
- ]);
- $this->hasMany('Students', [
- 'foreignKey' => 'school_id'
- ]);
- $this->hasMany('Teachers', [
- 'foreignKey' => 'school_id'
- ]);
- }
- /**
- * Default validation rules.
- *
- * @param \Cake\Validation\Validator $validator Validator instance.
- * @return \Cake\Validation\Validator
- */
- public function validationDefault(Validator $validator)
- {
- $validator
- ->add('id', 'valid', ['rule' => 'numeric'])
- ->allowEmpty('id', 'create');
- $validator
- ->allowEmpty('name');
- $validator
- ->requirePresence('uen_number', 'create')
- ->notEmpty('uen_number');
- $validator
- ->requirePresence('address1', 'create')
- ->notEmpty('address1');
- $validator
- ->requirePresence('address2', 'create')
- ->notEmpty('address2');
- $validator
- ->requirePresence('city', 'create')
- ->notEmpty('city');
- $validator
- ->requirePresence('post_code', 'create')
- ->notEmpty('post_code');
- $validator
- ->requirePresence('country', 'create')
- ->notEmpty('country');
- $validator
- ->requirePresence('telephone', 'create')
- ->notEmpty('telephone');
- $validator
- ->requirePresence('fax', 'create')
- ->notEmpty('fax');
- $validator
- ->add('email', 'valid', ['rule' => 'email'])
- ->requirePresence('email', 'create')
- ->notEmpty('email');
- $validator
- ->requirePresence('location', 'create')
- ->notEmpty('location');
- $validator
- ->requirePresence('zone', 'create')
- ->notEmpty('zone');
- $validator
- ->requirePresence('area', 'create')
- ->notEmpty('area');
- $validator
- ->requirePresence('type', 'create')
- ->notEmpty('type');
- $validator
- ->requirePresence('levels', 'create')
- ->notEmpty('levels');
- $validator
- ->requirePresence('photo', 'create')
- ->notEmpty('photo');
- // $validator
- // ->requirePresence('photo_dir', 'create')
- // ->notEmpty('photo_dir');
- return $validator;
- }
- /**
- * Returns a rules checker object that will be used for validating
- * application integrity.
- *
- * @param \Cake\ORM\RulesChecker $rules The rules object to be modified.
- * @return \Cake\ORM\RulesChecker
- */
- public function buildRules(RulesChecker $rules)
- {
- $rules->add($rules->isUnique(['email']));
- return $rules;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement