WRestModelBehavior.php
816 Bytes
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
<?php
/**
* @author Weavora Team <hello@weavora.com>
* @link http://weavora.com
* @copyright Copyright (c) 2011 Weavora LLC
*/
class WRestModelBehavior extends CActiveRecordBehavior
{
public function getAllAttributes()
{
$owner = $this->getOwner();
return $owner->getAttributes();
}
public function getCreateAttributes()
{
return $this->_getAttributesByScenario('insert');
}
public function getUpdateAttributes()
{
return $this->_getAttributesByScenario('update');
}
private function _getAttributesByScenario($scenario){
$owner = $this->getOwner();
$owner->setScenario($scenario);
$validators = $owner->getValidators();
$attributes = array();
foreach ($validators as $validator){
$attributes = array_merge($attributes, $validator->attributes);
}
return $attributes;
}
}