1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Icybee\Modules\Users\Block; |
4
|
|
|
|
5
|
|
|
use Brickrouge\Button; |
6
|
|
|
use Brickrouge\Element; |
7
|
|
|
use Brickrouge\Form; |
8
|
|
|
|
9
|
|
|
use Icybee\Binding\Core\PrototypedBindings; |
10
|
|
|
|
11
|
|
|
class AvailableSitesBlock extends Element |
12
|
|
|
{ |
13
|
|
|
use PrototypedBindings; |
14
|
|
|
|
15
|
|
|
public function render() |
16
|
|
|
{ |
17
|
|
|
$app = $this->app; |
18
|
|
|
$document = $app->document; |
19
|
|
|
$document->js->add('available-sites.js'); |
20
|
|
|
$document->page_title = 'Select a website'; |
21
|
|
|
|
22
|
|
|
/* @var $site \Icybee\Modules\Sites\Site */ |
23
|
|
|
$site = $app->site; |
24
|
|
|
$ws_title = \ICanBoogie\escape($site->admin_title ? $site->admin_title : $site->title .':' . $site->language); |
25
|
|
|
|
26
|
|
|
$available = $site->model |
27
|
|
|
->where('site_id IN(' . implode(',', $app->user->restricted_sites_ids) . ')') |
28
|
|
|
->order('admin_title, title') |
29
|
|
|
->all; |
30
|
|
|
|
31
|
|
|
$uri = substr($_SERVER['REQUEST_URI'], strlen($site->path)); |
32
|
|
|
$options = []; |
33
|
|
|
|
34
|
|
|
foreach ($available as $site) |
35
|
|
|
{ |
36
|
|
|
$title = $site->title . ':' . $site->language; |
37
|
|
|
|
38
|
|
|
if ($site->admin_title) |
39
|
|
|
{ |
40
|
|
|
$title .= ' (' . $site->admin_title . ')'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$options[$site->url . $uri] = $title; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$form = new Form([ |
47
|
|
|
|
48
|
|
|
Form::ACTIONS => new Button('Change', [ |
49
|
|
|
|
50
|
|
|
'class' => 'btn-primary', |
51
|
|
|
'type' => 'submit' |
52
|
|
|
|
53
|
|
|
]), |
54
|
|
|
|
55
|
|
|
Form::RENDERER => Form\GroupRenderer::class, |
56
|
|
|
|
57
|
|
|
Element::CHILDREN => [ |
58
|
|
|
|
59
|
|
|
new Element('select', [ |
60
|
|
|
|
61
|
|
|
Element::DESCRIPTION => "Select one of the website available to your profile.", |
62
|
|
|
Element::OPTIONS => $options |
63
|
|
|
|
64
|
|
|
]) |
65
|
|
|
], |
66
|
|
|
|
67
|
|
|
'name' => 'change-working-site', |
68
|
|
|
'class' => 'form-primary' |
69
|
|
|
|
70
|
|
|
]); |
71
|
|
|
|
72
|
|
|
return <<<EOT |
73
|
|
|
<div id="block--site-access-denied" class="block-alert"> |
74
|
|
|
<h2>Access denied</h2> |
75
|
|
|
<p>You don't have permission to access the administration interface for the website <q>$ws_title</q>, |
76
|
|
|
please select another website to work with:</p> |
77
|
|
|
$form |
78
|
|
|
</div> |
79
|
|
|
EOT; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|