-
Notifications
You must be signed in to change notification settings - Fork 22
/
LteChatMessage.php
108 lines (95 loc) · 2.34 KB
/
LteChatMessage.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace insolita\wgadminlte;
use yii\bootstrap\Widget;
use yii\helpers\Html;
/**
* LteChatMessage
*
* @example
* <?php
* echo LteChatBox::begin(['type'=>'info']);
* echo LteChatMessage::widget([
* 'author'=>'Jane Smith',
* 'message'=>'Hi guys! How are you?',
* 'image'=>'http://site.ru/images/123.jpg',
* 'imageAlt'=>'some text',
* 'createdAt'=>'2017-03-29 23:33',
* 'isRight' =>false
* ']);
* echo LteChatMessage::widget([
* 'author'=>'Artur Green',
* 'message'=>'Look this cool video',
* 'image'=>'http://site.ru/images/321.jpg',
* 'createdAt'=>'2017-03-29 23:18',
* 'isRight' =>true
* ']);
* echo LteChatBox::end();
* ?>
*
*/
class LteChatMessage extends Widget
{
/**
* @var string
*/
public $author = '';
/**
* @var string
*/
public $message = '';
/**
* @var string
*/
public $image = '';
/**
* @var string - alternative image text
*/
public $imageAlt = '';
/**
* @var string
*/
public $createdAt;
/**
* @var bool right-oriented
*/
public $isRight = false;
/**
* @var string
*/
public $template
= <<<HTML
<div {options}>
<div class="direct-chat-info clearfix">
<span class="direct-chat-name pull-{direction1}">{author}</span>
<span class="direct-chat-timestamp pull-{direction2}">{createdAt}</span>
</div>
<img class="direct-chat-img" src="{image}" alt="{imageAlt}">
<div class="direct-chat-text">
{message}
</div>
</div>
HTML;
/**
* @return string
*/
public function run()
{
Html::addCssClass($this->options, 'direct-chat-msg');
if($this->isRight){
Html::addCssClass($this->options, 'right');
}
return strtr(
$this->template,
[
'{options}' => Html::renderTagAttributes($this->options),
'{author}' => $this->author,
'{message}' => $this->message,
'{createdAt}' => $this->createdAt,
'{image}' => $this->image,
'{imageAlt}' => $this->imageAlt,
'{direction1}' =>$this->isRight?'right':'left',
'{direction2}' =>$this->isRight?'left':'right',
]
);
}
}