/** * @param Params $params * @param bool $allowDraft * * @return \Jobs\Entity\Job|object * @throws \Doctrine\ODM\MongoDB\LockException */ public function get(Params $params, $allowDraft = false) { /* @var \Jobs\Repository\Job $jobRepository */ $jobRepository = $this->repositoryService->get('Jobs/Job'); $idFromRoute = $params('id', 0); $idFromQuery = $params->fromQuery('id', 0); $idFromSubForm = $params->fromPost('job', 0); $id = empty($idFromRoute) ? empty($idFromQuery) ? $idFromSubForm : $idFromQuery : $idFromRoute; if (empty($id) && $allowDraft) { $this->acl->__invoke('Jobs/Manage', 'new'); $user = $this->auth->getUser(); /** @var \Jobs\Entity\Job $job */ $job = $jobRepository->findDraft($user); if (empty($job)) { $job = $jobRepository->create(); $job->setIsDraft(true); $job->setUser($user); $this->repositoryService->store($job); } return $job; } $job = $jobRepository->find($id); if (!$job) { throw new \RuntimeException('No job found with id "' . $id . '"'); } return $job; }
/** * Shorthand method for getting params from URLs. Makes code easier to edit and avoids DRY code. * * @param string $paramName * * @return array|string */ public function __invoke($paramName) { $escaper = new Escaper('utf-8'); /* * Return early. Usually params will come from post. * * @var mixed */ $param = $this->params->fromPost($paramName, null); if (!$param) { $param = $this->findParam($paramName); } /* * If this is array it MUST comes from fromFiles() */ if (is_array($param) && !empty($param)) { return $param; } return $escaper->escapeHtml($param); }
public function getLocationsByCityAction(Params $params, BaseFinder $cityFinderService, BaseFinder $regionFinderService, BaseFinder $countryFinderService) { $dataLocation = $params->fromPost(); $city = $cityFinderService->find(['RoLocations' => ['Cities' => ['Id' => $dataLocation['id']]]]); if (!$city) { $this->setError('error'); return $this->view; } $this->view->countries = $countryFinderService->findMany(['RoLocations' => ['Countries' => []]]); $this->view->regions = $regionFinderService->findMany(['RoLocations' => ['Regions' => ['countryId' => $city->getCountryId()]]]); $this->view->cities = $cityFinderService->findMany(['RoLocations' => ['Cities' => ['regionId' => $city->getRegionId()]]]); $this->view->locations = $city->extract(); return $this->view; }
public function fromPost($param = null, $default = null) { return $this->params->fromPost($param, $default); }