private static function getRentDemandStatus($rentDemandID) { $processes = RentProcesses::getRentDemandProcesses($rentDemandID); $failed = 0; $closed = 0; $alive = 0; $count = 0; foreach ($processes as $process) { if (isset($process['status'])) { $count++; if ($process['status'] == 'failed') { $failed++; } else { if ($process['status'] == 'closed') { $closed++; } else { if ($process['status'] == 'alive') { $alive++; } } } } } if ($failed == 0 && $closed == 0) { return 'alive'; } else { if ($closed > 0) { return 'closed'; } else { if ($failed == $count) { return 'failed'; } } } }
<?php $this->respond(['GET', 'POST'], '/create', function ($request, $response, $service, $app) { $data = json_decode($request->body(), true); $id = RentDemands::createRentDemand($data); if ($id > 0) { $response->json(Result::success('RentDemand Created.', ['id' => $id])); } else { $response->json(Result::error('RentDemand Creation Failed.', $id)); } }); $this->respond(['GET', 'POST'], '/watch-mod/get/[i:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $rentDemandData = RentDemands::getRentDemand($id); $processes = RentProcesses::getRentDemandProcesses($id); $result = array("rentDemandData" => $rentDemandData, "processes" => $processes); if ($result) { $response->json(Result::success('', $result)); } else { $response->json(Result::error('RentDemand not found')); } }); $this->respond(['GET', 'POST'], '/match-mod/get/[i:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $result = RentDemands::getRentDemand($id); if ($result) { $response->json(Result::success('', $result)); } else { $response->json(Result::error('RentDemand not found')); } });