|
8 | 8 |
|
9 | 9 | class Controller extends BaseController |
10 | 10 | { |
11 | | - /** |
12 | | - * Retrieve all tables. |
13 | | - * |
14 | | - * @return Response |
15 | | - */ |
16 | | - public function t_showAll() |
17 | | - { |
18 | | - return TableController::table_showAll(); |
19 | | - } |
20 | 11 |
|
21 | | - /** |
22 | | - * Retrieve all rows in table with the given name. |
23 | | - * |
24 | | - * @param string $tableName |
25 | | - * @return Response |
26 | | - */ |
27 | | - public function t_show($tableName) |
| 12 | + public function tableGetAll_() |
28 | 13 | { |
29 | | - return TableController::table_show($tableName); |
| 14 | + return TableController::tableGet(false); |
30 | 15 | } |
31 | 16 |
|
32 | | - /** |
33 | | - * Retrieve info about table with the given name. |
34 | | - * |
35 | | - * @param string $tableName |
36 | | - * @return Response |
37 | | - */ |
38 | | - public function t_showInfo($tableName) |
| 17 | + public function tableGet_($tableName) |
39 | 18 | { |
40 | | - return TableController::table_showInfo($tableName); |
| 19 | + return TableController::tableGet($tableName); |
41 | 20 | } |
42 | 21 |
|
43 | | - /** |
44 | | - * Retrieve row from table with the given id. |
45 | | - * |
46 | | - * @param string $tableName |
47 | | - * @param int $id |
48 | | - * @return Response |
49 | | - */ |
50 | | - public function r_show($tableName,$id) |
| 22 | + public function rowGet_($tableName,$id) |
51 | 23 | { |
52 | | - if (!TableController::table_exists($tableName)) |
53 | | - return abort(404, "Table '$tableName' don´t exist."); |
54 | | - |
55 | | - return RowController::row_show($tableName,$id); |
| 24 | + return RowController::rowGet($tableName,$id); |
56 | 25 | } |
57 | 26 |
|
58 | | - /** |
59 | | - * Create/Replace table. |
60 | | - * |
61 | | - * @param Request $request |
62 | | - * @return Response |
63 | | - */ |
64 | | - public function t_store(Request $request) |
65 | | - { |
66 | | - if (!$request->has('tablename')) |
67 | | - return abort(400, "No tablename given."); |
68 | | - |
69 | | - $tableName = $request->tablename; |
70 | | - |
71 | | - $table = array(); |
72 | | - $table['id'] = "increments"; |
73 | | - |
74 | | - foreach ($request->input() as $column => $type) { |
75 | | - if ($column != "id" && $column != "tablename") // Don´t use these |
76 | | - if ($type=="text" || $type=="integer") // Enabled types |
77 | | - $table[$column] = $type; |
78 | | - } |
79 | | - |
80 | | - if (TableController::table_exists($tableName)) |
81 | | - return abort(500, "Table '$tableName' allready exists."); |
82 | | - |
83 | | - if (!TableController::table_store($tableName,$table)) |
84 | | - return abort(500, "Failed to create Table '$tableName'"); |
85 | 27 |
|
86 | | - // Summary of the created table |
87 | | - echo "<pre>"; |
88 | | - echo "CREATE TABLE '$tableName'\n"; |
89 | | - echo "(\n"; |
90 | | - foreach ($table as $column => $type) { |
91 | | - echo " '$column' $type\n"; |
92 | | - } |
93 | | - echo ")</pre>"; |
94 | | - |
95 | | - return ""; |
96 | | - } |
97 | | - |
98 | | - /** |
99 | | - * Create/Replace row. |
100 | | - * |
101 | | - * @param string $tableName |
102 | | - * @param Request $request |
103 | | - * @return Response |
104 | | - */ |
105 | | - public function r_store($tableName, Request $request) |
| 28 | + public function tableRemove_($tableName) |
106 | 29 | { |
107 | | - if (!TableController::table_exists($tableName)) |
108 | | - return abort(404, "Table '$tableName' don´t exist."); |
109 | | - |
110 | | - $row = array(); |
111 | | - foreach ($request->input() as $column => $value) { |
112 | | - if ($column != "id") // Don´t use these |
113 | | - $row[$column] = $value; |
114 | | - } |
115 | | - |
116 | | - $id = RowController::row_store($tableName,$row); |
| 30 | + TableController::tableRemove($tableName); |
117 | 31 |
|
118 | | - if (!$id) |
119 | | - return abort(500, "Failed to create row in '$tableName'"); |
120 | | - |
121 | | - return RowController::row_show($tableName,$id); |
| 32 | + return TableController::tableGet(false); |
122 | 33 | } |
123 | 34 |
|
124 | | - /** |
125 | | - * Update table. |
126 | | - * |
127 | | - * @param Request $request |
128 | | - * @return Response |
129 | | - */ |
130 | | - public function t_update(Request $request) |
| 35 | + public function rowRemove_($tableName,$id) |
131 | 36 | { |
132 | | - if (!$request->has('tablename')) |
133 | | - return abort(400, "No tablename given."); |
134 | | - |
135 | | - $tableName = $request->tablename; |
136 | | - |
137 | | - $table = array(); |
138 | | - $table['id'] = "increments"; |
139 | | - |
140 | | - foreach ($request->input() as $column => $type) { |
141 | | - if ($column != "id" && $column != "tablename") // Don´t use these |
142 | | - if ($type=="text" || $type=="integer") // Enabled types |
143 | | - $table[$column] = $type; |
144 | | - } |
145 | | - |
146 | | - if (!TableController::table_update($tableName,$table)) |
147 | | - return abort(500, "Failed to update Table '$tableName'"); |
148 | | - |
149 | | - // Summary of the updated table |
150 | | - echo "<pre>"; |
151 | | - echo "CREATE TABLE '$tableName'\n"; |
152 | | - echo "(\n"; |
153 | | - foreach ($table as $column => $type) { |
154 | | - echo " '$column' $type\n"; |
155 | | - } |
156 | | - echo ")</pre>"; |
157 | | - |
158 | | - return ""; |
159 | | - } |
160 | | - |
161 | | - /** |
162 | | - * Update row. |
163 | | - * |
164 | | - * @param string $tableName |
165 | | - * @param int $id |
166 | | - * @param Request $request |
167 | | - * @return Response |
168 | | - */ |
169 | | - public function r_update($tableName, $id, Request $request) |
170 | | - { |
171 | | - if (!TableController::table_exists($tableName)) |
172 | | - return abort(404, "Table '$tableName' don´t exist."); |
173 | | - |
174 | | - $row = array(); |
175 | | - foreach ($request->input() as $column => $value) { |
176 | | - if ($column != "id") // Don´t use these |
177 | | - $row[$column] = $value; |
178 | | - } |
179 | | - |
180 | | - if (!RowController::row_update($tableName,$id,$row)) |
181 | | - return abort(500, "Failed to update row $id in '$tableName'"); |
182 | | - |
183 | | - return RowController::row_show($tableName,$id); |
184 | | - } |
185 | | - |
186 | | - /** |
187 | | - * Remove table. |
188 | | - * |
189 | | - * @param string $tableName |
190 | | - * @return Response |
191 | | - */ |
192 | | - public function t_remove($tableName) |
193 | | - { |
194 | | - if (!TableController::table_remove($tableName)) |
195 | | - return abort(500, "Failed to remove Table '$tableName'"); |
196 | | - |
197 | | - return TableController::table_showAll(); |
198 | | - } |
199 | | - |
200 | | - /** |
201 | | - * Remove row. |
202 | | - * |
203 | | - * @param string $tableName |
204 | | - * @param int $id |
205 | | - * @return Response |
206 | | - */ |
207 | | - public function r_remove($tableName,$id) |
208 | | - { |
209 | | - if (!TableController::table_exists($tableName)) |
210 | | - return abort(404, "Table '$tableName' don´t exist."); |
211 | | - |
212 | | - if (!RowController::row_remove($tableName,$id)) |
213 | | - return abort(500, "Failed to remove Row $id from '$tableName'"); |
| 37 | + RowController::rowRemove($tableName,$id); |
214 | 38 |
|
215 | | - return TableController::table_show($tableName); |
| 39 | + return TableController::tableGet($tableName); |
216 | 40 | } |
217 | 41 |
|
218 | 42 | } |
0 commit comments