1 | <?php |
||
19 | abstract class BaseWidget extends Widget |
||
20 | { |
||
21 | use ModuleTrait; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | public $entity; |
||
27 | |||
28 | /** |
||
29 | * @var null|\yii\db\ActiveRecord |
||
30 | */ |
||
31 | public $model; |
||
32 | |||
33 | /** |
||
34 | * @var null|integer; |
||
35 | */ |
||
36 | public $targetId; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | public $voteUrl; |
||
42 | |||
43 | /** |
||
44 | * @var null|\hauntd\vote\models\VoteAggregate |
||
45 | */ |
||
46 | public $aggregateModel; |
||
47 | |||
48 | /** |
||
49 | * @var null|integer |
||
50 | */ |
||
51 | public $userValue; |
||
52 | |||
53 | /** |
||
54 | * @var string |
||
55 | */ |
||
56 | public $jsBeforeVote; |
||
57 | |||
58 | /** |
||
59 | * @var string |
||
60 | */ |
||
61 | public $jsAfterVote; |
||
62 | |||
63 | /** |
||
64 | * @var string |
||
65 | */ |
||
66 | public $jsCodeKey = 'vote'; |
||
67 | |||
68 | /** |
||
69 | * @var string |
||
70 | */ |
||
71 | public $jsErrorVote; |
||
72 | |||
73 | /** |
||
74 | * @var string |
||
75 | */ |
||
76 | public $jsShowMessage; |
||
77 | |||
78 | /** |
||
79 | * @var string |
||
80 | */ |
||
81 | public $jsChangeCounters; |
||
82 | |||
83 | /** |
||
84 | * @var array |
||
85 | */ |
||
86 | public $options = []; |
||
87 | |||
88 | /** |
||
89 | * @var string |
||
90 | */ |
||
91 | public $viewFile = 'vote'; |
||
92 | |||
93 | /** |
||
94 | * @var array |
||
95 | */ |
||
96 | public $viewParams = []; |
||
97 | |||
98 | /** |
||
99 | * @var bool |
||
100 | */ |
||
101 | protected $_behaviorIncluded; |
||
102 | |||
103 | /** |
||
104 | * @return string |
||
105 | */ |
||
106 | public function getSelector() |
||
111 | |||
112 | /** |
||
113 | * @inheritdoc |
||
114 | * @throws \yii\base\InvalidConfigException |
||
115 | */ |
||
116 | public function init() |
||
130 | |||
131 | /** |
||
132 | * Initialize widget with default options. |
||
133 | * |
||
134 | * @throws \yii\base\InvalidConfigException |
||
135 | */ |
||
136 | public function initDefaults() |
||
137 | { |
||
138 | $this->voteUrl = isset($this->voteUrl) ?: Yii::$app->getUrlManager()->createUrl(['vote/default/vote']); |
||
139 | $this->targetId = isset($this->targetId) ?: $this->model->getPrimaryKey(); |
||
140 | |||
141 | if (!isset($this->aggregateModel)) { |
||
142 | $this->aggregateModel = $this->isBehaviorIncluded() ? |
||
143 | $this->model->getVoteAggregate($this->entity) : |
||
144 | VoteAggregate::findOne([ |
||
145 | 'entity' => $this->getModule()->encodeEntity($this->entity), |
||
146 | 'target_id' => $this->targetId, |
||
147 | ]); |
||
148 | } |
||
149 | |||
150 | if (!isset($this->userValue)) { |
||
151 | $this->userValue = $this->isBehaviorIncluded() ? $this->model->getUserValue($this->entity) : null; |
||
152 | } |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * Registers jQuery handler. |
||
157 | */ |
||
158 | protected function registerJs() |
||
179 | |||
180 | /** |
||
181 | * @param array $params |
||
182 | * @return array |
||
183 | */ |
||
184 | protected function getViewParams(array $params) |
||
188 | |||
189 | /** |
||
190 | * @return bool |
||
191 | */ |
||
192 | protected function isBehaviorIncluded() |
||
208 | } |
||
209 |