Esempio n. 1
0
 /**
  * Get controller from $mProjectUrl by request
  * @access public
  * @static
  * @param string $pPathInfo
  * @return array
  */
 public static function getControllerFromUrlObject($pPathInfo = '')
 {
     $controller_params = array();
     $pPathInfo = $pPathInfo ?: self::$mPathInfo;
     self::$mPojrectUrl->rewind();
     while (self::$mPojrectUrl->valid()) {
         list($pattern, $controller) = self::$mPojrectUrl->current();
         $pattern = '/' . str_replace('/', '\\/', $pattern) . '/';
         preg_match_all($pattern, $pPathInfo, $matched);
         if ($matched[0][0] == $pPathInfo) {
             $controller_params['c'] = $controller;
             $controller_params['p'] = self::getParamsFromRequest($matched);
             break;
         }
         self::$mPojrectUrl->next();
     }
     return $controller_params;
 }
Esempio n. 2
0
 /**
  * gets the Favorite by tweet it id
  *
  * @param \PDO $pdo PDO connection object
  * @param int $tweetId tweet id to search for
  * @return \SplFixedArray array of Favorites found or null if not found
  * @throws \PDOException when mySQL related errors occur
  * @throws \TypeError when variables are not the correct data type
  **/
 public static function getFavoriteByTweetId(\PDO $pdo, int $tweetId)
 {
     // sanitize the tweet id
     $tweetId = filter_var($tweetId, FILTER_VALIDATE_INT);
     if ($tweetId <= 0) {
         throw new \PDOException("tweet id is not positive");
     }
     // create query template
     $query = "SELECT profileId, tweetId, favoriteDate FROM favorite WHERE tweetId = :tweetId";
     $statement = $pdo->prepare($query);
     // bind the member variables to the place holders in the template
     $parameters = ["tweetId" => $tweetId];
     $statement->execute($parameters);
     // build an array of favorites
     $favorites = new \SplFixedArray($statement->rowCount());
     $statement->setFetchMode(\PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $favorite = new Favorite($row["tweetId"], $row["profileId"], $row["favoriteDate"]);
             $favorites[$favorites->key()] = $favorite;
             $favorites->next();
         } catch (\Exception $exception) {
             // if the row couldn't be converted, rethrow it
             throw new \PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $favorites;
 }
Esempio n. 3
0
 /**
  * get a favorite player by profile id
  *
  * @param \PDO $pdo PDO connection object
  * @param int $profileId
  * @return \SplFixedArray SplFixedArray of Favorite Players found or null if not found
  * @throws \PDOException when mySQL related errors occur
  * @throws \TypeError when variables are not the correct data type
  **/
 public static function getFavoritePlayersByFavoritePlayerProfileId(\PDO $pdo, int $favoritePlayerProfileId)
 {
     if ($favoritePlayerProfileId <= 0) {
         throw new \PDOException("this profile doesn't exist");
     }
     // create query template
     $query = "SELECT favoritePlayerProfileId, favoritePlayerPlayerId  FROM favoritePlayer WHERE favoritePlayerProfileId = :favoritePlayerProfileId";
     $statement = $pdo->prepare($query);
     $parameters = ["favoritePlayerProfileId" => $favoritePlayerProfileId];
     $statement->execute($parameters);
     // build an array of favorite players
     $favoritePlayers = new \SplFixedArray($statement->rowCount());
     $statement->setFetchMode(\PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $favoritePlayer = new FavoritePlayer($row["favoritePlayerProfileId"], $row["favoritePlayerPlayerId"]);
             $favoritePlayers[$favoritePlayers->key()] = $favoritePlayer;
             $favoritePlayers->next();
         } catch (\Exception $exception) {
             // if the row couldn't be converted, rethrow it
             throw new \PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $favoritePlayers;
 }
Esempio n. 4
0
 /**
  * getProductAlertByProductId
  *
  * @param PDO $pdo pointer to PDO connection, by reference
  * @param int $productId
  * @return mixed ProductAlert
  * @throws PDOException if productId is not an integer
  * @throws PDOException if productId is not positive
  **/
 public static function getProductAlertByProductId(PDO &$pdo, $productId)
 {
     // sanitize the productId before searching
     $productId = filter_var($productId, FILTER_VALIDATE_INT);
     if ($productId === false) {
         throw new PDOException("productId is not an integer");
     }
     if ($productId <= 0) {
         throw new PDOException("productId is not positive");
     }
     //create query template
     $query = "SELECT alertId, productId, alertEnabled FROM productAlert WHERE productId = :productId";
     $statement = $pdo->prepare($query);
     //bind the productId to the place holder in the template
     $parameters = array("productId" => $productId);
     $statement->execute($parameters);
     // build an array of ProductAlert(s)
     $productAlerts = new SplFixedArray($statement->rowCount());
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $productAlert = new ProductAlert($row["alertId"], $row["productId"], $row["alertEnabled"]);
             $productAlerts[$productAlerts->key()] = $productAlert;
             $productAlerts->next();
         } catch (PDOException $exception) {
             // if the row couldn't be converted, rethrow it
             throw new PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $productAlerts;
 }
Esempio n. 5
0
 /**
  * gets all Players by teamId
  *
  * @param \PDO $pdo PDO connection object
  * @return \SplFixedArray SplFixedArray of players found or null if not found
  * @throws \PDOException when mySQL related errors occur
  * @throws \TypeError when variables are not the correct data type
  **/
 public static function getAllPlayersByTeamId(\PDO $pdo, int $playerTeamId)
 {
     $query = "SELECT playerId, playerApiId, playerTeamId, playerSportId, playerName FROM player WHERE playerTeamId = :playerTeamId";
     $statement = $pdo->prepare($query);
     $parameters = ["playerTeamId" => $playerTeamId];
     $statement->execute($parameters);
     // build an array of Players
     $players = new \SplFixedArray($statement->rowCount());
     $statement->setFetchMode(\PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $player = new Player($row["playerId"], $row["playerApiId"], $row["playerTeamId"], $row["playerSportId"], $row["playerName"]);
             $players[$players->key()] = $player;
             $players->next();
         } catch (\Exception $exception) {
             // if the row couldn't be converted, rethrow it
             throw new \PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $players;
 }
Esempio n. 6
0
 /**
  * Gets all profiles
  *
  * @param PDO $pdo pointer to PDO connection, by reference
  * @return SplFixedArray of Profiles found
  * @throws PDOException when MySQL related errors occur
  */
 public static function getAllProfiles(PDO &$pdo)
 {
     // Create query template
     $query = "SELECT profileId, username, passwordHash FROM profile";
     $statement = $pdo->prepare($query);
     $statement->execute();
     // Build an array of profiles
     $profiles = new SplFixedArray($statement->rowCount());
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $profile = new Profile($row["profileId"], $row["username"], $row["passwordHash"]);
             $profiles[$profiles->key()] = $profile;
             $profiles->next();
         } catch (Exception $e) {
             // If the row couldn't be converted, rethrow it
             throw new PDOException($e->getMessage(), 0, $e);
         }
     }
     return $profiles;
 }
Esempio n. 7
0
 /**
  * gets the sport by the sport name
  *
  * @param \PDO $pdo connection object
  * @param string $sportName sport Name to search for
  * @return \SplFixedArray SplFixedArray of names found
  * @throws \PDOException when db related errors occur
  * @throws \TypeError when variables are not correct data type
  **/
 public static function getSportBySportName(\PDO $pdo, string $sportName)
 {
     // sanitize the description before searching
     $sportName = trim($sportName);
     $sportName = filter_var($sportName, FILTER_SANITIZE_STRING);
     if (empty($sportName) === true) {
         throw new \PDOException("That name is invalid");
     }
     // create query template
     $query = "SELECT sportId, sportName, sportLeague FROM sport WHERE sportName LIKE :sportName";
     $statement = $pdo->prepare($query);
     // bind the sport name to the place holder in the template
     $sportName = "%{$sportName}%";
     $parameters = array("sportName" => $sportName);
     $statement->execute($parameters);
     //build array of sport names
     $sportNames = new \SplFixedArray($statement->rowCount());
     $statement->setFetchMode(\PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $sport = new sport($row["sportId"], $row["sportLeague"], $row["sportName"]);
             $sportNames[$sportNames->key()] = $sport;
             $sportNames->next();
         } catch (\Exception $exception) {
             //if the row couldn't be converted, rethrow it
             throw new \PDOException($exception->getMessage(), 0, $exception);
         }
         return $sportNames;
     }
 }
Esempio n. 8
0
 public static function getAllPosts(\PDO $pdo)
 {
     // Create query template and execute
     $query = "SELECT postId, postProfileUserName, postSubmission, postTime FROM post";
     $statement = $pdo->prepare($query);
     $statement->execute();
     // Build an array of matches
     $posts = new \SplFixedArray($statement->rowCount());
     $statement->setFetchMode(\PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $post = new Post($row["postId"], $row["postProfileUserName"], $row["postSubmission"], \DateTime::createFromFormat("Y-m-d H:i:s", $row["postTime"]));
             $posts[$posts->key()] = $post;
             $posts->next();
         } catch (\Exception $exception) {
             throw new \PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $posts;
 }
Esempio n. 9
0
 /**
  * gets all Tweets
  *
  * @param PDO $pdo pointer to PDO connection, by reference
  * @return mixed SplFixedArray of Tweets found or null if not found
  * @throws PDOException when mySQL related errors occur
  **/
 public static function getAllTweets(PDO &$pdo)
 {
     // create query template
     $query = "SELECT tweetId, profileId, tweetContent, tweetDate FROM tweet";
     $statement = $pdo->prepare($query);
     $statement->execute();
     // build an array of tweets
     $tweets = new SplFixedArray($statement->rowCount());
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $tweet = new Tweet($row["tweetId"], $row["profileId"], $row["tweetContent"], $row["tweetDate"]);
             $tweets[$tweets->key()] = $tweet;
             $tweets->next();
         } catch (Exception $exception) {
             // if the row couldn't be converted, rethrow it
             throw new PDOException($exception->getMessage(), 0, $exception);
         }
     }
     // count the results in the array and return:
     // 1) null if 0 results
     // 2) the entire array if >= 1 result
     $numberOfTweets = count($tweets);
     if ($numberOfTweets === 0) {
         return null;
     } else {
         return $tweets;
     }
 }
Esempio n. 10
0
 /**
  * gets all Game
  *
  * @param \PDO $pdo PDO connection object
  * @return \SplFixedArray SplFixedArray of Game found or null if not found
  * @throws \PDOException when mySQL related errors occur
  * @throws \TypeError when variables are not the correct data type
  **/
 public static function getAllGame(\PDO $pdo)
 {
     //create query template
     $query = "SELECT gameId, gameFirstTeamId, gameSecondTeamId, gameTime FROM game ";
     $statement = $pdo->prepare($query);
     $statement->execute();
     //build an array of game
     $games = new \SplFixedArray($statement->rowCount());
     $statement->setFetchMode(\PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $game = new Game($row["gameId"], $row["gameFirstTeamId"], $row["gameSecondTeamId"], $row["gameTime"]);
             $games[$games->key()] = $game;
             $games->next();
         } catch (\Exception $exception) {
             // if the row couldn't be converted rethrow it
             throw new \PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $games;
 }
Esempio n. 11
0
 /**
  * gets all ProductLocations
  *
  * @param PDO $pdo pointer to PDO connection, by reference
  * @return SplFixedArray all productLocations found
  * @throws PDOException when mySQL related errors occur
  **/
 public static function getAllProductLocations(PDO &$pdo)
 {
     // create query template
     $query = "SELECT locationId, productId, unitId, quantity FROM productLocation";
     $statement = $pdo->prepare($query);
     $statement->execute();
     // build an array of ProductLocation(s)
     $productLocations = new SplFixedArray($statement->rowCount());
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $productLocation = new ProductLocation($row["locationId"], $row["productId"], $row["unitId"], $row["quantity"]);
             $productLocations[$productLocations->key()] = $productLocation;
             $productLocations->next();
         } catch (PDOException $exception) {
             // if the row couldn't be converted, rethrow it
             throw new PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $productLocations;
 }
Esempio n. 12
0
 public static function getAllProfiles(\PDO $pdo)
 {
     // Create query template and execute
     $query = "SELECT profileId, profileAdmin, profileNameFirst, profileNameLast, profileEmail, profileUserName, profileSalt, profileHash, profileActivationToken FROM profile";
     $statement = $pdo->prepare($query);
     $statement->execute();
     // Build an array of matches
     $profiles = new \SplFixedArray($statement->rowCount());
     $statement->setFetchMode(\PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $profile = new Profile($row["profileId"], $row["profileAdmin"], $row["profileNameFirst"], $row["profileNameLast"], $row["profileEmail"], $row["profileUserName"], $row["profileSalt"], $row["profileHash"], $row["profileActivationToken"]);
             $profiles[$profiles->key()] = $profile;
             $profiles->next();
         } catch (\Exception $exception) {
             throw new \PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $profiles;
 }
Esempio n. 13
0
 /**
  * gets the Follower relationship by the person being followed
  *
  * @param \PDO $pdo PDO connection object
  * @param int $followerFollowedId the person being followed
  * @return \SplFixedArray SplFixedArray of Follower relationships found or null if not found
  * @throws \PDOException when mySQL related errors occur
  * @throws \TypeError when variables are not the correct data type
  **/
 public static function getFollowerByFollowedId(\PDO $pdo, int $followerFollowedId)
 {
     //Sanitize the followed id
     if ($followerFollowedId <= 0) {
         throw new \PDOException("Get Follower by Followed: Followed Id is not positive");
     }
     //Create a query template
     $query = "SELECT followerFollowerId, followerFollowedId FROM follower WHERE followerFollowedId = :followerFollowedId";
     $statement = $pdo->prepare($query);
     //Search based on the one being followed
     $parameters = ["followerFollowedId" => $followerFollowedId];
     $statement->execute($parameters);
     //Build an array of follower relationships
     $followers = new \SplFixedArray($statement->rowCount());
     $statement->setFetchMode(\PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $follower = new Follower($row["followerFollowerId"], $row["followerFollowedId"]);
             $followers[$followers->key()] = $follower;
             $followers->next();
         } catch (\Exception $exception) {
             //If the row couldn't be converted, rethrow it
             throw new \PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $followers;
 }
Esempio n. 14
0
 /**
  * gets the list of this profiles favorite teams
  *
  * @param \PDO $pdo connection object
  * @param int $allFavoriteTeams search for
  * @return \SplFixedArray SplFixedArray of all teams favorited found
  * @throws \PDOException when db related errors occur
  * @throws \TypeError when variables are not correct data type
  **/
 public static function getFavoriteTeamsByFavoriteTeamProfileId(\PDO $pdo, int $favoriteTeamProfileId)
 {
     // sanitize the favoriteTeamProfileId
     if ($favoriteTeamProfileId <= 0) {
         throw new \PDOException("that profile doesnt exist");
     }
     // create a query template
     $query = "SELECT favoriteTeamProfileId, favoriteTeamTeamId FROM favoriteTeam WHERE favoriteTeamProfileId = :favoriteTeamProfileId";
     $statement = $pdo->prepare($query);
     // bind the favoriteTeamTeamId to the place holder in the template
     $parameters = ["favoriteTeamProfileId" => $favoriteTeamProfileId];
     $statement->execute($parameters);
     // build an array of favorite teams
     $favoriteTeams = new \SplFixedArray($statement->rowCount());
     $statement->setFetchMode(\PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $favoriteTeam = new FavoriteTeam($row["favoriteTeamProfileId"], $row["favoriteTeamTeamId"]);
             $favoriteTeams[$favoriteTeams->key()] = $favoriteTeam;
             $favoriteTeams->next();
         } catch (\Exception $exception) {
             // if the row can't be converted, rethrow it
             throw new \PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $favoriteTeams;
 }
Esempio n. 15
0
 /**
  *
  */
 public function next()
 {
     $this->set->next();
 }
Esempio n. 16
0
 /**
  * retrieves all listingtypes
  *
  * @param PDO $pdo pdo connection object
  * @return SplFixedArray all organizations
  * @throws PDOException if mySQL errors occur
  */
 public static function getAllListingTypes(PDO $pdo)
 {
     //create query template and execute
     $query = "SELECT listingTypeId, listingType FROM listingType";
     $statement = $pdo->prepare($query);
     $statement->execute();
     //build an array of the retrieved results
     //set the size of the object to the number of retrieved rows
     $retrievedTypes = new SplFixedArray($statement->rowCount());
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     //while rows can still be retrieved from the result
     while (($row = $statement->fetch()) !== false) {
         try {
             $listingType = new ListingType($row["listingTypeId"], $row["listingType"]);
             //place result in the current field, then advance the key
             $retrievedTypes[$retrievedTypes->key()] = $listingType;
             $retrievedTypes->next();
         } catch (Exception $exception) {
             //rethrow the exception if retrieval failed
             throw new PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $retrievedTypes;
 }
Esempio n. 17
0
 public static function getTrailByTrailUuid(PDO &$pdo, $trailUuid)
 {
     //sanitize the trailUuid before searching
     try {
         $trailUuid = Filter::filterString($trailUuid, "trailUuid");
     } catch (InvalidArgumentException $invalidArgument) {
         throw new PDOException($invalidArgument->getMessage(), 0, $invalidArgument);
     } catch (RangeException $range) {
         throw new PDOException($range->getMessage(), 0, $range);
     } catch (Exception $exception) {
         throw new PDOException($exception->getMessage(), 0, $exception);
     }
     //create query template
     $query = "SELECT trailId, userId, browser, createDate, ipAddress, submitTrailId, trailAmenities, trailCondition,trailDescription, trailDifficulty, trailDistance, trailName, trailSubmissionType,\ntrailTerrain, trailTraffic, trailUse, trailUuid FROM trail WHERE trailUuid = :trailUuid";
     $statement = $pdo->prepare($query);
     //bind trailUuid to placeholder
     $parameters = array("trailUuid" => $trailUuid);
     $statement->execute($parameters);
     //build an array of trails
     $trails = new SplFixedArray($statement->rowCount());
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             //new trail ($trailId, $userId, $submitTrailId, $browser, $createDate, $ipAddress, $trailAccessibility, $trailAmenities, $trailCondition,$trailDescription, $trailDifficulty, $trailDistance, $trailSubmissionType,$trailTerrain, $trailName, $trailTraffic, $trailUse, $trailUuId)
             $trail = new Trail($row["trailId"], $row["userId"], $row["browser"], $row["createDate"], $row["ipAddress"], $row["submitTrailId"], $row["trailAmenities"], $row["trailCondition"], $row["trailDescription"], $row["trailDifficulty"], $row["trailDistance"], $row["trailName"], $row["trailSubmissionType"], $row["trailTerrain"], $row["trailTraffic"], $row["trailUse"], $row["trailUuid"]);
             $trails[$trails->key()] = $trail;
             $trails->next();
         } catch (Exception $e) {
             //if the row couldn't be converted, rethrow it
             throw new PDOException($e->getMessage(), 0, $e);
         }
     }
     return $trails;
 }
Esempio n. 18
0
 /**
  * gets all Statistic
  *
  * @param \PDO $pdo PDO connection object
  * @return \SplFixedArray SplFixedArray of Statistic found or null if not found
  * @throws \PDOException when mySQL related errors occur
  * @throws \TypeError when variables are not the correct data type
  **/
 public static function getAllStatistic(\PDO $pdo)
 {
     // create query template
     $query = "SELECT statisticId, statisticName FROM statistic";
     $statement = $pdo->prepare($query);
     $statement->execute();
     //build array of statistic
     $statistics = new \SplFixedArray($statement->rowCount());
     $statement->setFetchMode(\PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $statistic = new Statistic($row["statisticId"], $row["statisticName"]);
             $statistics[$statistics->key()] = $statistic;
             $statistics->next();
         } catch (\Exception $exception) {
             //if the row couldn't be converted rethrow it
             throw new \PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $statistics;
 }
Esempio n. 19
0
 public function next()
 {
     echo "A::next\n";
     return parent::next();
 }
Esempio n. 20
0
 /**
  * gets all passwordResets
  *
  * @param \PDO $pdo PDO connection object
  * @return \SplFixedArray SplFixedArray of PasswordResets found or null if not found
  * @throws \PDOException when mySQL related errors occur
  * @throws \TypeError when variables are not the correct data type
  **/
 public static function getAllPasswordResets(\PDO $pdo)
 {
     // create query template
     $query = "SELECT passwordResetId, passwordResetProfileId, passwordResetProfileEmail, passwordResetToken, passwordResetTime FROM passwordReset";
     $statement = $pdo->prepare($query);
     $statement->execute();
     // build an array of passwordResets
     $passwordResets = new \SplFixedArray($statement->rowCount());
     $statement->setFetchMode(\PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $passwordReset = new PasswordReset($row["passwordResetId"], $row["passwordResetProfileId"], $row["passwordResetProfileEmail"], $row["passwordResetToken"], \DateTime::createFromFormat("Y-m-d H:i:s", $row["passwordResetTime"]));
             $passwordResets[$passwordResets->key()] = $passwordReset;
             $passwordResets->next();
         } catch (\Exception $exception) {
             // if the row couldn't be converted, rethrow it
             throw new \PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $passwordResets;
 }
Esempio n. 21
0
 /**
  * gets segment by segmentStopElevation
  *
  * @param PDO $pdo pointer to PDO connection
  * @param int $segmentStopElevation stop elevation to trail-search for
  * @return mixed segment found or null if not found
  * @throws PDOException when mySQL related errors occur
  * @throws RangeException when range is invalid
  * @throws Exception for other exception
  */
 public static function getSegmentBySegmentStopElevation(PDO &$pdo, $segmentStopElevation)
 {
     //sanitize the int before searching
     try {
         $segmentStopElevation = Filter::filterInt($segmentStopElevation, "segment stop", false);
     } catch (InvalidArgumentException $invalidArgument) {
         throw new PDOException($invalidArgument->getMessage(), 0, $invalidArgument);
     } catch (RangeException $range) {
         throw new RangeException($range->getMessage(), 0, $range);
     } catch (Exception $exception) {
         throw new Exception($exception->getMessage(), 0, $exception);
     }
     //create query template
     $query = "SELECT segmentId, ST_AsWKT(segmentStop) AS segmentStop, ST_AsWKT(segmentStart) AS segmentStart, segmentStartElevation, segmentStopElevation FROM segment WHERE segmentStopElevation = :segmentStopElevation";
     $statement = $pdo->prepare($query);
     //binds segmentStopElevation to placeholder
     $parameters = array("segmentStopElevation" => $segmentStopElevation);
     $statement->execute($parameters);
     //build an array of segments
     $segments = new SplFixedArray($statement->rowCount());
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $segmentStartJSON = Gisconverter::wktToGeojson($row["segmentStart"]);
             $segmentStopJSON = Gisconverter::wktToGeojson($row["segmentStop"]);
             $segmentStartGenericObject = json_decode($segmentStartJSON);
             $segmentStopGenericObject = json_decode($segmentStopJSON);
             $segmentStart = new Point($segmentStartGenericObject->coordinates[0], $segmentStartGenericObject->coordinates[1]);
             $segmentStop = new Point($segmentStopGenericObject->coordinates[0], $segmentStopGenericObject->coordinates[1]);
             $segment = new Segment($row["segmentId"], $segmentStart, $segmentStop, $row["segmentStartElevation"], $row["segmentStopElevation"]);
             $segments[$segments->key()] = $segment;
             $segments->next();
         } catch (Exception $e) {
             //if the row couldn't be converter, rethrow it
             throw new PDOException($e->getMessage(), 0, $e);
         }
     }
     return $segments;
 }
Esempio n. 22
0
 /**
  *
  * Decodes geoJson file, converts to string, sifts through the string and inserts the data into the database
  *
  * @param string $url
  * @throws PDOException PDO related errors
  * @throws Exception catch-all exception
  **/
 public static function readTrailSegmentsGeoJson($url)
 {
     $context = stream_context_create(array("http" => array("ignore_errors" => true, "method" => "GET")));
     try {
         $pdo = connectToEncryptedMySQL("/var/www/trailquail/encrypted-mysql/trailquail.ini");
         if (($jsonData = file_get_contents($url, null, $context)) !== false) {
             if (($jsonFd = @fopen("php://memory", "wb+")) === false) {
                 throw new RuntimeException("Memory Error: I can't remember");
             }
             //decode the geoJson file
             $jsonConverted = json_decode($jsonData);
             $jsonFeatures = $jsonConverted->features;
             // create array from converted geoJson file
             $properties = new SplFixedArray(count($jsonFeatures));
             //loop through array to get to json properties
             foreach ($jsonFeatures as $jsonFeature) {
                 $properties[$properties->key()] = $jsonFeature->properties;
                 $properties->next();
             }
             //create an array of trails and a SplObjectStorage for the trail guide
             $trails = [];
             $trailGuide = new SplObjectStorage();
             //loop through array to get trail name and trail use
             foreach ($properties as $property) {
                 $trailName = $property->name;
                 $trailUse = "";
                 //set $trailUse string based on information in geoJson properties field.
                 if ($property->bicycle === "yes") {
                     $trailUse = $trailUse . "bicycle: yes, ";
                 } else {
                     $trailUse = $trailUse . "bicycle: no, ";
                 }
                 if ($property->foot === "yes") {
                     $trailUse = $trailUse . "foot: yes, ";
                 } else {
                     $trailUse = $trailUse . "foot: no, ";
                 }
                 if ($property->wheelchair === "yes") {
                     $trailUse = $trailUse . "wheelchair: yes ";
                 } else {
                     $trailUse = $trailUse . "wheelchair: no ";
                 }
                 //get the trail by name and set the trail use
                 try {
                     $candidateTrails = Trail::getTrailByTrailName($pdo, $trailName);
                     foreach ($candidateTrails as $trail) {
                         $trail->setTrailUse($trailUse);
                         $trail->update($pdo);
                         $trails[] = $trail;
                     }
                 } catch (PDOException $pdoException) {
                     $sqlStateCode = "23000";
                     $errorInfo = $pdoException->errorInfo;
                     if ($errorInfo[0] === $sqlStateCode) {
                     } else {
                         throw new PDOException($pdoException->getMessage(), 0, $pdoException);
                     }
                 } catch (Exception $exception) {
                     throw new Exception($exception->getMessage(), 0, $exception);
                 }
             }
             try {
                 $trailIndex = 0;
                 foreach ($jsonFeatures as $jsonFeature) {
                     $jsonCoordinates = $jsonFeature->geometry->coordinates;
                     if ($jsonFeature->geometry->type === "LineString") {
                         $coordinates = new SplFixedArray(count($jsonCoordinates));
                         foreach ($jsonCoordinates as $coordinate) {
                             $coordinates[$coordinates->key()] = $coordinate;
                             $coordinates->next();
                         }
                         $trailGuide[$trails[$trailIndex]] = $coordinates;
                         $trailIndex++;
                     } else {
                         if ($jsonFeature->geometry->type === "MultiLineString") {
                             $trailClones = [];
                             $trails[$trailIndex]->delete($pdo);
                             for ($i = 1; $i <= count($jsonCoordinates); $i++) {
                                 $trail = clone $trails[$trailIndex];
                                 $trail->setTrailId(null);
                                 $trail->setTrailName($trail->getTrailName() . " {$i}");
                                 $trail->insert($pdo);
                                 $trailClones[] = $trail;
                             }
                             array_splice($trails, $trailIndex, 1, $trailClones);
                             foreach ($jsonCoordinates as $lineCoordinates) {
                                 $trailGuide[$trails[$trailIndex]] = $lineCoordinates;
                                 $trailIndex++;
                             }
                         }
                     }
                 }
                 $trailGuide->rewind();
                 foreach ($trailGuide as $map) {
                     $trail = $trailGuide->current();
                     $geo = $trailGuide->getInfo();
                     for ($indexTwo = 0; $indexTwo < count($geo) - 1; $indexTwo++) {
                         $segmentStartX = $geo[$indexTwo][0];
                         $segmentStartY = $geo[$indexTwo][1];
                         //							$segmentStartElevation = $geo[$indexTwo][2];
                         $segmentStopX = $geo[$indexTwo + 1][0];
                         $segmentStopY = $geo[$indexTwo + 1][1];
                         //							$segmentStopElevation = $geo[$indexTwo + 1][2];
                         $segmentStart = new Point($segmentStartX, $segmentStartY);
                         $segmentStop = new Point($segmentStopX, $segmentStopY);
                         try {
                             $segment = new Segment(null, $segmentStart, $segmentStop, 0, 0);
                             $segment->insert($pdo);
                             $relationship = new TrailRelationship($segment->getSegmentId(), $trail->getTrailId(), "T");
                             $relationship->insert($pdo);
                         } catch (PDOException $pdoException) {
                             $sqlStateCode = "23000";
                             $errorInfo = $pdoException->errorInfo;
                             if ($errorInfo[0] === $sqlStateCode) {
                             } else {
                                 throw new PDOException($pdoException->getMessage(), 0, $pdoException);
                             }
                         } catch (Exception $exception) {
                             throw new Exception($exception->getMessage(), 0, $exception);
                         }
                     }
                 }
             } catch (PDOException $pdoException) {
                 $sqlStateCode = "23000";
                 $errorInfo = $pdoException->errorInfo;
                 if ($errorInfo[0] === $sqlStateCode) {
                 } else {
                     throw new PDOException($pdoException->getMessage(), 0, $pdoException);
                 }
             } catch (Exception $exception) {
                 throw new Exception($exception->getMessage(), 0, $exception);
             }
         }
         fclose($jsonFd);
     } catch (PDOException $pdoException) {
         throw new PDOException($pdoException->getMessage(), 0, $pdoException);
     } catch (Exception $exception) {
         throw new Exception($exception->getMessage(), 0, $exception);
     }
 }
Esempio n. 23
0
 /**
  * getAllImages
  *
  * @param \PDO $pdo PDO connection object
  * @return \SplFixedArray SplFixedArray of images found or null if not found
  * @throws \PDOException when mySQL related errors occur
  * @throws \TypeError when variables are not the correct data type
  **/
 public static function getAllImages(\PDO $pdo)
 {
     // create query template
     $query = "SELECT imageId, imageProfileId, imageFileName, imageType FROM image";
     $statement = $pdo->prepare($query);
     $statement->execute();
     // build an array of images
     $images = new \SplFixedArray($statement->rowCount());
     $statement->setFetchMode(\PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $image = new Image($row["imageId"], $row["imageProfileId"], $row["imageFileName"], $row["imageType"]);
             $images[$images->key()] = $image;
             $images->next();
         } catch (\Exception $exception) {
             // if the row couldn't be converted, rethrow it
             throw new \PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $images;
 }
Esempio n. 24
0
 /**
  * gets all FinishedProduct(s)
  *
  * @param PDO $pdo pointer to PDO connection, by reference
  * @return SplFixedArray all FinishedProducts found
  * @throws PDOException when mySQL related errors occur
  **/
 public static function getAllFinishedProducts(PDO &$pdo)
 {
     // create query template
     $query = "SELECT finishedProductId, rawMaterialId, rawQuantity FROM finishedProduct";
     $statement = $pdo->prepare($query);
     $statement->execute();
     // build an array of FinishedProduct(s)
     $finishedProducts = new SplFixedArray($statement->rowCount());
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $finishedProduct = new FinishedProduct($row["finishedProductId"], $row["rawMaterialId"], $row["rawQuantity"]);
             $finishedProducts[$finishedProducts->key()] = $finishedProduct;
             $finishedProducts->next();
         } catch (PDOException $exception) {
             // if the row couldn't be converted, rethrow it
             throw new PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $finishedProducts;
 }
Esempio n. 25
0
 /**
  * gets all ratings
  *
  * @param PDO $pdo PDO connection object
  * @return SplFixedArray all ratings found
  * @throws PDOException when mySQL errors occur
  */
 public static function getAllRatings(PDO $pdo)
 {
     //create query template
     $query = "select trailId, userId, rating FROM rating";
     $statement = $pdo->prepare($query);
     $statement->execute();
     // build an array of rating values
     $ratings = new SplFixedArray($statement->rowCount());
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $rating = new Rating($row["userId"], $row["trailId"], $row["ratingValue"]);
             $ratings[$ratings->key()] = $rating;
             $ratings->next();
         } catch (Exception $exception) {
             // if the row couldn't be converted rethrow it
             throw new PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $ratings;
 }
Esempio n. 26
0
 /**
  * gets all Schedules
  *
  * @param \PDO $pdo PDO connection object
  * @return \SplFixedArray SplFixedArray of Schedules found or null if not found
  * @throws \PDOException when mySQL related errors occur
  * @throws \TypeError when variables are not the correct data type
  **/
 public static function getAllSchedules(\PDO $pdo)
 {
     // create query template
     $query = "SELECT scheduleId, scheduleCrewId, scheduleStartDate\n\t\t\t\t\t FROM schedule\n\t\t\t\t\t WHERE schedule.scheduleCrewId\n\t\t\t\t\t IN (SELECT crewId FROM crew WHERE crewCompanyId = :companyId)";
     $statement = $pdo->prepare($query);
     $parameters = ["companyId" => self::injectCompanyId()];
     $statement->execute($parameters);
     // build an array of schedules
     $schedules = new \SplFixedArray($statement->rowCount());
     $statement->setFetchMode(\PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $schedule = new Schedule($row["scheduleId"], $row["scheduleCrewId"], $row["scheduleStartDate"]);
             $schedules[$schedules->key()] = $schedule;
             $schedules->next();
         } catch (\Exception $exception) {
             // if the row couldn't be converted, rethrow it
             throw new \PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $schedules;
 }
Esempio n. 27
0
 /**
  * function to store multiple database results into an SplFixedArray
  *
  * @param PDOStatement $statement pdo statement object
  * @return SPLFixedArray all message obtained from database
  * @throws PDOException if mySQL related errors occur
  */
 public static function storeSQLResultsInArray(PDOStatement $statement)
 {
     //build an array of messages, as an SPLFixedArray object
     //set the size of the object to the number of retrieved rows
     $retrievedMessages = new SplFixedArray($statement->rowCount());
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     //while rows can still be retrieved from the result
     while (($row = $statement->fetch()) !== false) {
         try {
             $message = new Message($row["messageId"], $row["listingId"], $row["orgId"], $row["messageText"]);
             //place result in the current field, then advance the key
             $retrievedMessages[$retrievedMessages->key()] = $message;
             $retrievedMessages->next();
         } catch (Exception $exception) {
             //rethrow the exception if retrieval failed
             throw new PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $retrievedMessages;
 }
Esempio n. 28
0
 /**
  * gets the RamChip by product name
  *
  * @param PDO $pdo PDO connection object
  * @param string $productName product name to search for
  * @return SplFixedArray all RamChipS found for this name
  * @throws PDOException when mySQL related errors occur
  **/
 public static function getRamChipByProductName(\PDO $pdo, string $productName)
 {
     // sanitize the description before searching
     $productName = trim($productName);
     $productName = filter_var($productName, FILTER_SANITIZE_STRING);
     if (empty($productName) === true) {
         throw new \PDOException("product name is invalid");
     }
     // create query template
     $query = "SELECT productId, productName, manufacturerName, modelName, price FROM ramChip WHERE productName LIKE :productName";
     $statement = $pdo->prepare($query);
     // bind the product name to the place holder in the template
     $productName = "%{$productName}%";
     $parameters = array("productName" => $productName);
     $statement->execute($parameters);
     // build an array of  ram chips
     $ramChips = new \SplFixedArray($statement->rowCount());
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $ramChip = new RamChip($row["productId"], $row["productName"], $row["manufacturerName"], $row["modelName"], $row["price"]);
             $ramChips[$ramChips->key()] = $ramChip;
             $ramChips->next();
         } catch (Exception $exception) {
             // if the row couldn't be converted, rethrow it
             throw new PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $ramChips;
 }
Esempio n. 29
0
 /**
  * gets a Trail Relationship by trailId
  *
  * @param PDO $pdo PDO connection object
  * @param int $trailId trail id to trail-search for
  * @return mixed Trail Relationship found or null if not found
  * @throws PDOException when mySQL related errors occur
  **/
 public static function getTrailRelationshipByTrailId(PDO $pdo, $trailId)
 {
     // sanitize the trailId before searching
     $trailId = filter_var($trailId, FILTER_VALIDATE_INT);
     if ($trailId === false) {
         throw new PDOException("trailId is not an integer");
     }
     if ($trailId <= 0) {
         throw new PDOException("trailId is not positive");
     }
     //create query template
     $query = "SELECT segmentId, trailId, segmentType FROM trailRelationship WHERE trailId = :trailId";
     $statement = $pdo->prepare($query);
     //bind the trailId to the placeholder in the template
     $parameters = array("trailId" => $trailId);
     $statement->execute($parameters);
     // build an array of Trail Relationships
     $trailRelationships = new SplFixedArray($statement->rowCount());
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $trailRelationship = new TrailRelationship($row["segmentId"], $row["trailId"], $row["segmentType"]);
             $trailRelationships[$trailRelationships->key()] = $trailRelationship;
             $trailRelationships->next();
         } catch (Exception $e) {
             //if the row couldn't be converted, rethrow it
             throw new PDOException($e->getMessage(), 0, $e);
         }
     }
     //		// grab the Trail Relationship from mySQL
     //		try {
     //			$trailRelationship = null;
     //			$statement->setFetchMode(PDO::FETCH_ASSOC);
     //			$row = $statement->fetch();
     //			if($row !== false) {
     //				$trailRelationship = new TrailRelationship($row["segmentId"], $row["trailId"], $row["segmentType"]);
     //			}
     //		} catch(Exception $exception) {
     //			// if the row couldn't be converted, rethrow it
     //			throw(new PDOException($exception->getMessage(), 0, $exception));
     //		}
     return $trailRelationships;
 }
Esempio n. 30
0
 /**
  *  Get all Locations
  * @param PDO $pdo pointer to PDO connection, by reference
  * @return mixed|location
  **/
 public static function getAllLocations(PDO &$pdo)
 {
     // create query template
     $query = "SELECT locationId, storageCode, description FROM location";
     $statement = $pdo->prepare($query);
     $statement->execute();
     // build an array of movements
     $locations = new SplFixedArray($statement->rowCount());
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $location = new Location($row["locationId"], $row["storageCode"], $row["description"]);
             $locations[$locations->key()] = $location;
             $locations->next();
         } catch (Exception $exception) {
             // if the row couldn't be converted, rethrow it
             throw new PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $locations;
 }