Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
/*
4
 * This file is part of the symfony package.
5
 * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
 
11
/**
12
 * A timestampable implementation BC with symfony <= 1.2.
13
 *
14
 * @package     sfPropelPlugin
15
 * @subpackage  behavior
16
 * @author      Kris Wallsmith <kris.wallsmith@symfony-project.com>
17
 * @version     SVN: $Id: SfPropelBehaviorTimestampable.php 23310 2009-10-24 15:27:41Z Kris.Wallsmith $
18
 */
19
class SfPropelBehaviorTimestampable extends SfPropelBehaviorBase
20
{
21
  protected $parameters = array(
22
    'create_column' => null,
23
    'update_column' => null,
24
  );
25
 
26
  public function preInsert()
27
  {
28
    if ($this->isDisabled())
29
    {
30
      return;
31
    }
32
 
33
    if ($column = $this->getParameter('create_column'))
34
    {
35
      return <<<EOF
36
if (!\$this->isColumnModified({$this->getTable()->getColumn($column)->getConstantName()}))
37
{
38
  \$this->set{$this->getTable()->getColumn($column)->getPhpName()}(time());
39
}
40
 
41
EOF;
42
    }
43
  }
44
 
45
  public function preSave()
46
  {
47
    if ($this->isDisabled())
48
    {
49
      return;
50
    }
51
 
52
    if ($column = $this->getParameter('update_column'))
53
    {
54
      return <<<EOF
55
if (\$this->isModified() && !\$this->isColumnModified({$this->getTable()->getColumn($column)->getConstantName()}))
56
{
57
  \$this->set{$this->getTable()->getColumn($column)->getPhpName()}(time());
58
}
59
 
60
EOF;
61
    }
62
  }
63
}