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}"); }
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; }