/** * gets the listing by listing post time * * @param PDO $pdo pointer to PDO connection * @param int $listingPostTime listing post time to search for * @return mixed listing found or null if not found * @throws PDO Exceptions when my SQL related errors occur **/ public static function getListingByListingPostTime(PDO $pdo, $listingPostTime) { //sanitize the listingPostTime before searching try { //if we get an angular-style time value, filter it and convert it if (is_numeric($listingPostTime) === true) { filter_var($listingPostTime, FILTER_VALIDATE_INT); if ($listingPostTime === false) { throw new InvalidArgumentException("listing post time is not valid"); } $listingPostTime = Listing::ngToDateTime($listingPostTime); } $listingPostTime = Listing::validateDate($listingPostTime); } catch (InvalidArgumentException $invalidArgument) { throw new InvalidArgumentException($invalidArgument->getMessage(), 0, $invalidArgument); } catch (RangeException $range) { throw new RangeException($range->getMessage(), 0, $range); } $sunrise = $listingPostTime->format("Y-m-d") . " 00:00:00"; $sunset = $listingPostTime->format("Y-m-d") . " 23:59:59"; //create query template $query = "SELECT listingId,orgId,listingClaimedBy,listingClosed,listingCost,listingMemo,listingParentId,listingPostTime,listingTypeId FROM listing WHERE listingPostTime >= :sunrise AND listingPostTime <= :sunset"; $statement = $pdo->prepare($query); //bind the name value to the placeholder in the template $parameters = ["sunrise" => $sunrise, "sunset" => $sunset]; $statement->execute($parameters); //call the function to build an array of the retrieved results try { $retrievedListings = Listing::storeSQLResultsInArray($statement); } catch (Exception $exception) { //rethrow the exception if retrieval failed throw new PDOException($exception->getMessage(), 0, $exception); } return $retrievedListings; }