public static function updateDemand($demandID, $data) { global $db; // check if exists if (Demands::getDemand($demandID)) { return $db->update('demands', $data, ['id' => $demandID]); } return -1; }
<?php $this->respond(['GET', 'POST'], '/create', function ($request, $response, $service, $app) { $data = ['title' => $request->param('title', ''), 'ResponsibleAgent' => $request->param('ResponsibleAgent', ''), 'openingDate' => $request->param('openingDate', ''), 'notificationDate' => $request->param('notificationDate', ''), 'content' => $request->param('content', '')]; $id = Demands::createDemand($data); if ($id > 0) { $response->json(Result::success('Demand Created.', ['id' => $id])); } else { $response->json(Result::error('Demand Creation Failed.')); } }); $this->respond(['GET', 'POST'], '/get/[i:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $result = Demands::getDemand($id); if ($result) { $response->json(Result::success('', $result)); } else { $response->json(Result::error('Demand not found')); } }); $this->respond(['GET', 'POST'], '/edit/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $data = json_decode($request->body()); $result = Demands::updateDemand($id, $data); if ($result > 0) { $response->json(Result::success('Demand Updated.')); } elseif ($result === 0) { $response->json(Result::success('Demand not Updated.')); } else { $response->json(Result::error('Demand not found')); }