public function processRequest(User $user = NULL) { // check for a journey image list, if none exists, redirect to start journey view if (!isset($_SESSION['JOURNEY_IMAGE_LIST']) || empty($_SESSION['JOURNEY_IMAGE_LIST'])) { $startJourneyUrl = UrlFormatter::formatRoutingItemUrl('views/StartJourneyView'); header("Location: {$startJourneyUrl}"); exit; } // check for journey name and comments, if they're missing, redirect to finish journey view $finishJourneyUrl = UrlFormatter::formatRoutingItemUrl('views/FinishJourneyView'); if (!isset($_POST[self::POST_PARAM_JOURNEY_NAME]) || empty($_POST[self::POST_PARAM_JOURNEY_NAME]) || !isset($_POST[self::POST_PARAM_JOURNEY_COMMENTS]) || empty($_POST[self::POST_PARAM_JOURNEY_COMMENTS])) { header("Location: {$finishJourneyUrl}"); exit; } $journeyName = strip_tags($_POST[self::POST_PARAM_JOURNEY_NAME]); $journeyName = str_replace("\\", "", $journeyName); $journeyComments = strip_tags($_POST[self::POST_PARAM_JOURNEY_COMMENTS]); $journeyComments = str_replace("\\", "", $journeyComments); // populate and save a new journey data object $journeyData = new Journey(); $journeyData->setTitle($journeyName); $journeyData->setComments($journeyComments); $journeyData->setCreationDate(time()); foreach ($_SESSION['JOURNEY_IMAGE_LIST'] as $imageDataId) { $journeyData->addImageId($imageDataId); } $dbConnection = DbConnectionUtil::getDbConnection(); $journeyData->save($dbConnection); // unset the journey image list unset($_SESSION['JOURNEY_IMAGE_LIST']); unset($_SESSION['JOURNEY_ATTRIBUTE_MAP']); // redirect to the journey details view $journeyDetailsUrl = UrlFormatter::formatRoutingItemUrl('views/JourneyDetailsView', array(JourneyDetailsView::GET_PARAM_JOURNEY_ID => $journeyData->getId())); header("Location: {$journeyDetailsUrl}"); }
/** * @param \SimpleXMLElement $xml * @param string $date The date that will be assigned to this journey * @param Journey $obj An optional existing journey to overwrite * @return Journey */ public static function createFromXml(\SimpleXMLElement $xml, \DateTime $date, Journey $obj = null) { if (!$obj) { $obj = new StationBoardJourney(); } $obj = Journey::createFromXml($xml, $date, $obj); $obj->stop = Stop::createFromXml($xml->MainStop->BasicStop, $date, null); return $obj; }
/** LOADERS **/ public function load_uri($uri, $order_by = 'duration') { //$uri = 'from=2.31021881104%3B48.8662580532&to=2.37064361572%3B48.8669355812&datetime=20160209T0830'; $req = 'https://' . NAVITIA_KEY . '@api.navitia.io/v1/journeys?' . $uri; //echo($req); $data = file_get_contents($req, false); $api = json_decode($data, true); foreach ($api['links'] as $link) { $this->links[$link['type']] = $link['href']; } foreach ($api['journeys'] as $j) { $journey = new Journey(); $journey->load_api($j); $this->journeys[] = $journey; } foreach ($api['feed_publishers'] as $p) { $this->publishers[] = $p['id']; } // Order journeys by : usort($this->journeys, "order_by_" . $order_by); }
/** * @param \SimpleXMLElement $xml * @param \DateTime $date The date that will be assigned to this journey * @param StationBoardJourney $obj An optional existing journey to overwrite * * @return StationBoardJourney */ public static function createStationBoardFromXml(\SimpleXMLElement $xml, \DateTime $date, StationBoardJourney $obj = null) { if (!$obj) { $obj = new self(); } $stop = Stop::createFromXml($xml->MainStop->BasicStop, $date, null); // use resolved date from main stop $date = new \DateTime($stop->departure); /* @var $obj StationBoardJourney */ $obj = Journey::createFromXml($xml, $date, $obj); $obj->stop = $stop; return $obj; }
public function getConnection($jsonString) { $data = json_decode($jsonString); $connections = array(); if ($data->from && $data->to) { if (isset($data->connections[0])) { foreach ($data->connections as $result) { $connection = new Connection(); $connection->setFrom($result->from->station->name); $connection->setTo($result->to->station->name); $connection->setArivallTime($result->to->arrival); $connection->setDepartureTime($result->from->departure); $connection->setDuration($result->duration); $connection->setTransfers($result->transfers); foreach ($result->sections as $journeyResult) { if (isset($journeyResult->journey)) { // var_dump ($journeyResult); $journey = new Journey(); $journey->setName($journeyResult->journey->name); $journey->setCategory($journeyResult->journey->category); $departure = new JourneyDetails(); $departure->setTime($journeyResult->departure->departure); $departure->setPlatform($journeyResult->departure->platform); $departure->setLocation($journeyResult->departure->station->name); $journey->setDeparture($departure); $arrival = new JourneyDetails(); $arrival->setTime($journeyResult->arrival->arrival); $arrival->setPlatform($journeyResult->arrival->platform); $arrival->setLocation($journeyResult->arrival->station->name); $journey->setArrival($arrival); $connection->addJourney($journey); } else { if (isset($journeyResult->walk)) { //ToDo } else { //ToDo is necessary } } } array_push($connections, $connection); } } } // echo $connection->getFrom(), "<br>"; // echo $connection->getTo(), "<br>"; // echo $connection->getDuration(), "<br>"; // echo $connection->getTransfers(), "<br>"; // var_dump($connection->getJourney()); // var_dump($connections); return $connections; }
public function processRequest(User $user = NULL) { parent::displayHeader($user, 'Journeys List'); $dbConnection = DbConnectionUtil::getDbConnection(); $journeyIdList = Journey::loadAllJourneyIdList($dbConnection); $journeyDataList = array(); foreach ($journeyIdList as $journeyId) { $journeyDataList[] = Journey::loadJourneyById($dbConnection, $journeyId); } ?> <div class="imageDetailsView"> <?php foreach ($journeyDataList as $journeyData) { $journeyDetailUrl = UrlFormatter::formatRoutingItemUrl('views/JourneyDetailsView', array(JourneyDetailsView::GET_PARAM_JOURNEY_ID => $journeyData->getId())); ?> <div style="display:inline-block" class="searchResultItem"> <label for="journey_name_field">Journey Name</label> <br/> <a href="<?php echo $journeyDetailUrl; ?> "><span id="journey_name_field" class="imageDetailsField"><?php echo $journeyData->getTitle(); ?> </span></a> <br/> <label for="journey_date_field">Journey Date</label> <br/> <span id="journey_date_field" class="imageDetailsField"><?php echo $journeyData->getCreationDate(); ?> </span> </div> <div style="clear:both"></div> <?php } ?> </div> <?php parent::displayFooter(); }
private static function populateJourneyFromResultSet(PDO $dbConnection, $resultSet) { $journeyData = new Journey($resultSet['id']); $journeyData->setTitle($resultSet['title']); $journeyData->setComments($resultSet['comments']); $journeyData->setCreationDate($resultSet['creation_date']); $stmt = $dbConnection->prepare('SELECT image_data_id FROM journey_image_data_assoc WHERE journey_id = :id'); $stmt->bindParam(':id', $journeyData->getId()); $stmt->execute(); $resultRow = NULL; while ($resultRow = $stmt->fetch(PDO::FETCH_ASSOC)) { $journeyData->addImageId($resultRow['image_data_id']); } $stmt = NULL; return $journeyData; }
public function processRequest(User $user = NULL) { $journeyId = RequestParser::parseRequestParam($_GET, self::GET_PARAM_JOURNEY_ID, RequestParser::PARAM_FILTER_TYPE_INT); $baseUrl = Settings::getSetting('APPLICATION_URL'); if (!$journeyId) { header("Location: {$baseUrl}"); exit; } // load the journey data $dbConnection = DbConnectionUtil::getDbConnection(); $journeyData = Journey::loadJourneyById($dbConnection, $journeyId); if (!$journeyData) { header("Location: {$baseUrl}"); exit; } // load the images from the journey $imageDataList = ImageData::loadImageDataListByIdSet($dbConnection, $journeyData->getImageIdList()); parent::displayHeader($user, 'Journey Details'); ?> <div class="imageDetailsView"> <label for="journey_name_field">Journey Name</label> <br/> <span id="journey_name_field" class="imageDetailsViewField"><?php echo $journeyData->getTitle(); ?> </span> <br/> <label for="journey_creation_date_field">Journey Date</label> <br/> <span id="journey_creation_date_field" class="imageDetailsViewField"><?php echo $journeyData->getCreationDate(); ?> </span> <br/> <label for="journey_comments_field">Journey Comments</label> <br/> <p id="journey_comments_field" class="imageDetailsViewField"><?php echo $journeyData->getComments(); ?> </p> </div> <div class="imageGrid"> <?php foreach ($imageDataList as $imageData) { $imageDetailsUrl = UrlFormatter::formatRoutingItemUrl('views/ImageDetailsView', array(ImageDetailsView::GET_PARAM_IMAGE_ID => $imageData->getId())); $thumbnailUrl = UrlFormatter::formatImageUrl($imageData->getThumbnailUri()); ?> <a target="_blank" href="<?php echo $imageDetailsUrl; ?> "><img src="<?php echo $thumbnailUrl; ?> "/></a> <?php } ?> </div> <?php parent::displayFooter(); }
public function addJourney(Journey $journey) { $this->_distance += $journey->getDistance(); $this->journeys[] = $journey; }