Exemplo n.º 1
0
 public function getByOwner($ownerID)
 {
     $DBH = utility::connectToDB();
     if ($DBH == \NULL) {
         return \NULL;
     }
     $sql = "\n\t\t\t\t  SELECT \n\t\t\t\t\t     * \n\t\t\t\t  FROM \n\t\t\t\t      items\n\t\t\t\t  WHERE \n\t\t\t\t\t  owner = :id\n\t\t\t\t  ";
     try {
         $STH = $DBH->prepare($sql);
         $STH->bindParam(':id', $ownerID);
         if ($STH->execute()) {
             $results = $STH->fetchAll();
         } else {
             echo 'Error: retreaving data\\n';
             print_r($DBH->errorInfo());
             print_r($STH->errorInfo());
             return \NULL;
         }
         $count = $STH->rowCount();
     } catch (PDOException $e) {
         echo 'Error: ' . $e->getMessage();
         $DBH = \NULL;
         return \NULL;
     }
     $DBH = \NULL;
     return Items::newCollection($results, $count);
 }
Exemplo n.º 2
0
 private function logEvent($eventCatagory, $loanID, $itemID)
 {
     $timeNow = date('Y-m-d H:i:s');
     $DBH = utility::connectToDB();
     if ($DBH == \NULL) {
         echo "Error connecting to database";
         exit;
     }
     $sql = "\n\t\t\t\tINSERT INTO eventLog \n\t\t\t\t\t   ( \n\t\t\t\t\t\t  FK_ITEM_ID,\n\t\t\t\t\t\t  FK_LOAN_ID,\n\t\t\t\t\t\t  event,\n\t\t\t\t\t\t  eventDate\n\t\t\t\t\t   )\n\t\t\t\t    VALUES\n\t\t\t\t\t   (\n\t\t\t\t\t\t  :id,\n\t\t\t\t\t\t  :loanID,\n\t\t\t\t\t\t  :event,\n\t\t\t\t\t\t  :eventDate\n\t\t\t\t\t   )\n\t\t\t\t";
     try {
         $STH = $DBH->prepare($sql);
         $STH->bindParam(':id', $itemID);
         $STH->bindParam(':loanID', $loanID);
         $STH->bindParam(':event', $eventCatagory);
         $STH->bindParam(':eventDate', $timeNow);
         $DBH->beginTransaction();
         $sqlError = $STH->execute();
         if (!$sqlError) {
             echo 'Error: updating event log data';
             print_r($DBH->errorInfo());
             echo "<p>";
             print_r($STH->errorInfo());
             exit;
         }
         $DBH->commit();
     } catch (PDOException $e) {
         echo 'Error: ' . $e->getMessage();
         $DBH = \NULL;
         return \FALSE;
     }
     $DBH = \NULL;
     return \TRUE;
 }
Exemplo n.º 3
0
 public function getHistory()
 {
     $DBH = utility::connectToDB();
     if ($DBH == \NULL) {
         echo "Error connecting to database";
         exit;
     }
     $sql = "\n\t\t\t\tSELECT \n\t\t\t\t\t   * \n\t\t\t\tFROM \n\t\t\t\t    eventLog\n\t\t\t\tWHERE \n\t\t\t\t\tFK_ITEM_ID = :id\n\t\t\t\t";
     try {
         $STH = $DBH->prepare($sql);
         $STH->bindParam(':id', $this->id);
         if ($STH->execute()) {
             $results = $STH->fetchAll();
         } else {
             echo 'Error: retreaving data\\n';
             print_r($DBH->errorInfo());
             print_r($STH->errorInfo());
         }
     } catch (PDOException $e) {
         echo 'Error: ' . $e->getMessage();
         $DBH = \NULL;
         return \NULL;
     }
     $DBH = \NULL;
     return $results;
 }