Doctrine 1.2.4
Doctrine_Template_Listener_Timestampable Class Reference

Inherits Doctrine_Record_Listener.

Public Member Functions

 __construct (array $options)
 
 getOption ($name)
 
 getOptions ()
 
 getTimestamp ($type, $conn=null)
 
 preDqlUpdate (Doctrine_Event $event)
 
 preInsert (Doctrine_Event $event)
 
 preUpdate (Doctrine_Event $event)
 
 setOption ($name, $value=null)
 

Detailed Description

Definition at line 34 of file Timestampable.php.

Constructor & Destructor Documentation

Doctrine_Template_Listener_Timestampable::__construct ( array  $options)

__construct

Parameters
string$options
Returns
void

Definition at line 49 of file Timestampable.php.

{
$this->_options = $options;
}

Member Function Documentation

Doctrine_Record_Listener::getOption (   $name)
inherited

getOption returns the value of given option

Parameters
string$namethe name of the option
Returns
mixed the value of given option

Definition at line 74 of file Listener.php.

{
if (isset($this->_options[$name])) {
return $this->_options[$name];
}
return null;
}
Doctrine_Record_Listener::getOptions ( )
inherited

getOptions returns all options of this template and the associated values

Returns
array all options and their values

Definition at line 62 of file Listener.php.

{
return $this->_options;
}
Doctrine_Template_Listener_Timestampable::getTimestamp (   $type,
  $conn = null 
)

Gets the timestamp in the correct format based on the way the behavior is configured

Parameters
string$type
Returns
void

Definition at line 122 of file Timestampable.php.

{
$options = $this->_options[$type];
if ($options['expression'] !== false && is_string($options['expression'])) {
return new Doctrine_Expression($options['expression'], $conn);
} else {
if ($options['type'] == 'date') {
return date($options['format'], time());
} else if ($options['type'] == 'timestamp') {
return date($options['format'], time());
} else {
return time();
}
}
}
Doctrine_Template_Listener_Timestampable::preDqlUpdate ( Doctrine_Event  $event)

Set the updated field for dql update queries

Parameters
Doctrine_Event$evet
Returns
void

Definition at line 102 of file Timestampable.php.

{
if ( ! $this->_options['updated']['disabled']) {
$params = $event->getParams();
$updatedName = $event->getInvoker()->getTable()->getFieldName($this->_options['updated']['name']);
$field = $params['alias'] . '.' . $updatedName;
$query = $event->getQuery();
if ( ! $query->contains($field)) {
$query->set($field, '?', $this->getTimestamp('updated', $event->getInvoker()->getTable()->getConnection()));
}
}
}
Doctrine_Template_Listener_Timestampable::preInsert ( Doctrine_Event  $event)

Set the created and updated Timestampable columns when a record is inserted

Parameters
Doctrine_Event$event
Returns
void

Definition at line 60 of file Timestampable.php.

{
if ( ! $this->_options['created']['disabled']) {
$createdName = $event->getInvoker()->getTable()->getFieldName($this->_options['created']['name']);
$modified = $event->getInvoker()->getModified();
if ( ! isset($modified[$createdName])) {
$event->getInvoker()->$createdName = $this->getTimestamp('created', $event->getInvoker()->getTable()->getConnection());
}
}
if ( ! $this->_options['updated']['disabled'] && $this->_options['updated']['onInsert']) {
$updatedName = $event->getInvoker()->getTable()->getFieldName($this->_options['updated']['name']);
$modified = $event->getInvoker()->getModified();
if ( ! isset($modified[$updatedName])) {
$event->getInvoker()->$updatedName = $this->getTimestamp('updated', $event->getInvoker()->getTable()->getConnection());
}
}
}
Doctrine_Template_Listener_Timestampable::preUpdate ( Doctrine_Event  $event)

Set updated Timestampable column when a record is updated

Parameters
Doctrine_Event$evet
Returns
void

Definition at line 85 of file Timestampable.php.

{
if ( ! $this->_options['updated']['disabled']) {
$updatedName = $event->getInvoker()->getTable()->getFieldName($this->_options['updated']['name']);
$modified = $event->getInvoker()->getModified();
if ( ! isset($modified[$updatedName])) {
$event->getInvoker()->$updatedName = $this->getTimestamp('updated', $event->getInvoker()->getTable()->getConnection());
}
}
}
Doctrine_Record_Listener::setOption (   $name,
  $value = null 
)
inherited

setOption sets an option in order to allow flexible listener

Parameters
mixed$namethe name of the option to set
mixed$valuethe value of the option

Definition at line 47 of file Listener.php.

{
if (is_array($name)) {
$this->_options = Doctrine_Lib::arrayDeepMerge($this->_options, $name);
} else {
$this->_options[$name] = $value;
}
}

The documentation for this class was generated from the following file: