|
|
@ -8,6 +8,7 @@ |
|
|
|
namespace yii\behaviors; |
|
|
|
namespace yii\behaviors; |
|
|
|
|
|
|
|
|
|
|
|
use yii\base\Behavior; |
|
|
|
use yii\base\Behavior; |
|
|
|
|
|
|
|
use yii\base\Event; |
|
|
|
use yii\db\Expression; |
|
|
|
use yii\db\Expression; |
|
|
|
use yii\db\ActiveRecord; |
|
|
|
use yii\db\ActiveRecord; |
|
|
|
|
|
|
|
|
|
|
@ -64,30 +65,27 @@ class AutoTimestamp extends Behavior |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function events() |
|
|
|
public function events() |
|
|
|
{ |
|
|
|
{ |
|
|
|
$events = array(); |
|
|
|
$events = $this->attributes; |
|
|
|
$behavior = $this; |
|
|
|
foreach ($events as $i => $event) { |
|
|
|
foreach ($this->attributes as $event => $attributes) { |
|
|
|
$events[$i] = 'updateTimestamp'; |
|
|
|
if (!is_array($attributes)) { |
|
|
|
|
|
|
|
$attributes = array($attributes); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$events[$event] = function () use ($behavior, $attributes) { |
|
|
|
|
|
|
|
$behavior->updateTimestamp($attributes); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return $events; |
|
|
|
return $events; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Updates the attributes with the current timestamp. |
|
|
|
* Updates the attributes with the current timestamp. |
|
|
|
* @param array $attributes list of attributes to be updated. |
|
|
|
* @param Event $event |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function updateTimestamp($attributes) |
|
|
|
public function updateTimestamp($event) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
$attributes = isset($this->attributes[$event->name]) ? (array)$this->attributes[$event->name] : array(); |
|
|
|
|
|
|
|
if (!empty($attributes)) { |
|
|
|
$timestamp = $this->evaluateTimestamp(); |
|
|
|
$timestamp = $this->evaluateTimestamp(); |
|
|
|
foreach ($attributes as $attribute) { |
|
|
|
foreach ($attributes as $attribute) { |
|
|
|
$this->owner->$attribute = $timestamp; |
|
|
|
$this->owner->$attribute = $timestamp; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Gets the current timestamp. |
|
|
|
* Gets the current timestamp. |
|
|
|