예제 #1
0
 private function updateReadingHistoryBasedOnCurrentCheckouts()
 {
     global $user;
     require_once ROOT_DIR . '/sys/ReadingHistoryEntry.php';
     //Note, include deleted titles here so they are not added multiple times.
     $readingHistoryDB = new ReadingHistoryEntry();
     $readingHistoryDB->userId = $user->id;
     $readingHistoryDB->whereAdd('checkInDate IS NULL');
     $readingHistoryDB->find();
     $activeHistoryTitles = array();
     while ($readingHistoryDB->fetch()) {
         $historyEntry = $this->getHistoryEntryForDatabaseEntry($readingHistoryDB);
         $key = $historyEntry['source'] . ':' . $historyEntry['id'];
         $activeHistoryTitles[$key] = $historyEntry;
     }
     //Update reading history based on current checkouts.  That way it never looks out of date
     require_once ROOT_DIR . '/services/API/UserAPI.php';
     $userAPI = new UserAPI();
     $checkouts = $userAPI->getPatronCheckedOutItems();
     foreach ($checkouts['checkedOutItems'] as $checkout) {
         $sourceId = '?';
         $source = $checkout['checkoutSource'];
         if ($source == 'OverDrive') {
             $sourceId = $checkout['overDriveId'];
         } elseif ($source == 'ILS') {
             $sourceId = $checkout['id'];
         } elseif ($source == 'eContent') {
             $source = $checkout['recordType'];
             $sourceId = $checkout['id'];
         }
         $key = $source . ':' . $sourceId;
         if (array_key_exists($key, $activeHistoryTitles)) {
             unset($activeHistoryTitles[$key]);
         } else {
             $historyEntryDB = new ReadingHistoryEntry();
             $historyEntryDB->userId = $user->id;
             if (isset($checkout['groupedWorkId'])) {
                 $historyEntryDB->groupedWorkPermanentId = $checkout['groupedWorkId'] == null ? '' : $checkout['groupedWorkId'];
             } else {
                 $historyEntryDB->groupedWorkPermanentId = "";
             }
             $historyEntryDB->source = $source;
             $historyEntryDB->sourceId = $sourceId;
             $historyEntryDB->title = substr($checkout['title'], 0, 150);
             $historyEntryDB->author = substr($checkout['author'], 0, 75);
             $historyEntryDB->format = substr($checkout['format'], 0, 50);
             $historyEntryDB->checkOutDate = time();
             if (!$historyEntryDB->insert()) {
                 global $logger;
                 $logger->log("Could not insert new reading history entry", PEAR_LOG_ERR);
             }
         }
     }
     //Anything that was still active is now checked in
     foreach ($activeHistoryTitles as $historyEntry) {
         //Update even if deleted to make sure code is cleaned up correctly
         $historyEntryDB = new ReadingHistoryEntry();
         $historyEntryDB->source = $historyEntry['source'];
         $historyEntryDB->sourceId = $historyEntry['id'];
         $historyEntryDB->checkInDate = null;
         if ($historyEntryDB->find(true)) {
             $historyEntryDB->checkInDate = time();
             $numUpdates = $historyEntryDB->update();
             if ($numUpdates != 1) {
                 global $logger;
                 $key = $historyEntry['source'] . ':' . $historyEntry['id'];
                 $logger->log("Could not update reading history entry {$key}", PEAR_LOG_ERR);
             }
         }
     }
 }
예제 #2
0
        // "No Content" status
    }
    private function deleteUser()
    {
        if ($this->get_request_method() != "DELETE") {
            $this->response('', 406);
        }
        $id = (int) $this->_request['id'];
        if ($id > 0) {
            $query = "DELETE FROM tblUsers WHERE userID = {$id}";
            $r = $this->mysqli->query($query) or die($this->mysqli->error . __LINE__);
            $success = array('status' => "Success", "msg" => "Successfully deleted one record.");
            $this->response($this->json($success), 200);
        } else {
            $this->response('', 204);
        }
        // If no records "No Content" status
    }
    /*
     *	Encode array into JSON
     */
    private function json($data)
    {
        if (is_array($data)) {
            return json_encode($data);
        }
    }
}
// Initiiate Library
$api = new UserAPI();
$api->processApi();
예제 #3
0
<?php

namespace Application\APIs;

require '..\\..\\autoload.php';
require '\\..\\..\\Libs\\vendor\\autoload.php';
\Slim\Slim::registerAutoloader();
$mainApp = new \Slim\Slim();
$mainApp->response()->header("Content-Type', 'application/json;charset=utf-8");
UserAPI::registerAPI($mainApp);
$mainApp->run();