1: <?php
2:
3: namespace Laravella\Crud;
4:
5: use \DB;
6:
7: 8: 9: 10: 11:
12: class Options {
13:
14: public static function get($name, $type=null)
15: {
16: $setting = '';
17: $option = DB::table('_db_options as o');
18: if (!is_null($type) && !empty($type)) {
19: $option = $option->join('_db_option_types as ot', 'ot.id', '=', 'o.option_type_id')
20: ->where('ot.name', $type);
21: }
22: $option = $option->where('o.name', $name)
23: ->select('o.value')
24: ->first();
25: if (is_object($option))
26: {
27: $setting = $option->value;
28: }
29: return $setting;
30: }
31:
32: public static function getTypes($name)
33: {
34: $options = new Options();
35: return $options->__getTypes($name);
36: }
37:
38: 39: 40: 41: 42:
43: private function __getTypes($name)
44: {
45: if (empty($name))
46: {
47: return null;
48: }
49: $typeA = array();
50:
51: $options = DB::table('_db_option_types as pot')
52: ->join('_db_option_types as cot', 'cot.parent_id', '=', 'pot.id')
53: ->select('cot.name as cname', 'pot.name as pname')
54: ->where('pot.name', '=', $name)
55: ->get();
56:
57: if (is_array($options))
58: {
59: foreach ($options as $option)
60: {
61: $val = $this->getTypes($option->cname);
62: if (!empty($val))
63: {
64: $typeA[$option->cname] = $val;
65: }
66: else
67: {
68: $typeA[$option->cname] = $option->cname;
69: }
70: }
71: }
72:
73: return $typeA;
74: }
75:
76: 77: 78: 79: 80:
81: private function __getValues($types)
82: {
83: $values = array();
84: foreach ($types as $name => $type)
85: {
86: if (is_array($type) && count($type > 0))
87: {
88: $values[$name] = $this->__getValues($type);
89: }
90: else
91: {
92: $values[$name] = $this->getByType($name);
93: }
94: }
95: return $values;
96: }
97:
98: 99: 100: 101: 102:
103: private static function getValues($types)
104: {
105: $options = new Options();
106: return $options->__getValues($types);
107: }
108:
109: 110: 111: 112: 113:
114: public static function getByType($name) {
115: $options = DB::table('_db_options as o')
116: ->join('_db_option_types as ot', 'ot.id', '=', 'o.option_type_id')
117: ->select('ot.name as type', 'o.name as option', 'o.value as value')
118: ->where('ot.name', '=', $name)
119: ->get();
120:
121: $values = array();
122: foreach($options as $option) {
123: $values[$option->option] = $option->value;
124: }
125:
126: return $values;
127:
128: }
129:
130: 131: 132: 133: 134: 135:
136: public static function getType($name)
137: {
138:
139: $types = static::getTypes($name);
140:
141: $values = static::getValues($types);
142:
143: return $values;
144: }
145:
146: }
147:
148: ?>
149: