1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Element;
13
14 use ICanBoogie\Module;
15 use ICanBoogie\Operation;
16 use ICanBoogie\Route;
17
18 use Brickrouge\A;
19 use Brickrouge\Element;
20 use Brickrouge\DropdownMenu;
21
22 use Icybee\Modules\Users\Roles\Role;
23
24 25 26 27
28 class extends Element
29 {
30 public function __construct(array $attributes=array())
31 {
32 parent::__construct('div', $attributes);
33 }
34
35 protected function render_inner_html()
36 {
37 global $core;
38
39 $user = $core->user;
40 $site = $core->site;
41
42 $roles = '';
43
44 if ($user->is_admin)
45 {
46 $roles = 'Admin';
47 }
48 else if ($user->has_permission(Module::PERMISSION_ADMINISTER, 'users.roles'))
49 {
50 foreach ($user->roles as $role)
51 {
52 $roles .= ', <a href="' . $site->path . '/admin/users.roles/' . $role->rid . '/edit">' . $role->name . '</a>';
53 }
54
55 $roles = substr($roles, 2);
56 }
57 else
58 {
59 $n = count($user->roles);
60
61 foreach ($user->roles as $role)
62 {
63 if ($n > 1 && $role->rid == Role::USER_RID)
64 {
65 continue;
66 }
67
68 $roles .= ', ' . $role->name;
69 }
70
71 $roles = substr($roles, 2);
72 }
73
74 $username = new A($user->name, \ICanBoogie\Routing\contextualize('/admin/profile'));
75
76 $options = array
77 (
78 \ICanBoogie\Routing\contextualize('/admin/profile') => 'Profile',
79 false,
80 Operation::encode('users/logout') => 'Logout'
81 );
82
83 array_walk
84 (
85 $options, function(&$v, $k)
86 {
87 if (!is_string($v))
88 {
89 return;
90 }
91
92 $v = new A($v, $k);
93 }
94 );
95
96 $menu = new DropdownMenu
97 (
98 array
99 (
100 DropdownMenu::OPTIONS => $options,
101
102 'value' => $core->request->path
103 )
104 );
105
106 return <<<EOT
107 $username
108 <span class="btn-group">
109 <span class="dropdown-toggle" data-toggle="dropdown"><i class="icon-user icon-white"></i> <span class="caret"></span></span>
110 $menu
111 </span>
112 EOT;
113 }
114 }