forked from ShNURoK42/linuxforum
/
Post.php
68 lines (60 loc) · 1.38 KB
/
Post.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
<?php
namespace post;
use Yii;
use yii\base\InvalidConfigException;
use post\models\Post as PostModel;
use topic\models\Topic;
use user\models\User;
class Post extends \yii\base\Widget
{
/**
* @var PostModel
*/
public $model;
/**
* @var Topic
*/
public $topic;
/**
* @var integer
*/
public $count;
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if (!$this->model instanceof PostModel) {
throw new InvalidConfigException('The "model" property must be set.');
}
if ($this->topic instanceof Topic && $this->model->user instanceof User) {
if ($this->topic->first_post_user_id == $this->model->user->id) {
$this->model->setIsTopicAuthor(true);
}
}
if (!isset($this->count)) {
$this->count = 1;
}
$this->registerClientScript();
}
/**
* @inheritdoc
*/
public function run()
{
echo $this->render('post', [
'model' => $this->model,
'count' => $this->count,
]);
}
/**
* Register widget client scripts.
*/
protected function registerClientScript()
{
$view = $this->getView();
PostAsset::register($view);
$view->registerJs("jQuery('#p" . $this->model->id . "').post();");
}
}