summaryrefslogtreecommitdiff
path: root/generator/after-bake/src/Model/Table/EquipementsTable.php
diff options
context:
space:
mode:
authorLudovic Pouzenc <ludovic@pouzenc.fr>2016-05-29 22:17:21 +0200
committerLudovic Pouzenc <ludovic@pouzenc.fr>2016-05-29 22:17:21 +0200
commite7114fbf6efce4985ea9146e4664e12ee546c343 (patch)
tree3fe53236f490e1ef71b2cf9d71ef31bea359c314 /generator/after-bake/src/Model/Table/EquipementsTable.php
parenta7889db127f8c15a6609ed2344e94d0a9f068a9e (diff)
downloadchd_gestion-e7114fbf6efce4985ea9146e4664e12ee546c343.zip
chd_gestion-e7114fbf6efce4985ea9146e4664e12ee546c343.tar.gz
chd_gestion-e7114fbf6efce4985ea9146e4664e12ee546c343.tar.bz2
Equipements : allow multiple Equipements to be added at once.Unfinished
Ipmgmt causes constraint violation if set for more than once Equipement.
Diffstat (limited to 'generator/after-bake/src/Model/Table/EquipementsTable.php')
-rw-r--r--generator/after-bake/src/Model/Table/EquipementsTable.php139
1 files changed, 139 insertions, 0 deletions
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 @@
+<?php
+namespace App\Model\Table;
+
+use App\Model\Entity\Equipement;
+use Cake\ORM\Query;
+use Cake\ORM\RulesChecker;
+use Cake\ORM\Table;
+use Cake\Validation\Validator;
+use Search\Manager;
+
+/**
+ * Equipements Model
+ *
+ *
+ * @property \Cake\ORM\Association\BelongsTo $Equipements
+ * @property \Cake\ORM\Association\BelongsTo $Services
+ * @property \Cake\ORM\Association\BelongsTo $EquipementModeles
+ * @property \Cake\ORM\Association\BelongsTo $Ipmgmt
+ * @property \Cake\ORM\Association\BelongsTo $Relais
+ * @property \Cake\ORM\Association\BelongsTo $EquipementModes
+ */
+class EquipementsTable extends Table
+{
+
+ /**
+ * Initialize method
+ *
+ * @param array $config The configuration for the Table.
+ * @return void
+ */
+ public function initialize(array $config)
+ {
+ parent::initialize($config);
+
+ $this->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;
+ }
+}