|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace app\backend\actions; |
|
4
|
|
|
|
|
5
|
|
|
use app\models\Object; |
|
6
|
|
|
use app\models\Property; |
|
7
|
|
|
use app\properties\PropertyHandlers; |
|
8
|
|
|
use yii; |
|
9
|
|
|
use yii\base\Action; |
|
10
|
|
|
|
|
11
|
|
|
class PropertyHandler extends Action |
|
12
|
|
|
{ |
|
13
|
|
|
public $modelName = null; |
|
14
|
|
|
public $objectId = null; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @throws yii\web\ServerErrorHttpException |
|
18
|
|
|
*/ |
|
19
|
|
|
public function init() |
|
20
|
|
|
{ |
|
21
|
|
|
parent::init(); |
|
22
|
|
|
\yii\helpers\VarDumper::dump( |
|
23
|
|
|
[ |
|
24
|
|
|
'modelname' => $this->modelName |
|
25
|
|
|
], |
|
26
|
|
|
10, |
|
27
|
|
|
true |
|
28
|
|
|
); |
|
29
|
|
|
\Yii::$app->end(); |
|
30
|
|
|
if (null === $this->modelName) { |
|
31
|
|
|
throw new yii\web\ServerErrorHttpException('Model name should be set in controller actions'); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
if (!is_subclass_of($this->modelName, '\yii\db\ActiveRecord')) { |
|
|
|
|
|
|
35
|
|
|
throw new yii\web\ServerErrorHttpException('Model class does not exists'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
$this->objectId = Object::getForClass($this->modelName); |
|
39
|
|
|
if (null === $this->objectId) { |
|
40
|
|
|
throw new yii\web\ServerErrorHttpException('Object does not exists for model.'); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param null $property_id |
|
46
|
|
|
* @param null $handler_action |
|
47
|
|
|
* @param null $model_id |
|
48
|
|
|
* @return mixed |
|
49
|
|
|
*/ |
|
50
|
|
|
public function run($property_id = null, $handler_action = null, $model_id = null) |
|
51
|
|
|
{ |
|
52
|
|
|
if (null === $handler_action |
|
53
|
|
|
|| null === $property_id |
|
54
|
|
|
|| null === $model_id) |
|
55
|
|
|
{ |
|
56
|
|
|
return ''; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$property = Property::findById($property_id); |
|
60
|
|
|
if (null === $property) { |
|
61
|
|
|
return ''; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
$actionParams = [ |
|
65
|
|
|
'model_name' => $this->modelName, |
|
66
|
|
|
'model_id' => $model_id, |
|
67
|
|
|
'object_id' => $this->objectId, |
|
68
|
|
|
'property' => $property, |
|
69
|
|
|
]; |
|
70
|
|
|
$propertyHandler = PropertyHandlers::createHandler($property->handler); |
|
71
|
|
|
return $propertyHandler->runAction($handler_action, $actionParams); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
?> |