예제 #1
0
 /**
  * gets the Movement by movementDate
  *
  * @param PDO $pdo pointer to PDO connection, by reference
  * @param DateTime $newMovementDate the movementDate to search for
  * @return mixed Movement(s) found or null if not found
  * @throws PDOException when mySQL related errors occur
  **/
 public static function getMovementByMovementDate(PDO &$pdo, $newMovementDate)
 {
     // sanitize the movementDate before searching
     try {
         $newMovementDate = validateDate::validateDate($newMovementDate);
     } catch (InvalidArgumentException $invalidArgument) {
         throw new InvalidArgumentException($invalidArgument->getMessage(), 0, $invalidArgument);
     } catch (RangeException $range) {
         throw new RangeException($range->getMessage(), 0, $range);
     }
     $sunrise = $newMovementDate->format("Y-m-d") . " 00:00:00";
     $sunset = $newMovementDate->format("Y-m-d") . " 23:59:59";
     // create query template
     $query = "SELECT movementId, fromLocationId, toLocationId, productId, unitId, userId, cost, movementDate, movementType, price FROM movement WHERE movementDate >= :sunrise AND movementDate <= :sunset";
     $statement = $pdo->prepare($query);
     // bind the movementDate to the place holder in the template
     $parameters = array("sunrise" => $sunrise, "sunset" => $sunset);
     $statement->execute($parameters);
     // build an array of movements
     $movements = new SplFixedArray($statement->rowCount());
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $movement = new Movement($row["movementId"], $row["fromLocationId"], $row["toLocationId"], $row["productId"], $row["unitId"], $row["userId"], $row["cost"], $row["movementDate"], $row["movementType"], $row["price"]);
             $movements[$movements->key()] = $movement;
             $movements->next();
         } catch (Exception $exception) {
             // if the row couldn't be converted, rethrow it
             throw new PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $movements;
 }
예제 #2
0
 /**
  * Mutator method for imageDate
  * @param \datetime $newImageDate string for newImageDate or null to load current time
  * @throws \InvalidArgumentException if $newImageDate is not a valid object or string
  * @throws \RangeException if $newImageDate is a date that does not exist
  **/
 public function setImageDate($newImageDate = null)
 {
     //If date is null, set current time and date
     if ($newImageDate === null) {
         $this->imageDate = new \DateTime();
         return;
     }
     //Catch exceptions and display correct error (refers to validate-date.php) and if no exceptions, safe the new time and date
     try {
         $newImageDate = validateDate::validateDate($newImageDate);
     } catch (\InvalidArgumentException $invalidArgument) {
         throw new \InvalidArgumentException($invalidArgument->getMessage(), 0, $invalidArgument);
     } catch (\RangeException $range) {
         throw new \RangeException($range->getMessage(), 0, $range);
     } catch (\Exception $exception) {
         throw new \Exception($exception->getMessage(), 0, $exception);
     }
     $this->imageDate = $newImageDate;
 }
예제 #3
0
 /**
  * gets the Notification by notification Date Time
  *
  * @param PDO $pdo pointer to PDO connection, by reference
  * @param DateTime $newNotificationDateTime the notification date to search for
  * @return mixed notification(s) found or null if not found
  * @throws PDOException when mySQL related errors occur
  **/
 public static function getNotificationByNotificationDateTime(PDO &$pdo, $newNotificationDateTime)
 {
     // sanitize the notificationDateTime before searching
     try {
         $newNotificationDateTime = validateDate::validateDate($newNotificationDateTime);
     } catch (InvalidArgumentException $invalidArgument) {
         throw new InvalidArgumentException($invalidArgument->getMessage(), 0, $invalidArgument);
     } catch (RangeException $range) {
         throw new RangeException($range->getMessage(), 0, $range);
     }
     $sunrise = $newNotificationDateTime->format("Y-m-d") . " 00:00:00";
     $sunset = $newNotificationDateTime->format("Y-m-d") . " 23:59:59";
     // create query template
     $query = "SELECT notificationId, alertId, emailStatus, notificationDateTime, notificationHandle, notificationContent FROM notification WHERE notificationDateTime >= :sunrise AND notificationDateTime <= :sunset";
     $statement = $pdo->prepare($query);
     // bind the email id to the place holder in the template
     $parameters = array("sunrise" => $sunrise, "sunset" => $sunset);
     $statement->execute($parameters);
     //build an array of movements
     $notifications = new SplFixedArray($statement->rowCount());
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     while (($row = $statement->fetch()) !== false) {
         try {
             $notification = new Notification($row["notificationId"], $row["alertId"], $row["emailStatus"], $row["notificationDateTime"], $row["notificationHandle"], $row["notificationContent"]);
             $notifications[$notifications->key()] = $notification;
             $notifications->next();
         } catch (Exception $exception) {
             // if the row could't be converted
             throw new PDOException($exception->getMessage(), 0, $exception);
         }
     }
     return $notifications;
 }