/
Userstampable.php
73 lines (68 loc) · 1.78 KB
/
Userstampable.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* Easily add created and updated at timestamps to your doctrine records
*/
class Userstampable extends Doctrine_Template
{
/**
* Array of timestampable options
*
* @var string
*/
protected $_options = array(
'created' => array(
'name' => 'created_by_user_id',
'type' => 'integer',
'length' => '5',
'options' => array(),
'disabled' => false,
),
'updated' => array(
'name' => 'updated_by_user_id',
'type' => 'integer',
'length' => '5',
'options' => array(),
'disabled' => false,
)
);
/**
* __construct
*
* @param string $array
* @return void
*/
public function __construct(array $options = array())
{
$this->_options = Doctrine_Lib::arrayDeepMerge($this->_options, $options);
}
/**
* setTableDefinition
*
* @return void
*/
public function setTableDefinition()
{
if( ! $this->_options['created']['disabled']) {
$this->hasColumn($this->_options['created']['name'],
$this->_options['created']['type'],
$this->_options['created']['length'],
$this->_options['created']['options']);
}
if( ! $this->_options['updated']['disabled']) {
$this->hasColumn($this->_options['updated']['name'],
$this->_options['updated']['type'],
$this->_options['updated']['length'],
$this->_options['updated']['options']);
}
$this->addListener(new Listener_Userstampable($this->_options));
}
public function setUp()
{
$this->hasOne('sfGuardUser as CreatedBy', array(
'local' => $this->_options['created']['name'],
'foreign' => 'id'));
$this->hasOne('sfGuardUser as UpdatedBy', array(
'local' => $this->_options['updated']['name'],
'foreign' => 'id'));
}
}