예제 #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);
     }
 }
예제 #2
0
 /**
  * Do an update or edit of reading history information.  Current actions are:
  * deleteMarked
  * deleteAll
  * exportList
  * optOut
  *
  * @param   string  $action         The action to perform
  * @param   array   $selectedTitles The titles to do the action on if applicable
  */
 function doReadingHistoryAction($action, $selectedTitles)
 {
     global $user;
     if ($user->trackReadingHistory && $user->initialReadingHistoryLoaded || !$this->driver->hasNativeReadingHistory()) {
         if ($action == 'deleteMarked') {
             //Remove titles from database (do not remove from ILS)
             foreach ($selectedTitles as $titleId) {
                 list($source, $sourceId) = explode('_', $titleId);
                 $readingHistoryDB = new ReadingHistoryEntry();
                 $readingHistoryDB->userId = $user->id;
                 $readingHistoryDB->id = str_replace('rsh', '', $titleId);
                 if ($readingHistoryDB->find(true)) {
                     $readingHistoryDB->deleted = 1;
                     $readingHistoryDB->update();
                 }
             }
         } elseif ($action == 'deleteAll') {
             //Remove all titles from database (do not remove from ILS)
             $readingHistoryDB = new ReadingHistoryEntry();
             $readingHistoryDB->userId = $user->id;
             $readingHistoryDB->find();
             while ($readingHistoryDB->fetch()) {
                 $readingHistoryDB->deleted = 1;
                 $readingHistoryDB->update();
             }
         } elseif ($action == 'exportList') {
             //Leave this unimplemented for now.
         } elseif ($action == 'optOut') {
             $driverHasReadingHistory = $this->driver->hasNativeReadingHistory();
             //Opt out within the ILS if possible
             if ($driverHasReadingHistory) {
                 //First run delete all
                 $result = $this->driver->doReadingHistoryAction('deleteAll', $selectedTitles);
                 $result = $this->driver->doReadingHistoryAction($action, $selectedTitles);
             }
             //Delete the reading history (permanently this time sine we are opting out)
             $readingHistoryDB = new ReadingHistoryEntry();
             $readingHistoryDB->userId = $user->id;
             $readingHistoryDB->delete();
             //Opt out within Pika since the ILS does not seem to implement this functionality
             $user->trackReadingHistory = false;
             $user->update();
             $_SESSION['userinfo'] = serialize($user);
         } elseif ($action == 'optIn') {
             $driverHasReadingHistory = $this->driver->hasNativeReadingHistory();
             //Opt in within the ILS if possible
             if ($driverHasReadingHistory) {
                 $result = $this->driver->doReadingHistoryAction($action, $selectedTitles);
             }
             //Opt in within Pika since the ILS does not seem to implement this functionality
             $user->trackReadingHistory = true;
             $user->update();
             $_SESSION['userinfo'] = serialize($user);
         }
     } else {
         return $this->driver->doReadingHistoryAction($action, $selectedTitles);
     }
 }