public function renderShow($id) { $service = new TripService($this->entityManager); $trip = $service->find($id); $this->template->trip = $trip; try { $eventService = new EventService(); $config = Environment::getConfig('api'); $events = $eventService->getEvents($trip->arrival, new DateTime(), new EventfulMapper($config->eventfulUser, $config->eventfulPassword, $config->eventfulKey)); $this->template->events = $events; } catch (InvalidStateException $e) { $this->template->events = array(); } $articleService = new ArticleService($this->entityManager); $this->template->article = $articleService->buildArticle($trip->arrival, new ArticleWikipediaMapper()); try { $airportMapper = new AirportTravelMathMapper(); $airportService = new AirportService(); $locationService = new LocationService(); $coordinates = $locationService->getCoordinates($trip->getDeparture()); $from = $airportService->searchNearestAirport($airportMapper, $coordinates['latitude'], $coordinates['longitude']); $coordinates = $locationService->getCoordinates($trip->getArrival()); $to = $airportService->searchNearestAirport($airportMapper, $coordinates['latitude'], $coordinates['longitude']); $flightMapper = new FlightKayakMapper(); $flightService = new FlightService($this->entityManager); $depart_date = new DateTime('now'); $return_date = new DateTime('+1 week'); $this->template->flights = $flightService->buildFlights($flightMapper, $from, $to, $depart_date, $return_date, '1', 'e', 'n'); } catch (FlightException $e) { $this->template->flightsError = "Connection with search system <a href='http://kayak.com'>Kayak</a> failed."; } catch (AirportException $e) { $this->template->flightsError = $e->getMessage(); } }
/** * Gets all locations. * @return string[] $locationList */ private function _getLocationList() { $locationService = new LocationService(); $locationList = array('-1' => __('All')); $locations = $locationService->getLocationList(); foreach ($locations as $location) { $locationList[$location->id] = $location->name; } return $locationList; }
/** * AJAX signal handler for getting user location string. */ public function handleLocation() { $latitude = $this->request->post['latitude']; $longitude = $this->request->post['longitude']; $service = new LocationService(); try { $location = $service->getLocation($latitude, $longitude); $this->terminate(new JsonResponse(array('status' => 'OK', 'location' => $location->street . ', ' . $location->city . ', ' . $location->country))); } catch (InvalidStateException $e) { $this->terminate(new JsonResponse(array('status' => 'FAIL'))); } }
public static function loadModel() { if (self::$_model === null) { if (isset($_GET['id'])) { self::$_model = Location::model()->findByPk($_GET['id']); } if (self::$_model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } } return self::$_model; }
/** * Deletes a particular model. * If deletion is successful, the browser will be redirected to the 'index' page. */ public function actionDelete() { if (Yii::app()->request->isPostRequest) { // we only allow deletion via POST request if (LocationService::loadModel()->delete()) { Flashes::addInfoFlash(Yii::t('amo', 'Location deleted')); } else { Flashes::addErrorFlash(Yii::t('amo', 'Could not delete the location.') . ' ' . Yii::t('amo', 'Please, try again later.')); } $this->redirect(array('index')); } else { throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.'); } }
protected function getEmployeeListAsJson() { $jsonArray = array(); $employeeService = $this->getEmployeeService(); $locationService = new LocationService(); $employeeList = UserRoleManagerFactory::getUserRoleManager()->getAccessibleEntities('Employee'); $employeeUnique = array(); foreach ($employeeList as $employee) { $workShiftLength = 0; $employeeCountry = null; $terminationId = $employee->getTerminationId(); if (!isset($employeeUnique[$employee->getEmpNumber()]) && empty($terminationId)) { $employeeWorkShift = $employeeService->getWorkShift($employee->getEmpNumber()); if ($employeeWorkShift != null) { $workShiftLength = $employeeWorkShift->getWorkShift()->getHoursPerDay(); } else { $workShiftLength = WorkShift::DEFAULT_WORK_SHIFT_LENGTH; } /*$operatinalCountry = $employee->getOperationalCountry(); if ($employee->getOperationalCountry() instanceof OperationalCountry) { $employeeCountry = $operatinalCountry->getId(); }*/ $employeeLocations = $employee->getLocations(); if ($employeeLocations[0] instanceof Location) { $location = $locationService->getLocationById($employeeLocations[0]->getId()); if ($location instanceof Location) { $country = $location->getCountry(); if ($country instanceof Country) { $employeeOperationalCountry = $country->getOperationalCountry(); if ($employeeOperationalCountry instanceof OperationalCountry) { $employeeCountry = $employeeOperationalCountry->getId(); } } } } $name = $employee->getFullName(); $employeeUnique[$employee->getEmpNumber()] = $name; $jsonArray[] = array('name' => $name, 'id' => $employee->getEmpNumber(), 'workShift' => $workShiftLength, 'country' => $employeeCountry); } } $jsonString = json_encode($jsonArray); return $jsonString; }
/** * Gets all locations. * @return string[] $locationList */ private function _getLocationList() { $locationService = new LocationService(); $showAll = $this->getOption('show_all_locations'); $locationList = array(); $locations = $locationService->getLocationList(); $accessibleLocations = UserRoleManagerFactory::getUserRoleManager()->getAccessibleEntityIds('Location'); foreach ($locations as $location) { if ($showAll || in_array($location->id, $accessibleLocations)) { $locationList[$location->id] = $location->name; } } return $locationList; }
public function getNumberOfEmployees() { $locationService = new LocationService(); return (string) $locationService->getNumberOfEmplyeesForLocation($this->id); }
/** * Gets all locations. * @return string[] $locationList */ private function _getLocationList() { $locationService = new LocationService(); $showAll = $this->getOption('show_all_locations'); $locationList = array(); $locations = $locationService->getLocationList(); $accessibleLocations = UserRoleManagerFactory::getUserRoleManager()->getAccessibleEntityIds('Location', BasicUserRoleManager::OPERATION_VIEW); foreach ($locations as $location) { if ($showAll || in_array($location->id, $accessibleLocations)) { $locationList[$location->getCountry()->getCouName()][] = $location; } } ksort($locationList); return $locationList; }
private function _getLocations(Employee $employee) { $locationList = array('' => '-- ' . __('Select') . ' --'); $locationService = new LocationService(); $locations = $locationService->getLocationList(); $accessibleLocations = UserRoleManagerFactory::getUserRoleManager()->getAccessibleEntityIds('Location'); $empLocations = $employee->getLocations(); foreach ($empLocations as $location) { $accessibleLocations[] = $location->getId(); } foreach ($locations as $location) { if (in_array($location->id, $accessibleLocations)) { $locationList[$location->id] = $location->name; } } return $locationList; }