public static function getAssetMatchingInvestmentProfiles($assetID) { global $db; $result = array("matching" => [], "notMatching" => []); $assetRow = $db->get('assets', 'sellingProfile', ['id' => $assetID]); if ($assetRow === false) { return false; } $sellingProfile = json_decode($assetRow, true); $investmentProfileRows = $db->select('investmentProfiles', ['id', 'investmentProfile']); foreach ($investmentProfileRows as $investmentProfileRow) { $investmentProfile = json_decode($investmentProfileRow['investmentProfile'], true); $matchResult = Assets::checkMatch($sellingProfile, $investmentProfile); $toPush = array("id" => $investmentProfileRow['id'], "investor" => Investors::getInvestorFromProfile($investmentProfileRow['id']), "percentage" => $matchResult['percentage'], "reasons" => array("negative" => $matchResult['negativeReasons'], "positive" => $matchResult['positiveReasons']), "matched" => Logs::isLogExists($assetID, $investmentProfileRow['id'])); if ($matchResult['notMatching']) { array_push($result['notMatching'], $toPush); } else { array_push($result['matching'], $toPush); } } return $result; }
public static function matchAssetAndInvestmentProfile($assetID, $investmentProfileID, $reasons, $isMatching) { global $db; $investor = Investors::getInvestorFromProfile($investmentProfileID); $reasons = json_encode($reasons); $data = ['asset' => $assetID, 'investmentProfile' => $investmentProfileID, 'investor' => $investor['id'], 'reasons' => $reasons, 'isMatching' => $isMatching, 'processStage' => 'marketing', 'status' => 'alive']; $id = $db->insert('logs', $data); return Logs::getLog($id); }
public static function getInvestmentProfileMatchingAssets($investmentProfileID) { global $db; $result = array("notMatching" => [], "matching" => array("forSale" => [], "notForSale" => [])); $investmentProfileRow = $db->get('investmentProfiles', 'investmentProfile', ['id' => $investmentProfileID]); if ($investmentProfileRow === false) { return false; } $investmentProfile = json_decode($investmentProfileRow, true); $investor = Investors::getInvestorFromProfile($investmentProfileID); $assets = self::getNotInvestorAssets($investor['id']); foreach ($assets as $asset) { $sellingProfile = json_decode($asset['sellingProfile'], true); $matchResult = Assets::checkMatch($sellingProfile, $investmentProfile); $toPush = array("id" => $asset['id'], "name" => $asset['name'], "percentage" => $matchResult['percentage'], "reasons" => array("negative" => $matchResult['negativeReasons'], "positive" => $matchResult['positiveReasons']), "matched" => Logs::isLogExists($asset['id'], $investmentProfileID)); if ($matchResult['notMatching']) { array_push($result['notMatching'], $toPush); } else { if ($asset['isForSale'] == 1) { array_push($result['matching']['forSale'], $toPush); } else { array_push($result['matching']['notForSale'], $toPush); } } } return $result; }
}); $this->respond(['GET', 'POST'], '/edit/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $data = json_decode($request->body(), true); $result = InvestmentProfiles::updateInvestmentProfile($id, $data); if ($result > 0) { $response->json(Result::success('InvestmentProfile Updated.')); } elseif ($result === 0) { $response->json(Result::success('InvestmentProfile not Updated.')); } else { $response->json(Result::error('InvestmentProfile not found')); } }); $this->respond(['GET', 'POST'], '/delete/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $result = InvestmentProfiles::deleteInvestmentProfile($id); if ($result > 0) { $response->json(Result::success('InvestmentProfile Deleted.')); } else { $response->json(Result::error('InvestmentProfile not Deleted')); } }); $this->respond(['GET', 'POST'], '/get-investor-from-profile/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $result = Investors::getInvestorFromProfile($id); if ($result > 0) { $response->json(Result::success('', $result)); } else { $response->json(Result::error('Investor not found')); } });