From e7114fbf6efce4985ea9146e4664e12ee546c343 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Sun, 29 May 2016 22:17:21 +0200 Subject: Equipements : allow multiple Equipements to be added at once.Unfinished Ipmgmt causes constraint violation if set for more than once Equipement. --- .../src/Model/Table/EquipementsTable.php | 139 +++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 generator/after-bake/src/Model/Table/EquipementsTable.php (limited to 'generator/after-bake/src/Model/Table/EquipementsTable.php') diff --git a/generator/after-bake/src/Model/Table/EquipementsTable.php b/generator/after-bake/src/Model/Table/EquipementsTable.php new file mode 100644 index 0000000..f5e2f05 --- /dev/null +++ b/generator/after-bake/src/Model/Table/EquipementsTable.php @@ -0,0 +1,139 @@ +table('equipements'); + $this->displayField('title'); + $this->primaryKey('id'); + + $this->addBehavior('Search.Search'); + + $this->belongsTo('Equipements', [ + 'foreignKey' => 'uplink_id' + ]); + $this->belongsTo('Services', [ + 'foreignKey' => 'service_id' + ]); + $this->belongsTo('EquipementModeles', [ + 'foreignKey' => 'equipement_modele_id', + 'joinType' => 'INNER' + ]); + $this->belongsTo('Ipmgmt', [ + 'foreignKey' => 'ipmgmt_id' + ]); + $this->belongsTo('Relais', [ + 'foreignKey' => 'relais_id' + ]); + $this->belongsTo('EquipementModes', [ + 'foreignKey' => 'equipement_mode_id', + 'joinType' => 'INNER' + ]); + } + /** + * Search plugin queries configuration + */ + public function searchConfiguration() + { + $search = new Manager($this); + $search + ->like('q', [ + 'before' => true, + 'after' => true, + 'field' => [$this->aliasField('mac'), $this->aliasField('ipmgmt_id'), $this->aliasField('hostname')] + ]) + ->value('equipement_modele_id', [ 'field' => $this->aliasField('equipement_modele_id')]) + ->value('relais_id', [ 'field' => $this->aliasField('relais_id')]); + return $search; + } + + /** + * 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 + ->requirePresence('mac', 'create') + ->notEmpty('mac') + ->add('mac', 'validFormat',[ + 'rule' => array('custom', '/^[0-9A-F]{2}(:[0-9A-F]{2}){5}$/'), + 'message' => 'Please use XX:XX:XX:XX:XX:XX MAC format.' + ]) + ->add('mac', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']); + + $validator + ->requirePresence('hostname', 'create') + ->notEmpty('hostname'); + + $validator + ->allowEmpty('description'); + + $validator + ->add('date_achat', 'valid', ['rule' => 'date']) + ->allowEmpty('date_achat'); + + $validator + ->add('date_hs', 'valid', ['rule' => 'date']) + ->allowEmpty('date_hs'); + + $validator + ->allowEmpty('notes'); + + 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(['mac'])); + $rules->add($rules->existsIn(['ipmgmt_id'], 'Ipmgmt')); + $rules->add($rules->existsIn(['uplink_id'], 'Equipements')); + $rules->add($rules->existsIn(['service_id'], 'Services')); + $rules->add($rules->existsIn(['equipement_modele_id'], 'EquipementModeles')); + $rules->add($rules->existsIn(['relais_id'], 'Relais')); + $rules->add($rules->existsIn(['equipement_mode_id'], 'EquipementModes')); + return $rules; + } +} -- cgit v1.1