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'], '/get/control-data', function ($request, $response, $service, $app) { $processLogs = Logs::getProcessLogs(); $processForCheckLogs = Logs::getProcessForCheckLogs(); $marketingListLogs = Logs::getMarketingListLogs(); $demands = Demands::getDemands(); $lids = Lids::getLids(); $trackedAssets = TrackedAssets::getTrackedAssets(); $investors = Investors::getInvestorsForControlPanel(); $notifications = Notifications::getAllNotificationsToShow(); $result = array("processLogs" => $processLogs, "processForCheckLogs" => $processForCheckLogs, "marketingListLogs" => $marketingListLogs, "demands" => $demands, "lids" => $lids, "trackedAssets" => $trackedAssets, "investors" => $investors, "notifications" => $notifications); $response->json(Result::success('', $result)); });
}); $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')); } }); $this->respond(['GET', 'POST'], '/delete/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $result = Demands::deleteDemand($id); if ($result > 0) { $response->json(Result::success('Demand Deleted.')); } else { $response->json(Result::error('Demand not Deleted')); } });