PluginProbe
Responsive Menu – Create Mobile-Friendly Menu / 3.1.16
Responsive Menu – Create Mobile-Friendly Menu v3.1.16
4.7.3 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.10 4.1.11 4.1.12 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 All 90 releases
responsive-menu / app / Management / OptionManager.php

OptionManager.php in Responsive Menu – Create Mobile-Friendly Menu 3.1.16, at app/Management/OptionManager.php

66 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ResponsiveMenu\Management;
4 use ResponsiveMenu\Collections\OptionsCollection;
5 use ResponsiveMenu\Database\Database;
6
7 class OptionManager {
8
9 private $db;
10 private $default_options;
11
12 public function __construct(Database $db, $default_options) {
13 $this->db = $db;
14 $this->default_options = $default_options;
15 }
16
17 public function all() {
18 $options = $this->db->all('responsive_menu');
19 return new OptionsCollection($options);
20 }
21
22 public function updateOptions(array $options) {
23 $updated_options = $this->combineOptions($options);
24 foreach($updated_options as $name => $val):
25 $val = is_array($val) ? json_encode($val) : $val;
26 $updated_options[$name] = $val;
27 $this->db->update('responsive_menu', ['name' => $name, 'value' => $val]);
28 endforeach;
29 return new OptionsCollection($updated_options);
30 }
31
32 public function createOptions(array $options) {
33 $updated_options = $this->combineOptions($options);
34 foreach($options as $name => $val):
35 $val = is_array($val) ? json_encode($val) : $val;
36 $updated_options[$name] = $val;
37 $this->db->insert('responsive_menu', ['name' => $name, 'value' => $val]);
38 endforeach;
39 return new OptionsCollection($updated_options);
40 }
41
42 public function removeOptions(array $options) {
43 $updated_options = $this->combineOptions($options);
44 foreach($options as $name => $val):
45 $val = is_array($val) ? json_encode($val) : $val;
46 $updated_options[$name] = $val;
47 unset($updated_options[$name]);
48 $this->db->delete('responsive_menu', ['name' => $name]);
49 endforeach;
50 return new OptionsCollection($updated_options);
51 }
52
53 public function buildFromArray(array $options) {
54 $new_options = $this->combineOptions($options);
55 foreach($options as $name => $val):
56 $val = is_array($val) ? json_encode($val) : $val;
57 $new_options[$name] = $val;
58 endforeach;
59 return new OptionsCollection($new_options);
60 }
61
62 private function combineOptions($new_options) {
63 return array_merge($this->default_options, $new_options);
64 }
65
66 }