コード例 #1
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);
     }
 }