From a3be234cb30e275c9cf8fc4c0e4a3bcb872da8d9 Mon Sep 17 00:00:00 2001 From: willkoua Date: Thu, 26 May 2016 19:29:26 -0400 Subject: [PATCH] enregistremant automatique de la date de creation et de modification des organisations --- ...0526192549_update_organizations_fields.php | 40 ++++++++++++++++ src/Controller/OrganizationsController.php | 1 + src/Model/Entity/Organization.php | 46 +++++++++++++++++++ src/Model/Table/OrganizationsTable.php | 8 ++++ 4 files changed, 95 insertions(+) create mode 100644 config/Migrations/20160526192549_update_organizations_fields.php diff --git a/config/Migrations/20160526192549_update_organizations_fields.php b/config/Migrations/20160526192549_update_organizations_fields.php new file mode 100644 index 00000000..6ec65522 --- /dev/null +++ b/config/Migrations/20160526192549_update_organizations_fields.php @@ -0,0 +1,40 @@ +table('organizations'); + + $table->removeColumn('updated'); + $table->removeColumn('created'); + + $table->addColumn('created', 'datetime', ['default' => null, 'null' => true]); + $table->addColumn('modified', 'datetime', ['default' => null, 'null' => true]); + + $table->update(); + } +} diff --git a/src/Controller/OrganizationsController.php b/src/Controller/OrganizationsController.php index 4af37eb3..0643b77c 100644 --- a/src/Controller/OrganizationsController.php +++ b/src/Controller/OrganizationsController.php @@ -327,6 +327,7 @@ public function submit() if ($this->request->is('post')) { $organization = $this->Organizations->patchEntity($organization, $this->request->data); + if ($this->Organizations->save($organization)) { $this->Flash->success(__('The organization has been saved.')); return $this->redirect(['action' => 'submit', 'controller' => 'Projects']); diff --git a/src/Model/Entity/Organization.php b/src/Model/Entity/Organization.php index 9e58bd82..776ba0cd 100644 --- a/src/Model/Entity/Organization.php +++ b/src/Model/Entity/Organization.php @@ -98,6 +98,26 @@ public function getOwners() return $this->_properties['owners']; } + /** + * Get the created + * + * @return array created + */ + public function getCreated() + { + return $this->_properties['created']; + } + + /** + * Get the modified + * + * @return array modified + */ + public function getModified() + { + return $this->_properties['modified']; + } + /** * Get the members * @@ -251,6 +271,32 @@ public function editOwners($owners) return $owners; } + /** + * Set the created + * + * @param string $created created + * + * @return string $created + */ + public function editCreated($created) + { + $this->set('created', $created); + return $created; + } + + /** + * Set the modified + * + * @param string $modified modified + * + * @return string $modified + */ + public function editModified($modified) + { + $this->set('modified', $modified); + return $modified; + } + /** * Set the members * diff --git a/src/Model/Table/OrganizationsTable.php b/src/Model/Table/OrganizationsTable.php index a77df335..86921b3b 100644 --- a/src/Model/Table/OrganizationsTable.php +++ b/src/Model/Table/OrganizationsTable.php @@ -70,6 +70,8 @@ public function initialize(array $config) 'joinTable' => 'organizations_members' ] ); + + $this->addBehavior('Timestamp'); } /** @@ -120,6 +122,12 @@ public function validationDefault(Validator $validator) $validator ->allowEmpty('description'); + $validator + ->allowEmpty('created', 'create', ['message' => __('date created not define.')]); + + $validator + ->allowEmpty('modified', 'update', ['message' => __('date modified not define.')]); + $validator ->notEmpty('isValidated');