optional fields
This commit is contained in:
parent
542f9b0d72
commit
536c4fd55a
@ -58,11 +58,15 @@ class Doctrine_Template_Listener_Timestampable extends Doctrine_Record_Listener
|
|||||||
*/
|
*/
|
||||||
public function preInsert(Doctrine_Event $event)
|
public function preInsert(Doctrine_Event $event)
|
||||||
{
|
{
|
||||||
$createdName = $this->_options['created']['name'];
|
if(!$this->_options['created']['disabled']) {
|
||||||
$updatedName = $this->_options['updated']['name'];
|
$createdName = $this->_options['created']['name'];
|
||||||
|
$event->getInvoker()->$createdName = $this->getTimestamp('created');
|
||||||
$event->getInvoker()->$createdName = $this->getTimestamp('created');
|
}
|
||||||
$event->getInvoker()->$updatedName = $this->getTimestamp('updated');
|
|
||||||
|
if(!$this->_options['updated']['disabled']) {
|
||||||
|
$updatedName = $this->_options['updated']['name'];
|
||||||
|
$event->getInvoker()->$updatedName = $this->getTimestamp('updated');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,9 +77,10 @@ class Doctrine_Template_Listener_Timestampable extends Doctrine_Record_Listener
|
|||||||
*/
|
*/
|
||||||
public function preUpdate(Doctrine_Event $event)
|
public function preUpdate(Doctrine_Event $event)
|
||||||
{
|
{
|
||||||
$updatedName = $this->_options['updated']['name'];
|
if(!$this->_options['updated']['disabled']) {
|
||||||
|
$updatedName = $this->_options['updated']['name'];
|
||||||
$event->getInvoker()->$updatedName = $this->getTimestamp('updated');
|
$event->getInvoker()->$updatedName = $this->getTimestamp('updated');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,10 +42,12 @@ class Doctrine_Template_Timestampable extends Doctrine_Template
|
|||||||
protected $_options = array('created' => array('name' => 'created_at',
|
protected $_options = array('created' => array('name' => 'created_at',
|
||||||
'type' => 'timestamp',
|
'type' => 'timestamp',
|
||||||
'format' => 'Y-m-d H:i:s',
|
'format' => 'Y-m-d H:i:s',
|
||||||
|
'disabled' => false,
|
||||||
'options' => array()),
|
'options' => array()),
|
||||||
'updated' => array('name' => 'updated_at',
|
'updated' => array('name' => 'updated_at',
|
||||||
'type' => 'timestamp',
|
'type' => 'timestamp',
|
||||||
'format' => 'Y-m-d H:i:s',
|
'format' => 'Y-m-d H:i:s',
|
||||||
|
'disabled' => false,
|
||||||
'options' => array()));
|
'options' => array()));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,9 +68,12 @@ class Doctrine_Template_Timestampable extends Doctrine_Template
|
|||||||
*/
|
*/
|
||||||
public function setTableDefinition()
|
public function setTableDefinition()
|
||||||
{
|
{
|
||||||
$this->hasColumn($this->_options['created']['name'], $this->_options['created']['type'], null, $this->_options['created']['options']);
|
if(!$this->_options['created']['disabled']) {
|
||||||
$this->hasColumn($this->_options['updated']['name'], $this->_options['updated']['type'], null, $this->_options['updated']['options']);
|
$this->hasColumn($this->_options['created']['name'], $this->_options['created']['type'], null, $this->_options['created']['options']);
|
||||||
|
}
|
||||||
|
if(!$this->_options['updated']['disabled']) {
|
||||||
|
$this->hasColumn($this->_options['updated']['name'], $this->_options['updated']['type'], null, $this->_options['updated']['options']);
|
||||||
|
}
|
||||||
$this->addListener(new Doctrine_Template_Listener_Timestampable($this->_options));
|
$this->addListener(new Doctrine_Template_Listener_Timestampable($this->_options));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -273,10 +273,12 @@ class User extends Doctrine_Record
|
|||||||
$this->actAs('Timestampable', array('created' => array('name' => 'created_at',
|
$this->actAs('Timestampable', array('created' => array('name' => 'created_at',
|
||||||
'type' => 'timestamp',
|
'type' => 'timestamp',
|
||||||
'format' => 'Y-m-d H:i:s',
|
'format' => 'Y-m-d H:i:s',
|
||||||
|
'disabled' => false,
|
||||||
'options' => array()),
|
'options' => array()),
|
||||||
'updated' => array('name' => 'updated_at',
|
'updated' => array('name' => 'updated_at',
|
||||||
'type' => 'timestamp',
|
'type' => 'timestamp',
|
||||||
'format' => 'Y-m-d H:i:s',
|
'format' => 'Y-m-d H:i:s',
|
||||||
|
'disabled' => false,
|
||||||
'options' => array())));
|
'options' => array())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -305,6 +307,28 @@ User:
|
|||||||
type: string(255)
|
type: string(255)
|
||||||
</code>
|
</code>
|
||||||
|
|
||||||
|
If you are only interested in keeping using only one of the columns, such as a created_at timestamp, but not a an updated_at field, set the flag disabled=>true for either of the fields as in the example below.
|
||||||
|
|
||||||
|
YAML Example
|
||||||
|
<code type="yaml">
|
||||||
|
---
|
||||||
|
User:
|
||||||
|
actAs:
|
||||||
|
Timestampable:
|
||||||
|
created:
|
||||||
|
name: created_at
|
||||||
|
type: timestamp
|
||||||
|
format:Y-m-d H:i:s
|
||||||
|
options: []
|
||||||
|
updated:
|
||||||
|
disabled: true
|
||||||
|
columns:
|
||||||
|
username:
|
||||||
|
type: string(125)
|
||||||
|
password:
|
||||||
|
type: string(255)
|
||||||
|
</code>
|
||||||
|
|
||||||
+++ Sluggable
|
+++ Sluggable
|
||||||
If you do not specify the columns to create the slug from, it will default to just using the toString() method on the model.
|
If you do not specify the columns to create the slug from, it will default to just using the toString() method on the model.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user