public static function updateLid($lidID, $lidData) { global $db; // check if exists if (Lids::getLid($lidID)) { return $db->update('lidsForReview', $lidData, ['id' => $lidID]); } 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 = Lids::createLid($data); if ($id > 0) { $response->json(Result::success('Lid Created.', ['id' => $id])); } else { $response->json(Result::error('Lid Creation Failed.')); } }); $this->respond(['GET', 'POST'], '/get/[i:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $result = Lids::getLid($id); if ($result) { $response->json(Result::success('', $result)); } else { $response->json(Result::error('Lid not found')); } }); $this->respond(['GET', 'POST'], '/edit/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $data = json_decode($request->body()); $result = Lids::updateLid($id, $data); if ($result > 0) { $response->json(Result::success('Lid Updated.')); } elseif ($result === 0) { $response->json(Result::success('Lid not Updated.')); } else { $response->json(Result::error('Lid not found')); }