|
27 | 27 | * @link https://github.com/pluginsGLPI/gantt |
28 | 28 | * ------------------------------------------------------------------------- |
29 | 29 | */ |
| 30 | +use GlpiPlugin\Gantt\DataFactory; |
| 31 | +use GlpiPlugin\Gantt\Item; |
| 32 | +use GlpiPlugin\Gantt\ProjectDAO; |
| 33 | +use GlpiPlugin\Gantt\TaskDAO; |
30 | 34 |
|
31 | | -include('../../../inc/includes.php'); |
| 35 | +use function Safe\json_encode; |
32 | 36 |
|
33 | 37 | /** @var array $CFG_GLPI */ |
34 | 38 | global $CFG_GLPI; |
|
46 | 50 |
|
47 | 51 | if (isset($_REQUEST['getData'])) { |
48 | 52 | $itemArray = []; |
49 | | - $factory = new \GlpiPlugin\Gantt\DataFactory(); |
| 53 | + $factory = new DataFactory(); |
50 | 54 | $factory->getItemsForProject($itemArray, $id); |
51 | 55 | $links = $factory->getProjectTaskLinks($itemArray); |
52 | 56 |
|
|
63 | 67 | echo json_encode($result); |
64 | 68 | } elseif (isset($_POST['addTask'])) { |
65 | 69 | try { |
66 | | - $item = new \GlpiPlugin\Gantt\Item(); |
| 70 | + $item = new Item(); |
67 | 71 | $task = $_POST['task']; |
68 | 72 | $item->populateFrom($task); |
69 | | - $taskDAO = new \GlpiPlugin\Gantt\TaskDAO(); |
| 73 | + $taskDAO = new TaskDAO(); |
70 | 74 | $newTask = $taskDAO->addTask($item); |
71 | | - $factory = new \GlpiPlugin\Gantt\DataFactory(); |
| 75 | + $factory = new DataFactory(); |
72 | 76 | $ganttItem = $factory->populateGanttItem($newTask->fields, 'task'); |
73 | 77 |
|
74 | 78 | $result = [ |
75 | 79 | 'ok' => true, |
76 | 80 | 'item' => $ganttItem, |
77 | 81 | ]; |
78 | | - } catch (\Exception $ex) { |
| 82 | + } catch (Exception $ex) { |
79 | 83 | $result = [ |
80 | 84 | 'ok' => false, |
81 | 85 | 'error' => $ex->getMessage(), |
|
85 | 89 | } elseif (isset($_POST['updateTask'])) { |
86 | 90 | try { |
87 | 91 | $updated = false; |
88 | | - $item = new \GlpiPlugin\Gantt\Item(); |
| 92 | + $item = new Item(); |
89 | 93 | $task = $_POST['task']; |
90 | 94 | $item->populateFrom($task); |
91 | | - $taskDAO = new \GlpiPlugin\Gantt\TaskDAO(); |
| 95 | + $taskDAO = new TaskDAO(); |
92 | 96 | $updated = $taskDAO->updateTask($item); |
93 | 97 | $result = [ |
94 | 98 | 'ok' => $updated, |
95 | 99 | ]; |
96 | | - } catch (\Exception $ex) { |
| 100 | + } catch (Exception $ex) { |
97 | 101 | $result = [ |
98 | 102 | 'ok' => false, |
99 | 103 | 'error' => $ex->getMessage(), |
|
106 | 110 | $p_target = $_POST['target']; |
107 | 111 |
|
108 | 112 | if ($p_item['type'] == 'project' && $p_target['type'] != 'project') { |
109 | | - throw new \Exception(__('Target item must be of project type', 'gantt')); |
| 113 | + throw new Exception(__s('Target item must be of project type', 'gantt')); |
110 | 114 | } |
111 | 115 |
|
112 | | - $item = new \GlpiPlugin\Gantt\Item(); |
| 116 | + $item = new Item(); |
113 | 117 | $item->populateFrom($p_item); |
114 | | - $target = new \GlpiPlugin\Gantt\Item(); |
| 118 | + $target = new Item(); |
115 | 119 | $target->populateFrom($p_target); |
116 | 120 |
|
117 | 121 | $item->parent = $target->id; |
118 | | - if ($p_item['type'] == 'project') { |
119 | | - $dao = new \GlpiPlugin\Gantt\ProjectDAO(); |
120 | | - } else { |
121 | | - $dao = new \GlpiPlugin\Gantt\TaskDAO(); |
122 | | - } |
| 122 | + $dao = $p_item['type'] == 'project' ? new ProjectDAO() : new TaskDAO(); |
123 | 123 | $dao->updateParent($item); |
124 | 124 |
|
125 | 125 | $result = [ |
126 | 126 | 'ok' => true, |
127 | 127 | ]; |
128 | | - } catch (\Exception $ex) { |
| 128 | + } catch (Exception $ex) { |
129 | 129 | $result = [ |
130 | 130 | 'ok' => false, |
131 | 131 | 'error' => $ex->getMessage(), |
|
138 | 138 |
|
139 | 139 | // double check for safety.. |
140 | 140 | if ($p_item['type'] != 'project') { |
141 | | - throw new \Exception(__('Item must be of project type', 'gantt')); |
| 141 | + throw new Exception(__s('Item must be of project type', 'gantt')); |
142 | 142 | } |
143 | 143 |
|
144 | | - $item = new \GlpiPlugin\Gantt\Item(); |
| 144 | + $item = new Item(); |
145 | 145 | $item->populateFrom($p_item); |
146 | | - $dao = new \GlpiPlugin\Gantt\ProjectDAO(); |
| 146 | + $dao = new ProjectDAO(); |
147 | 147 | $dao->updateParent($item); |
148 | 148 |
|
149 | 149 | $result = [ |
150 | 150 | 'ok' => true, |
151 | 151 | ]; |
152 | | - } catch (\Exception $ex) { |
| 152 | + } catch (Exception $ex) { |
153 | 153 | $result = [ |
154 | 154 | 'ok' => false, |
155 | 155 | 'error' => $ex->getMessage(), |
|
158 | 158 | echo json_encode($result); |
159 | 159 | } elseif (isset($_POST['addProject'])) { |
160 | 160 | try { |
161 | | - $item = new \GlpiPlugin\Gantt\Item(); |
| 161 | + $item = new Item(); |
162 | 162 | $project = $_POST['project']; |
163 | 163 | $item->populateFrom($project); |
164 | | - $dao = new \GlpiPlugin\Gantt\ProjectDAO(); |
| 164 | + $dao = new ProjectDAO(); |
165 | 165 | $newProj = $dao->addProject($item); |
166 | | - $factory = new \GlpiPlugin\Gantt\DataFactory(); |
| 166 | + $factory = new DataFactory(); |
167 | 167 | $ganttItem = $factory->populateGanttItem($newProj->fields, 'project'); |
168 | 168 |
|
169 | 169 | $result = [ |
170 | 170 | 'ok' => true, |
171 | 171 | 'item' => $ganttItem, |
172 | 172 | ]; |
173 | | - } catch (\Exception $ex) { |
| 173 | + } catch (Exception $ex) { |
174 | 174 | $result = [ |
175 | 175 | 'ok' => false, |
176 | 176 | 'error' => $ex->getMessage(), |
|
180 | 180 | } elseif (isset($_POST['updateProject'])) { |
181 | 181 | try { |
182 | 182 | $updated = false; |
183 | | - $item = new \GlpiPlugin\Gantt\Item(); |
| 183 | + $item = new Item(); |
184 | 184 | $project = $_POST['project']; |
185 | 185 | $item->populateFrom($project); |
186 | | - $projectDAO = new \GlpiPlugin\Gantt\ProjectDAO(); |
| 186 | + $projectDAO = new ProjectDAO(); |
187 | 187 | $updated = $projectDAO->updateProject($item); |
188 | 188 | $result = [ |
189 | 189 | 'ok' => $updated, |
190 | 190 | ]; |
191 | | - } catch (\Exception $ex) { |
| 191 | + } catch (Exception $ex) { |
192 | 192 | $result = [ |
193 | 193 | 'ok' => false, |
194 | 194 | 'error' => $ex->getMessage(), |
|
197 | 197 | echo json_encode($result); |
198 | 198 | } elseif (isset($_POST['addTaskLink'])) { |
199 | 199 | try { |
200 | | - $taskLink = new \ProjectTaskLink(); |
| 200 | + $taskLink = new ProjectTaskLink(); |
201 | 201 |
|
202 | 202 | if ($taskLink->checkIfExist($_POST['taskLink'])) { |
203 | | - throw new \Exception(__('Link already exist!', 'gantt')); |
| 203 | + throw new Exception(__s('Link already exist!', 'gantt')); |
204 | 204 | } |
205 | 205 |
|
206 | 206 | $id = $taskLink->add($_POST['taskLink']); |
207 | 207 | $result = [ |
208 | 208 | 'ok' => true, |
209 | 209 | 'id' => $id, |
210 | 210 | ]; |
211 | | - } catch (\Exception $ex) { |
| 211 | + } catch (Exception $ex) { |
212 | 212 | $result = [ |
213 | 213 | 'ok' => false, |
214 | 214 | 'error' => $ex->getMessage(), |
|
217 | 217 | echo json_encode($result); |
218 | 218 | } elseif (isset($_POST['updateTaskLink'])) { |
219 | 219 | try { |
220 | | - $taskLink = new \ProjectTaskLink(); |
| 220 | + $taskLink = new ProjectTaskLink(); |
221 | 221 | $taskLink->update($_POST['taskLink']); |
222 | 222 | $result = [ |
223 | 223 | 'ok' => true, |
224 | 224 | ]; |
225 | | - } catch (\Exception $ex) { |
| 225 | + } catch (Exception $ex) { |
226 | 226 | $result = [ |
227 | 227 | 'ok' => false, |
228 | 228 | 'error' => $ex->getMessage(), |
|
231 | 231 | echo json_encode($result); |
232 | 232 | } elseif (isset($_POST['deleteTaskLink'])) { |
233 | 233 | try { |
234 | | - $taskLink = new \ProjectTaskLink(); |
| 234 | + $taskLink = new ProjectTaskLink(); |
235 | 235 | $taskLink->delete($_POST); |
236 | 236 | $result = [ |
237 | 237 | 'ok' => true, |
238 | 238 | ]; |
239 | | - } catch (\Exception $ex) { |
| 239 | + } catch (Exception $ex) { |
240 | 240 | $result = [ |
241 | 241 | 'ok' => false, |
242 | 242 | 'error' => $ex->getMessage(), |
|
0 commit comments