Example #1
0
 /**
  * Do an update or edit of reading history information.  Current actions are:
  * deleteMarked
  * deleteAll
  * exportList
  * optOut
  * optIn
  *
  * @param   array   $patron         The patron array
  * @param   string  $action         The action to perform
  * @param   array   $selectedTitles The titles to do the action on if applicable
  */
 function doReadingHistoryAction($patron, $action, $selectedTitles)
 {
     require_once ROOT_DIR . '/sys/ReadingHistoryEntry.php';
     global $user;
     //Reading History Information is stored in the VuFind database
     if ($action == 'deleteMarked') {
         //Remove selected titles from the database
         foreach ($selectedTitles as $selectedId => $selectValue) {
             //Get the resourceid for the bib
             $resource = new Resource();
             $resource->source = 'VuFind';
             if (is_numeric($selectValue)) {
                 $resource->record_id = $selectValue;
             } else {
                 $resource->record_id = $selectedId;
             }
             $resource->find();
             if ($resource->N) {
                 $resource->fetch();
                 $resourceId = $resource->id;
                 $readingHistory = new ReadingHistoryEntry();
                 $readingHistory->userId = $user->id;
                 $readingHistory->resourceId = $resourceId;
                 $readingHistory->delete();
             }
         }
     } elseif ($action == 'deleteAll') {
         //remove all titles from the database
         $readingHistory = new ReadingHistoryEntry();
         $readingHistory->userId = $user->id;
         $readingHistory->delete();
     } elseif ($action == 'exportList') {
         //Export the list (not currently implemented)
     } elseif ($action == 'optOut') {
         //remove all titles from the database
         $readingHistory = new ReadingHistoryEntry();
         $readingHistory->userId = $user->id;
         $readingHistory->delete();
         //Stop recording reading history and remove all titles from the database
         $user->trackReadingHistory = 0;
         $user->update();
         UserAccount::updateSession($user);
     } elseif ($action == 'optIn') {
         //Start recording reading history
         $user->trackReadingHistory = 1;
         $user->update();
         UserAccount::updateSession($user);
     }
 }
 public function returnRecordInReadingHistory($eContentRecord, $user)
 {
     //Get the resource for the record
     $resource = new Resource();
     $resource->record_id = $eContentRecord->id;
     $resource->source = 'eContent';
     if ($resource->find(true)) {
         //Check to see if there is an existing entry
         require_once ROOT_DIR . '/sys/ReadingHistoryEntry.php';
         $readingHistoryEntry = new ReadingHistoryEntry();
         $readingHistoryEntry->userId = $user->id;
         $readingHistoryEntry->resourceId = $resource->id;
         if ($readingHistoryEntry->find(true)) {
             $readingHistoryEntry->lastCheckoutDate = date('Y-m-d');
             $ret = $readingHistoryEntry->update();
         }
     }
 }
 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);
             }
         }
     }
 }