CommentWidget.php
2.44 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace common\widgets;
use yii\base\Widget;
use yii\helpers\Html;
class CommentWidget extends Widget
{
public $comments;
public $reload;
private function html ($d, $lvl)
{
echo '
<li class="comment" level="' . $lvl . '">
<div class="comment_body" comment_id="'. $d['id'] .'">
<div class="comment_info">
<span class="comment_username">' . $d['username'] . '</span>
<span class="comment_created_time">' . date('F j Y h:i', strtotime($d['created_at'])) . '</span>
<div class="dropdown">
<button class="btn btn-default btn-xs dropdown-toggle" type="button" id="" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
Manage
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
<li><a href="#">Edit</a></li>
<li><a href="#">Hide</a></li>
<li><a href="#">Delete</a></li>
</ul>
</div>
</div>
<div class="message">
<p>' . $d['content'] . '</p>
</div>
<button type="button" class="btn btn-default btn-xs btn-reply">Reply</button>
</div>
</li>';
}
private function display(array $comments, $level = 0)
{
foreach ($comments as $info)
{
echo '<ul>';
$this->html($info, $level + 1);
if (!empty($info['childs']))
{
$this->display($info['childs'], $level + 1);
}
echo '</ul>';
}
if (isset($this->reload) && $this->reload == false)
{
}
}
private function field()
{
echo '<div class="container new_comment">
<div class="form-group">
<label for="comment">Comment:</label>
<textarea class="form-control" rows="5" id="comment"></textarea>
<button type="button" class="btn btn-info btn-md btn-send">Send</button>
</div>
</div>';
}
public function init()
{
}
public function run()
{
echo '<div class="container" id="comment_wrapper">';
$this->display($this->comments);
echo '</div>';
$this->field();
}
}