@@ 80-104 (lines=25) @@ | ||
77 | * METHOD: POST |
|
78 | * URL: /import_list |
|
79 | */ |
|
80 | public function import() : void { |
|
81 | $this->form_validation->set_rules('json', 'JSON String', 'required|is_valid_json'); |
|
82 | ||
83 | if($this->form_validation->run() === TRUE) { |
|
84 | $status = $this->Tracker->portation->importFromJSON($this->input->post('json')); |
|
85 | switch($status['code']) { |
|
86 | case 0: |
|
87 | $this->output->set_status_header('200'); //Success |
|
88 | break; |
|
89 | case 1: |
|
90 | $this->output->set_status_header('400', 'JSON contains invalid keys'); |
|
91 | break; |
|
92 | case 2: |
|
93 | $this->output->set_status_header('400', 'Unable to add some rows from JSON'); |
|
94 | //$this->_render_json(json_encode($status['failed_rows'])); //TODO: We should list what rows these are. |
|
95 | break; |
|
96 | } |
|
97 | } else { |
|
98 | if(!$this->form_validation->isRuleValid('is_valid_json')) { |
|
99 | $this->output->set_status_header('400', 'File isn\'t valid JSON!'); |
|
100 | } else { |
|
101 | $this->output->set_status_header('400', 'No file sent'); |
|
102 | } |
|
103 | } |
|
104 | } |
|
105 | ||
106 | /** |
|
107 | * Used to export a users' list. |
|
@@ 213-233 (lines=21) @@ | ||
210 | * METHOD: POST |
|
211 | * URL: /set_category |
|
212 | */ |
|
213 | public function set_category() : void { |
|
214 | $this->form_validation->set_rules('id[]', 'List of IDs', 'required|ctype_digit'); |
|
215 | $this->form_validation->set_rules('category', 'Category Name', 'required|is_valid_category'); |
|
216 | ||
217 | if($this->form_validation->run() === TRUE) { |
|
218 | $status = $this->Tracker->category->setByIDList($this->input->post('id[]'), $this->input->post('category')); |
|
219 | switch($status['code']) { |
|
220 | case 0: |
|
221 | $this->output->set_status_header('200'); //Success! |
|
222 | break; |
|
223 | case 1: |
|
224 | $this->output->set_status_header('400', 'Request contains invalid IDs'); |
|
225 | break; |
|
226 | case 2: |
|
227 | $this->output->set_status_header('400', 'Request contains invalid category.'); |
|
228 | break; |
|
229 | } |
|
230 | } else { |
|
231 | $this->output->set_status_header('400', 'Request contained invalid elements!'); |
|
232 | } |
|
233 | } |
|
234 | ||
235 | /** |
|
236 | * Used to permanently hide the current notice. |