1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace App\Lib;
13:
14: use Nette\Database\Table\ActiveRow,
15: App\Lib\Statics\Cons;
16:
17: 18: 19:
20: class Structure extends Container {
21:
22:
23: private $table;
24:
25: 26: 27: 28:
29: public function __construct(ActiveRow $table) {
30: $this->table = $table;
31: $fields = $this->toArray($table->related(Cons::TABLE_TABLE . '_' . Cons::TABLE_FIELDS)->order(Cons::COLUMN_SEQ, 'ASC'));
32: parent::__construct($fields);
33: }
34:
35: 36: 37: 38:
39: public function getName() {
40: return $this->table[Cons::COLUMN_NAME];
41: }
42:
43: 44: 45: 46:
47: public function getDesc() {
48: return $this->table[Cons::COLUMN_DESC];
49: }
50:
51: 52: 53: 54:
55: public function getFields() {
56: return $this->fields;
57: }
58:
59: 60: 61: 62:
63: public function getType() {
64: return $this->table[Cons::COLUMN_TYPE];
65: }
66:
67: 68: 69: 70:
71: public function getObject() {
72: return $this->table[Cons::COLUMN_OBJECT];
73: }
74:
75: 76: 77: 78:
79: public function getFooter() {
80: return $this->table[Cons::COLUMN_FOOTER];
81: }
82:
83: 84: 85: 86:
87: public function disableFields() {
88: foreach ($this->container as $field) {
89: $this->disableField($field);
90: }
91: return $this;
92: }
93:
94: 95: 96: 97: 98:
99: public function disableField($field) {
100: $field[Cons::COLUMN_READONLY] = '1';
101: return $this;
102: }
103:
104: 105: 106: 107: 108:
109: public function removeField($field) {
110: unset($field);
111: return $this;
112: }
113:
114: 115: 116: 117: 118:
119: public function getColumn() {
120: $column = array();
121: foreach ($this->container as $key => $val) {
122: if ($val[Cons::COLUMN_ROW] == '1') {
123: $column[$key] = $val;
124: }
125: }
126: return $column;
127: }
128:
129: 130: 131: 132:
133: private function toArray($selection, $array = array()) {
134: foreach ($selection as $activeRow) {
135: $array[$activeRow[Cons::COLUMN_FIELD]] = $activeRow->toArray();
136: $array[$activeRow[Cons::COLUMN_FIELD]][Cons::TABLE_TABLE.'_'.Cons::COLUMN_ID] = $this->table[Cons::COLUMN_OBJECT];
137: $relation = $activeRow[Cons::TABLE_TABLE.'_'.Cons::TABLE_ELEMENTS];
138: $array[$activeRow[Cons::COLUMN_FIELD]][Cons::TABLE_TABLE.'_'.Cons::TABLE_ELEMENTS.'_'.Cons::COLUMN_ID] = $relation[Cons::COLUMN_TYPE];
139: $array[$activeRow[Cons::COLUMN_FIELD]][Cons::COLUMN_CLASS] = $relation[Cons::COLUMN_CLASS];
140: }
141: return $array;
142: }
143:
144: }
145: