Completed
Push — master ( 06f53d...d82ac1 )
by Ryan
02:54
created

UserPresenter::gravatar()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php namespace Anomaly\UsersModule\User;
2
3
use Anomaly\Streams\Platform\Entry\EntryPresenter;
4
use Anomaly\UsersModule\User\Contract\UserInterface;
5
6
/**
7
 * Class UserPresenter
8
 *
9
 * @link          http://pyrocms.com/
10
 * @author        PyroCMS, Inc. <[email protected]>
11
 * @author        Ryan Thompson <[email protected]>
12
 * @package       Anomaly\UsersModule\User
13
 */
14
class UserPresenter extends EntryPresenter
15
{
16
17
    /**
18
     * The decorated object.
19
     * This is for IDE support.
20
     *
21
     * @var UserInterface
22
     */
23
    protected $object;
24
25
    /**
26
     * Return the users name.
27
     *
28
     * @return string
29
     */
30
    public function name()
31
    {
32
        return implode(' ', array_filter([$this->object->getFirstName(), $this->object->getLastName()]));
33
    }
34
35
    /**
36
     * Return the user gravatar.
37
     *
38
     * @return string
39
     */
40
    public function gravatar()
41
    {
42
        return 'https://www.gravatar.com/avatar/' . md5($this->object->getEmail());
43
    }
44
45
    /**
46
     * Return the user's status as a label.
47
     *
48
     * @param string $size
49
     * @return null|string
50
     */
51
    public function statusLabel($size = 'sm')
52
    {
53
        $color  = 'default';
54
        $status = $this->status();
55
56
        switch ($status) {
57
            case 'active':
58
                $color = 'success';
59
                break;
60
61
            case 'inactive':
62
                $color = 'default';
63
                break;
64
65
            case 'disabled':
66
                $color = 'danger';
67
                break;
68
        }
69
70
        return '<span class="label label-' . $size . ' label-' . $color . '">' . trans(
71
            'anomaly.module.users::field.status.option.' . $status
72
        ) . '</span>';
73
    }
74
75
    /**
76
     * Return the status key.
77
     *
78
     * @return null|string
79
     */
80
    public function status()
81
    {
82
        if (!$this->object->isEnabled()) {
83
            return 'disabled';
84
        }
85
86
        if ($this->object->isEnabled() && !$this->object->isActivated()) {
87
            return 'inactive';
88
        }
89
90
        if ($this->object->isEnabled() && $this->object->isActivated()) {
91
            return 'active';
92
        }
93
94
        return null;
95
    }
96
}
97