} }); $this->respond(['GET', 'POST'], '/get/[i:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $assetData = Assets::getAsset($id); $assetInvestors = Investors::getAssetInvestors($id); $result = array("assetData" => $assetData, "assetInvestors" => $assetInvestors); if ($assetData) { $response->json(Result::success('', $result)); } else { $response->json(Result::error('Asset not found')); } }); $this->respond(['GET', 'POST'], '/get-for-edit/[i:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $assetData = Assets::getAsset($id); $assetContacts = Contacts::getAssetContacts($id); $assetInvestors = Investors::getAssetInvestors($id); $assetAreas = RentAreas::getAssetRentAreas($id); $assetProcesses = RentProcesses::getAssetRentProcesses($id); $result = array("assetData" => $assetData, "assetContacts" => $assetContacts, "assetInvestors" => $assetInvestors, "assetAreas" => $assetAreas, "assetProcesses" => $assetProcesses); if ($assetData) { $response->json(Result::success('', $result)); } else { $response->json(Result::error('Asset not found')); } }); $this->respond(['GET', 'POST'], '/get/all', function ($request, $response, $service, $app) { $result = Assets::getAllAssets(); $response->json(Result::success('', $result)); });
private static function isAssetMatching($rentDemand, $asset) { // check employmentRegion if (!empty($rentDemand['employmentRegion']) && $rentDemand['employmentRegion'] != $asset['employmentRegion']) { $empRegionFlexList = json_decode($rentDemand['employmentRegionFlexibility'], true); if (!empty($empRegionFlexList)) { $foundEquals = false; foreach ($empRegionFlexList as $empRegionFlex) { if ($empRegionFlex == $asset['employmentRegion']) { $foundEquals = true; break; } } if (!$foundEquals) { return false; } } else { return false; } } // check if at least one rentArea is matching $rentAreas = RentAreas::getAssetRentAreas($asset['id']); $availableCount = 0; $matchingCount = 0; $ans = array(); $isMatching = false; foreach ($rentAreas as $rentArea) { $availableCount++; if (Assets::isRentAreaMatching($rentDemand, $rentArea)) { $matchingCount++; // getting from first match if (!$isMatching) { $ans['availableDate'] = $rentArea['populating']; $ans['price'] = $rentArea['price']; $ans['finishing'] = $rentArea['finishing']; } $isMatching = true; } } if (!$isMatching) { return $isMatching; } else { $ans['matchRatio'] = $availableCount == 0 ? 0 : $matchingCount / $availableCount * 100; return $ans; } }