1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class Ajde_Crud_Options extends Ajde_Object_Standard |
4
|
|
|
{ |
5
|
|
|
protected $_key; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @var Ajde_Crud_Options |
9
|
|
|
*/ |
10
|
|
|
protected $_parent = null; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var array |
14
|
|
|
*/ |
15
|
|
|
public $_stack = []; |
16
|
|
|
|
17
|
|
|
public function __construct() |
18
|
|
|
{ |
19
|
|
|
$this->_active = $this; |
|
|
|
|
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
// Protected functions |
23
|
|
|
|
24
|
|
|
protected function _select($name, $key = null) |
25
|
|
|
{ |
26
|
|
|
$key = isset($key) ? $key : $name; |
27
|
|
|
// Get new active object |
28
|
|
|
$className = get_class($this).'_'.ucfirst($name); |
29
|
|
|
/* @var $new Ajde_Crud_Options */ |
30
|
|
|
$new = new $className(); |
31
|
|
|
$new->_parent = $this; |
32
|
|
|
$new->_key = $key; |
33
|
|
|
if (isset($this->_stack[$key])) { |
34
|
|
|
$new->_stack = $this->_stack[$key]; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
return $new; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
protected function _set($key, $value) |
41
|
|
|
{ |
42
|
|
|
parent::_set($key, $value); |
43
|
|
|
|
44
|
|
|
return $this; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
// Public functions |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return Ajde_Crud_Options |
51
|
|
|
*/ |
52
|
|
|
public function up($obj = false) |
53
|
|
|
{ |
54
|
|
|
if (!$obj) { |
55
|
|
|
$obj = $this; |
56
|
|
|
} |
57
|
|
|
if (!isset($obj->_parent)) { |
58
|
|
|
return false; |
|
|
|
|
59
|
|
|
} |
60
|
|
|
$obj->_parent->_stack[$obj->_key] = array_merge($obj->_stack, $obj->values()); |
|
|
|
|
61
|
|
|
|
62
|
|
|
return $obj->_parent; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return Ajde_Crud_Options |
67
|
|
|
*/ |
68
|
|
|
public function finished() |
69
|
|
|
{ |
70
|
|
|
$test = $this->up(); |
71
|
|
|
while ($test) { |
72
|
|
|
$test = $test->up(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $this; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return Ajde_Crud_Options |
80
|
|
|
*/ |
81
|
|
|
public function display() |
82
|
|
|
{ |
83
|
|
|
var_dump($this->_stack); |
|
|
|
|
84
|
|
|
|
85
|
|
|
return $this; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
|
|
public function getArray() |
92
|
|
|
{ |
93
|
|
|
return $this->_stack; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
// ========================================================================= |
97
|
|
|
// Select functions |
98
|
|
|
// ========================================================================= |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return Ajde_Crud_Options_Fields |
102
|
|
|
*/ |
103
|
|
|
public function selectFields() |
104
|
|
|
{ |
105
|
|
|
return $this->_select('fields'); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return Ajde_Crud_Options_List |
110
|
|
|
*/ |
111
|
|
|
public function selectList() |
112
|
|
|
{ |
113
|
|
|
return $this->_select('list'); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return Ajde_Crud_Options_Edit |
118
|
|
|
*/ |
119
|
|
|
public function selectEdit() |
120
|
|
|
{ |
121
|
|
|
return $this->_select('edit'); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
// ========================================================================= |
125
|
|
|
// Set functions |
126
|
|
|
// ========================================================================= |
127
|
|
|
} |
128
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: