/** * @desc Runs `composer update` by monitoring `composer.json`. */ public function watchComposer() { if (!$this->watcherReady()) { return Result::error($this); } $this->watcherComposerMonitor(); $this->taskWatch->run(); }
} }); $this->respond(['GET', 'POST'], '/match-mod/get/assets', function ($request, $response, $service, $app) { $id = $request->param('id'); $result = Assets::getRentDemandMatchingAssets($id); $response->json(Result::success('', $result)); }); $this->respond(['GET', 'POST'], '/match-mod/match', function ($request, $response, $service, $app) { $rentDemandID = $request->param('rentDemandID'); $assetID = $request->param('assetID'); $id = RentProcesses::matchRentDemandAndAsset($rentDemandID, $assetID); if ($id > 0) { $response->json(Result::success('Matched.', ['rentProcessID' => $id])); } else { $response->json(Result::error('Error trying to match')); } }); $this->respond(['GET', 'POST'], '/delete/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $rentDemandResult = RentDemands::deleteRentDemand($id); RentProcesses::deleteRentDemandProcesses($id); if ($rentDemandResult > 0) { $response->json(Result::success('Demand Deleted.')); } else { $response->json(Result::error('Demand not Deleted')); } }); $this->respond(['GET', 'POST'], '/get/all', function ($request, $response, $service, $app) { $result = RentDemands::getAllRentDemands(); $response->json(Result::success('', $result)); });
if ($result) { $response->json(Result::success('', $result)); } else { $response->json(Result::error('RentProcess not found')); } }); $this->respond(['GET', 'POST'], '/edit/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $data = json_decode($request->body(), true); $result = RentProcesses::updateRentProcess($id, $data); if ($result > 0) { $response->json(Result::success('RentProcess Updated.')); } elseif ($result === 0) { $response->json(Result::success('RentProcess not Updated.')); } else { $response->json(Result::error('RentProcess not found')); } }); $this->respond(['GET', 'POST'], '/delete/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $result = RentProcesses::deleteRentProcess($id); if ($result > 0) { $response->json(Result::success('RentProcess Deleted.')); } else { $response->json(Result::error('RentProcess not Deleted')); } }); $this->respond(['GET', 'POST'], '/get/all', function ($request, $response, $service, $app) { $result = RentProcesses::getAllRentProcesses(); $response->json(Result::success('', $result)); });
$agents = $request->param('logAgents'); $result = Logs::updateLog($id, $logData, $agents); if ($result > 0) { $response->json(Result::success('Log Updated.')); } elseif ($result === 0) { $response->json(Result::success('Log not Updated.')); } else { $response->json(Result::error('Log not found')); } }); $this->respond(['GET', 'POST'], '/get/[i:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $logData = Logs::getLog($id); $agents = Agents::getLogAgents($id); $notes = Notes::getLogNotes($id); $result = array("logData" => $logData, "logAgents" => $agents, "logNotes" => $notes); if ($logData) { $response->json(Result::success('', $result)); } else { $response->json(Result::error('Log not found')); } }); $this->respond(['GET', 'POST'], '/delete/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $result = Logs::deleteLog($id); if ($result > 0) { $response->json(Result::success('Log Deleted.')); } else { $response->json(Result::error('Log not Deleted')); } });
function __defaultReturn($success_message, $error_messages) { if (is_html()) { if (!$error_messages) { Flash::ok($success_message); return Redirect::success(); } else { foreach ($error_messages as $error_msg) { Flash::error($error_msg); } return Redirect::failure(); } } else { if (!$error_messages) { return Result::ok(); } else { return Result::error($error_messages); } } }
<?php $this->respond(['GET', 'POST'], '/uploadFile', function ($request, $response, $service, $app) { $ans = FileUploader::uploadFile(); if ($ans != -1) { $response->json(Result::success('file uploaded.', ['path' => $ans])); } else { $response->json(Result::error('file upload Failed.')); } });
$id = $request->param('id'); $assetData = $request->param('assetData'); $contactsData = $request->param('assetContacts'); $investorsData = $request->param('assetInvestors'); $result = Assets::updateAssetInvest($id, $assetData, $contactsData, $investorsData); if ($result > 0) { $response->json(Result::success('Asset Updated.')); } elseif ($result === 0) { $response->json(Result::success('Asset not Updated.')); } else { $response->json(Result::error('Asset not found')); } }); $this->respond(['GET', 'POST'], '/delete/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $assetResult = Assets::deleteAsset($id); Logs::deleteAssetInvestLogs($id); Contacts::deleteAssetContacts($id); Investors::deleteAssetInvestors($id); RentAreas::deleteAssetRentAreas($id); RentProcesses::deleteAssetRentProcesses($id); if ($assetResult > 0) { $response->json(Result::success('Asset Deleted.')); } else { $response->json(Result::error('Asset not Deleted')); } }); $this->respond(['GET', 'POST'], '/get/all', function ($request, $response, $service, $app) { $result = Assets::getAllAssets(); $response->json(Result::success('', $result)); });
$isMatching = $request->param('isMatching'); if (Logs::isLogAlreadyConnectedToInvestor($assetID, $investmentProfileID)) { $response->json(Result::error('קיים כבר לוג בין המשקיע לנכס')); } else { $result = Logs::matchAssetAndInvestmentProfile($assetID, $investmentProfileID, $reasons, $isMatching); if ($result) { $response->json(Result::success('Matched.', $result)); } else { $response->json(Result::error('Error trying to match')); } } }); $this->respond(['GET', 'POST'], '/cancel/asset-and-investment-profile', function ($request, $response, $service, $app) { $logID = $request->param('logID'); $result = Logs::cancelMatchAssetAndInvestmentProfile($logID); if ($result > 0) { $response->json(Result::success('Canceled')); } else { $response->json(Result::error('Error trying to cancel')); } }); $this->respond(['GET', 'POST'], '/get/marketing-logs/all', function ($request, $response, $service, $app) { $assetID = $request->param('assetID', ''); $investmentProfileID = $request->param('investmentProfileID', ''); $result = Logs::getAllMarketingLogs($assetID, $investmentProfileID); if ($result) { $response->json(Result::success('', $result)); } else { $response->json(Result::error('Marketing Logs not found')); } });
/** * Tries to execute the given function and returns a result representing the * outcome, i.e. if the function returns normally, a successful result is * returned containing the return value and if the function throws an exception, * an error result is returned containing the error * * $f should take no arguments and return a value that will be wrapped in a * success if the computation completes successfully * * The _ is required if we want to use the word try since it is keyword */ public static function _try(callable $f) { try { return Result::success($f()); } catch (\Exception $error) { return Result::error($error); } }
}); $this->respond(['GET', 'POST'], '/get/[i:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $result = Notes::getNote($id); if ($result) { $response->json(Result::success('', $result)); } else { $response->json(Result::error('Note not found')); } }); $this->respond(['GET', 'POST'], '/edit/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $data = json_decode($request->body()); $result = Notes::updateNote($id, $data); if ($result > 0) { $response->json(Result::success('Note Updated.')); } elseif ($result === 0) { $response->json(Result::success('Note not Updated.')); } else { $response->json(Result::error('Note not found')); } }); $this->respond(['GET', 'POST'], '/delete/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $result = Notes::deleteNote($id); if ($result > 0) { $response->json(Result::success('Note Deleted.')); } else { $response->json(Result::error('Note not Deleted')); } });
function getSubmissionPart($against) { # Validating file inputs is a rather difficult task. # This solution is based on: http://php.net/manual/en/features.file-upload.php#114004 # It should be pretty bullet-proof, which is important because # it is easy to create security vulnerabilities with file uploads. return $against->files($this->name)->ifOk(function ($val) { # See http://php.net/manual/en/features.file-upload.php if (!is_array($val) || !isset($val['error']) || is_array($val['error'])) { return Result::error('Invalid data.'); } else { if ($val['error'] === UPLOAD_ERR_INI_SIZE || $val['error'] === UPLOAD_ERR_FORM_SIZE) { return Result::error('File size exceeds server or form limit.'); } else { if ($val['error'] === UPLOAD_ERR_NO_FILE) { return Result::none(null); } else { if ($val['error'] === UPLOAD_ERR_OK) { return Result::ok($val); } else { return Result::error('Error uploading file.'); } } } } })->requiredMaybe($this->required)->ifOk(function ($file) { if ($file['size'] > $this->maxSize) { return Result::error('File must be under ' . $this->maxSize . ' bytes in size.'); } else { return Result::ok($file); } })->ifOk(function ($file) { $finfo = new finfo(FILEINFO_MIME_TYPE); $mime = $finfo->file($file['tmp_name']); $ext = array_search($mime, $this->allowedExtensions, true); if ($ext === false) { return Result::error('Invalid file type or wrong MIME type. Allowed extensions are: ' . implode(', ', array_keys($this->allowedExtensions)) . '.'); } if (!is_uploaded_file($file['tmp_name'])) { return Result::error('Security error.'); } $filename = sha1_file($file['tmp_name']) . '-' . floor(microtime(true)) . '.' . $ext; return Result::ok(new FileInfo($file, $filename, $mime, $this->permissions)); })->name($this->name); }
}); $this->respond(['GET', 'POST'], '/get/[i:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $result = RentAreas::getRentArea($id); if ($result) { $response->json(Result::success('', $result)); } else { $response->json(Result::error('RentArea not found')); } }); $this->respond(['GET', 'POST'], '/edit/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $data = json_decode($request->body()); $result = RentAreas::updateRentArea($id, $data); if ($result > 0) { $response->json(Result::success('RentArea Updated.')); } elseif ($result === 0) { $response->json(Result::success('RentArea not Updated.')); } else { $response->json(Result::error('RentArea not found')); } }); $this->respond(['GET', 'POST'], '/delete/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $result = RentAreas::deleteRentArea($id); if ($result > 0) { $response->json(Result::success('RentArea Deleted.')); } else { $response->json(Result::error('RentArea not Deleted')); } });
} }); $this->respond(['GET', 'POST'], '/edit/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $data = json_decode($request->body()); $result = Regions::updateRegion($id, $data); if ($result > 0) { $response->json(Result::success('Region Updated.')); } elseif ($result === 0) { $response->json(Result::success('Region not Updated.')); } else { $response->json(Result::error('Region not found')); } }); $this->respond(['GET', 'POST'], '/delete/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $result = Regions::deleteRegion($id); if ($result > 0) { $response->json(Result::success('Region Deleted.')); } else { $response->json(Result::error('Region not Deleted')); } }); $this->respond(['GET', 'POST'], '/get/all', function ($request, $response, $service, $app) { $result = Regions::getAllRegions(); $response->json(Result::success('', $result)); }); $this->respond(['GET', 'POST'], '/index/all', function ($request, $response, $service, $app) { $result = Regions::getAllRegionsForIndex(); $response->json(Result::success('', $result)); });
$data = json_decode($request->body(), true); // Access only for Current Agent if (!Agents::isAdmin() && !Agents::isCurrentAgent($id)) { $response->json(Result::error('Access is denied')); } else { $result = Agents::updateAgent($id, $data); if ($result > 0) { $response->json(Result::success('Agent Updated.')); } elseif ($result === 0) { $response->json(Result::success('Agent not Updated.')); } else { $response->json(Result::error('Agent not found')); } } }); $this->respond(['GET', 'POST'], '/edit/password/[:id]', function ($request, $response, $service) { $id = $request->param('id'); $oldPassword = $request->param('oldPassword', ''); $newPassword = $request->param('newPassword', ''); // Access only for Current Agent if (!Agents::isAdmin() && !Agents::isCurrentAgent($id)) { $response->json(Result::error('Access is denied')); } else { $result = User::editPassword($oldPassword, $newPassword, $newPassword); if ($result === true) { $response->json(Result::success('edited password successfully')); } else { $response->json(Result::error($result)); } } });
} else { $response->json(Result::error('Contact not found')); } }); $this->respond(['GET', 'POST'], '/delete/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $contactResult = Contacts::deleteContact($id); Conversations::deleteContactConversations($id); if ($contactResult > 0) { $response->json(Result::success('Contact Deleted.')); } else { $response->json(Result::error('Contact not Deleted')); } }); $this->respond(['GET', 'POST'], '/get/all-for-index', function ($request, $response, $service, $app) { $result = Contacts::getAllContactsForIndex(); $response->json(Result::success('', $result)); }); $this->respond(['GET', 'POST'], '/get/all', function ($request, $response, $service, $app) { $result = Contacts::getAllContacts(); $response->json(Result::success('', $result)); }); $this->respond(['GET', 'POST'], '/get-investor-contacts/[i:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $contacts = Contacts::getInvestorCrmContacts($id); if ($contacts) { $response->json(Result::success('', $contacts)); } else { $response->json(Result::error('Contact not found')); } });
Notes::deleteInvestorNotes($id); Assets::deleteInvestorAssets($id); Logs::deleteInvestorLogs($id); Contacts::deleteInvestorContacts($id); if ($investorResult > 0) { $response->json(Result::success('Investor Deleted.')); } else { $response->json(Result::error('Investor not Deleted')); } }); $this->respond(['GET', 'POST'], '/get/[i:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $investorData = Investors::getInvestor($id); $investorContacts = Contacts::getInvestorContacts($id); $investorAssets = Assets::getInvestorAssets($id); $investorProfiles = InvestmentProfiles::getInvestorProfiles($id); $investorBuyLogs = Logs::getInvestorLogs($id); $investorSellLogs = Logs::getInvestorAssetsLogs($id); $investorConversations = Conversations::getInvestorConversations($id); $investorNotes = Notes::getInvestorNotes($id); $result = array("investorData" => $investorData, "investorContacts" => $investorContacts, "investorAssets" => $investorAssets, "investorProfiles" => $investorProfiles, "investorBuyLogs" => $investorBuyLogs, "investorSellLogs" => $investorSellLogs, "investorConversations" => $investorConversations, "investorNotes" => $investorNotes); if ($investorData) { $response->json(Result::success('', $result)); } else { $response->json(Result::error('Investor not found')); } }); $this->respond(['GET', 'POST'], '/get/all', function ($request, $response, $service, $app) { $result = Investors::getAllInvestors(); $response->json(Result::success('', $result)); });
function min_max() { $min = Params::get("min"); $max = Params::get("max"); $value = Params::get("value"); $nome_parametro = Params::get("nome_parametro"); if ($value < $min || $value >= $max) { return Result::error($nome_parametro . " deve essere compreso tra " . $min . ""); } }
} }); $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)); });
$id = $request->param('id'); $result = Conversations::getConversation($id); if ($result) { $response->json(Result::success('', $result)); } else { $response->json(Result::error('Conversation not found')); } }); $this->respond(['GET', 'POST'], '/edit/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $data = json_decode($request->body(), true); $oldConv = Conversations::getConversation($id); Logs::createLogOnConversationSave($data, $oldConv); $result = Conversations::updateConversation($id, $data); if ($result > 0) { $response->json(Result::success('Conversation Updated.')); } elseif ($result === 0) { $response->json(Result::success('Conversation not Updated.')); } else { $response->json(Result::error('Conversation not found')); } }); $this->respond(['GET', 'POST'], '/delete/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $result = Conversations::deleteConversation($id); if ($result > 0) { $response->json(Result::success('Conversation Deleted.')); } else { $response->json(Result::error('Conversation not Deleted')); } });
function delete_gallery() { $gallery_name = Params::get("gallery_name"); $dir = new Dir($this->get_current_folder() . "/" . $gallery_name); $gallery_ini = $dir->newFile("_gallery.ini"); if ($gallery_ini->exists()) { $dir->delete(true); if (is_html()) { return Redirect::success(); } else { return Result::ok(); } } else { if (is_html()) { return Redirect::failure(); } else { return Result::error("Impossibile eliminare la gallery"); } } }
function groupValidate($items) { return $this->ifOk(function ($val) use($items) { return array_reduce($items, function ($total, $field) use($val) { if (!$field instanceof Storeable) { return $total; } return $field->getSubmissionPart(Result::ok($val))->collapse()->ifSuccess(function ($r) { return Result::ok(function ($total) use($r) { return array_merge($r, $total); }); })->ifError(function ($r) { return Result::error(function ($total) use($r) { return array_merge($r, $total); }); })->ifError(function ($merge) use($total) { return $total->ifOk(function ($x) { return Result::error([]); })->ifError(function ($x) use($merge) { return Result::error($merge($x)); }); })->ifOk(function ($merge) use($total) { return $total->ifOk(function ($x) use($merge) { return Result::ok($merge($x)); }); }); }, Result::ok([])); }); }
$result = User::login($request->param('username', 'none'), $request->param('password', 'none'), $request->param('rememberMe', true)); if ($result === true) { $response->json(Result::success('logged in successfully', ['REMEMBERMECOOKIE' => $_SESSION['REMEMBERMECOOKIE'], 'SESSIONID' => session_id()])); } else { $response->json(Result::error($result)); } }); //$this->respond(['GET','POST'], '/register', function ($request, $response, $service) { // $result = User::register($request->param('userName','none'),$request->param('mail','none'), // $request->param('password','none'),$request->param('passwordRepeat','none')); // if ($result != -1) { // $response->json(Result::success('registered successfuly',['id'=>$result])); // } // else // $response->json(Result::error($result)); //}); $this->respond(['GET', 'POST'], '/logout', function ($request, $response, $service) { if (User::isLoggedIn() !== true) { $response->json(Result::error('Can\'t Logout: Not logged in.')); } else { User::logout(); $response->json(Result::success('Logged out successfully')); } }); $this->respond(['GET', 'POST'], '/isLoggedIn', function ($request, $response, $service) { if (User::isLoggedIn() !== true) { $response->json(Result::error('You"re not logged in', [false])); } else { $response->json(Result::success('You"re logged in', array('userId' => User::currentUserID()))); } });
$response->json(Result::success('Notification Updated.')); } elseif ($result === 0) { $response->json(Result::success('Notification not Updated.')); } else { $response->json(Result::error('Notification not found')); } }); $this->respond(['GET', 'POST'], '/get/[i:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $notificationData = Notifications::getNotification($id); $notificationRecipients = Agents::getNotificationRecipients($id); $result = array("notificationData" => $notificationData, "notificationRecipients" => $notificationRecipients); if ($result) { $response->json(Result::success('', $result)); } else { $response->json(Result::error('Notification not found')); } }); $this->respond(['GET', 'POST'], '/delete/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $result = Notifications::deleteNotification($id); if ($result > 0) { $response->json(Result::success('Notification Deleted.')); } else { $response->json(Result::error('Notification not Deleted')); } }); $this->respond(['GET', 'POST'], '/get/all', function ($request, $response, $service, $app) { $result = Notifications::getAllNotificationsToShow(); $response->json(Result::success('', $result)); });
/** * Writes the result to destination. * * @return Result */ public function run() { foreach ($this->files as $in => $out) { $css = $this->compile($in); if (false === $css) { return \Result::error($this, 'Less compilation failed for %s.', $in); } $dst = $out . '.part'; $write_result = file_put_contents($dst, $css); rename($dst, $out); if (false === $write_result) { return Result::error($this, 'File write failed: %s', $out); } $this->printTaskSuccess(sprintf('Wrote CSS to <info>%s</info>', $out)); } return Result::success($this, 'All less files compiled.'); }
$stringifier->writeArray(json_decode($html, true), $res, $token); }); $klein->respond('POST', '/submit', function ($req, $res) use($parser, $stringifier) { $res->header('X-Frame-Options', 'DENY'); # Check for XSRF $csrf = new \Riimu\Kit\CSRF\CSRFHandler(); $csrf->validateRequest(true); # The name of the form is provided in the $_POST data, # not the URL! $page = $parser->parseJade($_POST['__form_name']); $config = Config::get(); $res->header('Content-Type', 'application/json; charset=utf-8'); # Do the form submission and create data that is # compatible with the frontend. return $page->form->getSubmissionPart(Result::ok(new ClientData($_POST, $_FILES)))->ifError(function ($val) { return Result::error(['success' => false, 'errors' => $val]); })->ifOk(function ($val) use($page, $config) { ob_start(); $val = $page->outputs->run($val, $page); var_dump($val); $out = ob_get_clean(); return Result::ok(['success' => true, 'debugOutput' => $config['debug'] ? $out : '']); })->ifError(function ($val) { return Result::ok($val); })->ifOk(function ($output) { return json_encode(['data' => $output]); }); }); # Generate a CSV file for a TableView # See http://stackoverflow.com/questions/217424/create-a-csv-file-for-a-user-in-php $klein->respond('GET', '/csv', function ($req, $res) use($parser, $stringifier) {