-
Notifications
You must be signed in to change notification settings - Fork 0
/
GravatarSidebarUserPanel.php
68 lines (54 loc) · 1.52 KB
/
GravatarSidebarUserPanel.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 memclutter\AdminLTE;
use cebe\gravatar\Gravatar;
use yii\base\InvalidValueException;
class GravatarSidebarUserPanel extends SidebarUserPanel
{
/**
* @var string email attribute name for gravatar
*/
public $emailAttribute = 'email';
/**
* @var array
*/
public $gravatarOptions = [];
/**
* @var array
*/
public $imgOptions = [];
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if (empty($this->emailAttribute)) {
throw new InvalidValueException('Missing required attribute emailAttribute');
}
if (!$this->model->hasAttribute($this->emailAttribute)) {
throw new InvalidValueException('Email attribute not found');
}
if (!isset($this->imgOptions['alt'])) {
$this->imgOptions['alt'] = $this->getUserName();
}
if (!isset($this->imgOptions['title'])) {
$this->imgOptions['title'] = $this->getUserName();
}
if (!isset($this->imgOptions['class'])) {
$this->imgOptions['class'] = 'img-circle';
}
$this->gravatarOptions['email'] = $this->getEmail();
$this->gravatarOptions['options'] = $this->imgOptions;
}
/**
* @inheritdoc
*/
protected function buildImgTag()
{
return Gravatar::widget($this->gravatarOptions);
}
protected function getEmail()
{
return $this->model->getAttribute($this->emailAttribute);
}
}