1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee;
13
14 use ICanBoogie\Exception;
15 use ICanBoogie\Operation;
16
17 use Brickrouge\Button;
18 use Brickrouge\Element;
19 use Brickrouge\Form;
20
21 22 23
24 abstract class ConfigBlock extends FormBlock
25 {
26 public function render()
27 {
28 parent::render();
29
30 $this->element->save();
31
32 return $this;
33 }
34
35 protected function get_permission()
36 {
37 global $core;
38
39 return $core->user->has_permission(Module::PERMISSION_ADMINISTER, $this->module);
40 }
41
42 protected function access_control()
43 {
44 if (!$this->permission)
45 {
46 throw new Exception("You don't have permission to access the config block of the %module module", array('module' => $this->module->title));
47 }
48 }
49
50 51 52
53 protected function lazy_get_attributes()
54 {
55 return \ICanBoogie\array_merge_recursive
56 (
57 parent::lazy_get_attributes(), array
58 (
59 Form::HIDDENS => array
60 (
61 Operation::NAME => Module::OPERATION_CONFIG
62 )
63 )
64 );
65 }
66
67 protected function alter_actions(array $actions, array $params)
68 {
69 return array_merge
70 (
71 parent::alter_actions($actions, $params), array
72 (
73 'primary' => new Button('Save', array('class' => 'btn-primary', 'type' => 'submit', 'name' => false))
74 )
75 );
76 }
77
78 protected function alter_values(array $values, array $params)
79 {
80 global $core;
81
82 $values = parent::alter_values($values, $params);
83
84 $iterator = new Form(array(Element::CHILDREN => $this->children));
85
86 $registry = $core->registry;
87 $local = $core->site->metas;
88
89 foreach ($iterator as $child)
90 {
91 $name = $child['name'];
92
93 if (!$name)
94 {
95 continue;
96 }
97
98 $dotted_name = strtr($name, array('[' => '.', ']' => ''));
99
100 $value = null;
101
102 if (strpos($dotted_name, 'local.') === 0)
103 {
104 $value = $local[substr($dotted_name, 6)];
105 }
106 else if (strpos($dotted_name, 'global.') === 0)
107 {
108 $value = $registry[substr($dotted_name, 7)];
109 }
110 else
111 {
112
113
114 $value = $registry[$dotted_name];
115 }
116
117 if ($value === null)
118 {
119 continue;
120 }
121
122 $values[$name] = $value;
123 }
124
125 return $values;
126 }
127 }