-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chat.php
52 lines (41 loc) · 1.3 KB
/
Chat.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
<?php
namespace poprigun\chat;
use Yii;
use yii\base\Widget;
use yii\helpers\Html;
class Chat extends Widget{
private static $sessionName = 'pchat_asset_url';
public static $defaultUserAvatar = '/img/avatar.png';
public static $defaultUserName = 'Annonimus';
public static $defaultCount = 10;
/**
* @var string template path
*/
public $template;
/**
* @var array widget plugin options
*/
protected $options = [];
public $showUserAvatar = true;
public $showLastMessage = true;
public $count;
public function init(){
parent::init();
$this->initOptions();
$this->registerAssets();
}
public function initOptions(){
$this->options['showUserAvatar'] = $this->showUserAvatar;
$this->options['showLastMessage '] = $this->showLastMessage ;
$this->options['count'] = isset($this->count) ? $this->count : self::$defaultCount;
}
public function registerAssets(){
$view = $this->getView();
ChatAssets::register($view);
Yii::$app->session->set(self::$sessionName,ChatAssets::register($view)->baseUrl);
echo $this->renderFile($this->template,['options' => $this->options]);
}
public static function getSessionName(){
return self::$sessionName;
}
}