1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Nodes;
13
14 use Icybee\Modules\Nodes\Node;
15
16 use Brickrouge\Element;
17 use Brickrouge\Form;
18
19 20 21
22 class EditBlock extends \Icybee\EditBlock
23 {
24 25 26 27 28 29 30 31
32 protected function lazy_get_attributes()
33 {
34 $attributes = parent::lazy_get_attributes();
35
36 $attributes[Element::GROUPS]['visibility'] = [
37
38 'title' => 'Visibility',
39 'weight' => 400
40
41 ];
42
43 return $attributes;
44 }
45
46 47 48 49 50
51 protected function lazy_get_children()
52 {
53 $values = $this->values;
54
55 return array_merge(parent::lazy_get_children(), [
56
57 Node::TITLE => new TitleSlugCombo([
58
59 Form::LABEL => 'title',
60 Element::REQUIRED => true,
61 TitleSlugCombo::T_NODEID => $values[Node::NID],
62 TitleSlugCombo::T_SLUG_NAME => 'slug'
63
64 ]),
65
66 Node::UID => $this->get_control__user(),
67 Node::SITEID => $this->get_control__site(),
68 Node::IS_ONLINE => new Element(Element::TYPE_CHECKBOX, [
69
70 Element::LABEL => 'is_online',
71 Element::DESCRIPTION => 'is_online',
72 Element::GROUP => 'visibility'
73
74 ])
75 ]);
76 }
77
78 79 80 81 82 83 84 85
86 protected function get_control__user()
87 {
88 global $core;
89
90 if (!$core->user->has_permission(Module::PERMISSION_ADMINISTER, $this->module))
91 {
92 return;
93 }
94
95 $users = $core->models['users']->select('uid, username')->order('username')->pairs;
96
97 if (count($users) < 2)
98 {
99 return;
100 }
101
102 return new Element('select', [
103
104 Form::LABEL => 'User',
105 Element::OPTIONS => [ null => '' ] + $users,
106 Element::REQUIRED => true,
107 Element::DEFAULT_VALUE => $core->user->uid,
108 Element::GROUP => 'admin',
109 Element::DESCRIPTION => 'user'
110
111 ]);
112 }
113
114 115 116 117 118 119 120 121
122 protected function get_control__site()
123 {
124 global $core;
125
126 if (!$core->user->has_permission(Module::PERMISSION_MODIFY_BELONGING_SITE, $this->module))
127 {
128 return;
129 }
130
131 $sites = $core->models['sites']->select('siteid, IF(admin_title != "", admin_title, concat(title, ":", language))')->order('admin_title, title')->pairs;
132
133 if (count($sites) < 2)
134 {
135 $this->attributes[Form::HIDDENS][Node::SITEID] = $core->site_id;
136
137 return;
138 }
139
140 return new Element('select', [
141
142 Form::LABEL => 'siteid',
143 Element::OPTIONS => [ null => '' ] + $sites,
144 Element::GROUP => 'admin',
145 Element::DESCRIPTION => 'siteid'
146
147 ]);
148 }
149 }