Completed
Push — master ( ab125f...3d5e2b )
by Ryan
02:42
created

UserPresenter::status()   B

Complexity

Conditions 6
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 16
c 1
b 0
f 0
rs 8.8571
cc 6
eloc 8
nc 4
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://anomaly.is/streams-platform
10
 * @author        AnomalyLabs, 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's status as a label.
37
     *
38
     * @param string $size
39
     * @return null|string
40
     */
41
    public function statusLabel($size = 'sm')
42
    {
43
        $color  = 'default';
44
        $status = $this->status();
45
46
        switch ($status) {
47
            case 'active':
48
                $color = 'success';
49
                break;
50
51
            case 'inactive':
52
                $color = 'default';
53
                break;
54
55
            case 'disabled':
56
                $color = 'danger';
57
                break;
58
        }
59
60
        return '<span class="label label-' . $size . ' label-' . $color . '">' . trans(
61
            'anomaly.module.users::field.status.option.' . $status
62
        ) . '</span>';
63
    }
64
65
    /**
66
     * Return the status key.
67
     *
68
     * @return null|string
69
     */
70
    public function status()
71
    {
72
        if (!$this->object->isEnabled()) {
73
            return 'disabled';
74
        }
75
76
        if ($this->object->isEnabled() && !$this->object->isActivated()) {
77
            return 'inactive';
78
        }
79
80
        if ($this->object->isEnabled() && $this->object->isActivated()) {
81
            return 'active';
82
        }
83
84
        return null;
85
    }
86
}
87