PluginProbe
Responsive Menu – Create Mobile-Friendly Menu / 3.0.14
Responsive Menu – Create Mobile-Friendly Menu v3.0.14
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 / src / app / Repositories / OptionRepository.php

OptionRepository.php in Responsive Menu – Create Mobile-Friendly Menu 3.0.14, at src/app/Repositories/OptionRepository.php

57 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ResponsiveMenu\Repositories;
4 use ResponsiveMenu\Models\Option;
5 use ResponsiveMenu\Collections\OptionsCollection;
6 use ResponsiveMenu\Database\Database;
7 use ResponsiveMenu\Factories\OptionFactory;
8
9 class OptionRepository {
10
11 protected static $table = 'responsive_menu';
12
13 public function __construct(Database $db, OptionFactory $factory, array $defaults) {
14 $this->db = $db;
15 $this->factory = $factory;
16 $this->defaults = $defaults;
17 }
18
19 public function all() {
20 $options = $this->db->all(self::$table);
21 $collection = new OptionsCollection;
22 foreach($options as $option)
23 $collection->add($this->factory->build($option->name, $option->value));
24 return $collection;
25 }
26
27 public function update(Option $option) {
28 return $this->db->update(self::$table,
29 ['value' => $option->getFiltered()],
30 ['name' => $option->getName()]
31 );
32 }
33
34 public function create(Option $option) {
35 $arguments['name'] = $option->getName();
36 $arguments['value'] = $option->getFiltered();
37 $arguments['created_at'] = $this->db->mySqlTime();
38 return $this->db->insert(self::$table, $arguments);
39 }
40
41 public function remove($name) {
42 return $this->db->delete(self::$table, $name);
43 }
44
45 public function buildFromArray(array $array) {
46 $collection = new OptionsCollection;
47 foreach(array_merge($this->defaults, $array) as $name => $value):
48 $option = $this->factory->build($name, $value);
49 $option->setValue($option->getFiltered());
50 $collection->add($option);
51 endforeach;
52
53 return $collection;
54 }
55
56 }
57