Skip to content

Commit

Permalink
enregistremant automatique de la date de creation et de modification …
Browse files Browse the repository at this point in the history
…des organisations
  • Loading branch information
willkoua committed May 26, 2016
1 parent 5292eda commit a3be234
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
40 changes: 40 additions & 0 deletions config/Migrations/20160526192549_update_organizations_fields.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

use Phinx\Migration\AbstractMigration;

class UpdateOrganizationsFields extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$table = $this->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();
}
}
1 change: 1 addition & 0 deletions src/Controller/OrganizationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
46 changes: 46 additions & 0 deletions src/Model/Entity/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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
*
Expand Down
8 changes: 8 additions & 0 deletions src/Model/Table/OrganizationsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public function initialize(array $config)
'joinTable' => 'organizations_members'
]
);

$this->addBehavior('Timestamp');
}

/**
Expand Down Expand Up @@ -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');

Expand Down

0 comments on commit a3be234

Please sign in to comment.