Пример #1
0
 function launch($msg = null)
 {
     global $interface;
     global $configArray;
     if (!($user = UserAccount::isLoggedIn())) {
         require_once ROOT_DIR . '/services/MyAccount/Login.php';
         MyAccount_Login::launch();
         exit;
     }
     // Save Data
     if (isset($_POST['submit'])) {
         $this->saveChanges($user);
         // After changes are saved, send the user back to an appropriate page;
         // either the list they were viewing when they started editing, or the
         // overall favorites list.
         if (isset($_REQUEST['list_id'])) {
             $nextAction = 'MyList/' . $_REQUEST['list_id'];
         } else {
             $nextAction = 'Home';
         }
         header('Location: ' . $configArray['Site']['path'] . '/MyAccount/' . $nextAction);
         exit;
     }
     require_once ROOT_DIR . '/sys/LocalEnrichment/UserList.php';
     $userList = new UserList();
     $userList->id = $_REQUEST['list_id'];
     $userList->find(true);
     $interface->assign('list', $userList);
     require_once ROOT_DIR . '/RecordDrivers/GroupedWorkDriver.php';
     $id = $_GET['id'];
     $groupedWorkDriver = new GroupedWorkDriver($id);
     if ($groupedWorkDriver->isValid) {
         $interface->assign('recordDriver', $groupedWorkDriver);
     }
     // Record ID
     $interface->assign('recordId', $id);
     // Retrieve saved information about record
     require_once ROOT_DIR . '/sys/LocalEnrichment/UserListEntry.php';
     $userListEntry = new UserListEntry();
     $userListEntry->groupedWorkPermanentId = $id;
     $userListEntry->listId = $_REQUEST['list_id'];
     $userListEntry->find(true);
     $interface->assign('listEntry', $userListEntry);
     $interface->assign('listFilter', $_GET['list_id']);
     $interface->setTemplate('editListTitle.tpl');
     $interface->display('layout.tpl');
 }
Пример #2
0
 /**
  * Add titles to a user list.
  *
  * Parameters:
  * <ul>
  * <li>username - The barcode of the user.  Can be truncated to the last 7 or 9 digits.</li>
  * <li>password - The pin number for the user. </li>
  * <li>listId   - The id of the list to add items to.</li>
  * <li>recordIds - The id of the record(s) to add to the list.</li>
  * <li>tags   - A comma separated string of tags to apply to the titles within the list. (optional)</li>
  * <li>notes  - descriptive text to apply to the titles.  Can be viewed while on the list.  (optional)</li>
  * </ul>
  *
  * Note: You may also provide the parameters to addTitlesToList and titles will be added to the list
  * after the list is created.
  *
  * Returns:
  * <ul>
  * <li>success - true if the account is valid and the titles could be added to the list, false if the username or password were incorrect or the list could not be created.</li>
  * <li>listId - the id of the list that titles were added to.</li>
  * <li>numAdded - the number of titles that were added to the list.</li>
  * </ul>
  *
  * Sample Call:
  * <code>
  * http://catalog.douglascountylibraries.org/API/ListAPI?method=createList&username=23025003575917&password=1234&title=Test+List&description=Test&public=0
  * </code>
  *
  * Sample Response:
  * <code>
  * {"result":{"success":true,"listId":"1688"}}
  * </code>
  */
 function addTitlesToList()
 {
     $username = $_REQUEST['username'];
     $password = $_REQUEST['password'];
     if (!isset($_REQUEST['listId'])) {
         return array('success' => false, 'message' => 'You must provide the listId to add titles to.');
     }
     $recordIds = array();
     if (!isset($_REQUEST['recordIds'])) {
         return array('success' => false, 'message' => 'You must provide one or more records to add tot he list.');
     } else {
         if (!is_array($_REQUEST['recordIds'])) {
             $recordIds[] = $_REQUEST['recordIds'];
         } else {
             $recordIds = $_REQUEST['recordIds'];
         }
     }
     global $user;
     $user = UserAccount::validateAccount($username, $password);
     if ($user && !PEAR_Singleton::isError($user)) {
         $list = new UserList();
         $list->id = $_REQUEST['listId'];
         $list->user_id = $user->id;
         if (!$list->find(true)) {
             return array('success' => false, 'message' => 'Unable to find the list to add titles to.');
         } else {
             $numAdded = 0;
             foreach ($recordIds as $id) {
                 $userListEntry = new UserListEntry();
                 $userListEntry->listId = $list->id;
                 $userListEntry->groupedWorkPermanentId = $id;
                 $existingEntry = false;
                 if ($userListEntry->find(true)) {
                     $existingEntry = true;
                 }
                 if (isset($_REQUEST['notes'])) {
                     $notes = $_REQUEST['notes'];
                 } else {
                     $notes = '';
                 }
                 $userListEntry->notes = $notes;
                 $userListEntry->dateAdded = time();
                 if ($existingEntry) {
                     $userListEntry->update();
                 } else {
                     $userListEntry->insert();
                 }
                 $numAdded++;
             }
             return array('success' => true, 'listId' => $list->id, 'numAdded' => $numAdded);
         }
     } else {
         return array('success' => false, 'message' => 'Login unsuccessful');
     }
 }
Пример #3
0
 function bulkAddTitles($list)
 {
     global $user;
     $numAdded = 0;
     $notes = array();
     $titlesToAdd = $_REQUEST['titlesToAdd'];
     $titleSearches[] = preg_split("/\\r\\n|\\r|\\n/", $titlesToAdd);
     foreach ($titleSearches[0] as $titleSearch) {
         $_REQUEST['lookfor'] = $titleSearch;
         $_REQUEST['type'] = 'Keyword';
         // Initialise from the current search globals
         $searchObject = SearchObjectFactory::initSearchObject();
         $searchObject->setLimit(1);
         $searchObject->init();
         $searchObject->clearFacets();
         $results = $searchObject->processSearch(false, false);
         if ($results['response'] && $results['response']['numFound'] >= 1) {
             $firstDoc = $results['response']['docs'][0];
             //Get the id of the document
             $id = $firstDoc['id'];
             $numAdded++;
             $userListEntry = new UserListEntry();
             $userListEntry->listId = $list->id;
             $userListEntry->groupedWorkPermanentId = $id;
             $existingEntry = false;
             if ($userListEntry->find(true)) {
                 $existingEntry = true;
             }
             $userListEntry->notes = '';
             $userListEntry->dateAdded = time();
             if ($existingEntry) {
                 $userListEntry->update();
             } else {
                 $userListEntry->insert();
             }
         } else {
             $notes[] = "Could not find a title matching " . $titleSearch;
         }
     }
     //Update solr
     $list->update();
     if ($numAdded > 0) {
         $notes[] = "Added {$numAdded} titles to the list";
     }
     return $notes;
 }
Пример #4
0
 /**
  * @param String $workToRemove
  */
 function removeListEntry($workToRemove)
 {
     // Remove the Saved List Entry
     require_once ROOT_DIR . '/sys/LocalEnrichment/UserListEntry.php';
     $listEntry = new UserListEntry();
     $listEntry->groupedWorkPermanentId = $workToRemove;
     $listEntry->listId = $this->id;
     $listEntry->delete();
     unset($this->listTitles[$this->id]);
 }
Пример #5
0
 /**
  * Import Lists from the ILS
  *
  * @return array - an array of results including the names of the lists that were imported as well as number of titles.
  */
 function importListsFromIls()
 {
     require_once ROOT_DIR . '/sys/LocalEnrichment/UserList.php';
     global $user;
     $results = array('totalTitles' => 0, 'totalLists' => 0);
     $patronDump = $this->_getPatronDump($this->_getBarcode());
     //Get the page which contains a table with all lists in them.
     $listsPage = $this->_fetchPatronInfoPage($patronDump, 'mylists');
     //Get the actual table
     if (preg_match('/<table[^>]*?class="patFunc"[^>]*?>(.*?)<\\/table>/si', $listsPage, $listsPageMatches)) {
         $allListTable = $listsPageMatches[1];
         //Now that we have the table, get the actual list names and ids
         preg_match_all('/<tr[^>]*?class="patFuncEntry"[^>]*?>.*?<input type="checkbox" id ="(\\d+)".*?<a.*?>(.*?)<\\/a>.*?<td[^>]*class="patFuncDetails">(.*?)<\\/td>.*?<\\/tr>/si', $allListTable, $listDetails, PREG_SET_ORDER);
         for ($listIndex = 0; $listIndex < count($listDetails); $listIndex++) {
             $listId = $listDetails[$listIndex][1];
             $title = $listDetails[$listIndex][2];
             $description = str_replace('&nbsp;', '', $listDetails[$listIndex][3]);
             //Create the list (or find one that already exists)
             $newList = new UserList();
             $newList->user_id = $user->id;
             $newList->title = $title;
             if (!$newList->find(true)) {
                 $newList->description = $description;
                 $newList->insert();
             }
             $currentListTitles = $newList->getListTitles();
             //Get a list of all titles within the list to be imported
             $listDetailsPage = $this->_fetchPatronInfoPage($patronDump, 'mylists?listNum=' . $listId);
             //Get the table for the details
             if (preg_match('/<table[^>]*?class="patFunc"[^>]*?>(.*?)<\\/table>/si', $listDetailsPage, $listsDetailsMatches)) {
                 $listTitlesTable = $listsDetailsMatches[1];
                 //Get the bib numbers for the title
                 preg_match_all('/<input type="checkbox" name="(b\\d{1,7})".*?<span[^>]*class="patFuncTitle(?:Main)?">(.*?)<\\/span>/si', $listTitlesTable, $bibNumberMatches, PREG_SET_ORDER);
                 for ($bibCtr = 0; $bibCtr < count($bibNumberMatches); $bibCtr++) {
                     $bibNumber = $bibNumberMatches[$bibCtr][1];
                     $bibTitle = strip_tags($bibNumberMatches[$bibCtr][2]);
                     //Get the grouped work for the resource
                     require_once ROOT_DIR . '/sys/Grouping/GroupedWorkPrimaryIdentifier.php';
                     require_once ROOT_DIR . '/sys/Grouping/GroupedWork.php';
                     $primaryIdentifier = new GroupedWorkPrimaryIdentifier();
                     $groupedWork = new GroupedWork();
                     $primaryIdentifier->identifier = '.' . $bibNumber . $this->getCheckDigit($bibNumber);
                     $primaryIdentifier->type = 'ils';
                     $primaryIdentifier->joinAdd($groupedWork);
                     if ($primaryIdentifier->find(true)) {
                         //Check to see if this title is already on the list.
                         $resourceOnList = false;
                         foreach ($currentListTitles as $currentTitle) {
                             if ($currentTitle->groupedWorkPermanentId == $primaryIdentifier->permanent_id) {
                                 $resourceOnList = true;
                                 break;
                             }
                         }
                         if (!$resourceOnList) {
                             $listEntry = new UserListEntry();
                             $listEntry->groupedWorkPermanentId = $primaryIdentifier->permanent_id;
                             $listEntry->listId = $newList->id;
                             $listEntry->notes = '';
                             $listEntry->dateAdded = time();
                             $listEntry->insert();
                         }
                     } else {
                         //The title is not in the resources, add an error to the results
                         if (!isset($results['errors'])) {
                             $results['errors'] = array();
                         }
                         $results['errors'][] = "\"{$bibTitle}\" on list {$title} could not be found in the catalog and was not imported.";
                     }
                     $results['totalTitles']++;
                 }
             }
             $results['totalLists'] += 1;
         }
     }
     return $results;
 }
Пример #6
0
 function getSaveToListForm()
 {
     global $interface;
     global $user;
     $id = $_REQUEST['id'];
     $interface->assign('id', $id);
     require_once ROOT_DIR . '/sys/LocalEnrichment/UserListEntry.php';
     //Get a list of all lists for the user
     $containingLists = array();
     $nonContainingLists = array();
     $userLists = new UserList();
     $userLists->user_id = $user->id;
     $userLists->deleted = 0;
     $userLists->find();
     while ($userLists->fetch()) {
         //Check to see if the user has already added the title to the list.
         $userListEntry = new UserListEntry();
         $userListEntry->listId = $userLists->id;
         $userListEntry->groupedWorkPermanentId = $id;
         if ($userListEntry->find(true)) {
             $containingLists[] = array('id' => $userLists->id, 'title' => $userLists->title);
         } else {
             $nonContainingLists[] = array('id' => $userLists->id, 'title' => $userLists->title);
         }
     }
     $interface->assign('containingLists', $containingLists);
     $interface->assign('nonContainingLists', $nonContainingLists);
     $results = array('title' => 'Add To List', 'modalBody' => $interface->fetch("GroupedWork/save.tpl"), 'modalButtons' => "<span class='tool btn btn-primary' onclick='VuFind.GroupedWork.saveToList(\"{$id}\"); return false;'>Save To List</span>");
     return json_encode($results);
 }
Пример #7
0
 /**
  * Assign necessary Smarty variables and return a template name to
  * load in order to display a summary of the item suitable for use in
  * user's favorites list.
  *
  * @access  public
  * @param   object $user User object owning tag/note metadata.
  * @param   int $listId ID of list containing desired tags/notes (or
  *                              null to show tags/notes from all user's lists).
  * @param   bool $allowEdit Should we display edit controls?
  * @return  string              Name of Smarty template file to display.
  */
 public function getListEntry($user, $listId = null, $allowEdit = true)
 {
     global $configArray;
     global $interface;
     global $timer;
     $id = $this->getUniqueID();
     $timer->logTime("Starting to load search result for grouped work {$id}");
     $interface->assign('summId', $id);
     if (substr($id, 0, 1) == '.') {
         $interface->assign('summShortId', substr($id, 1));
     } else {
         $interface->assign('summShortId', $id);
     }
     $relatedManifestations = $this->getRelatedManifestations();
     $interface->assign('relatedManifestations', $relatedManifestations);
     //Build the link URL.
     //If there is only one record for the work we will link straight to that.
     $relatedRecords = $this->getRelatedRecords();
     if (count($relatedRecords) == 1) {
         $firstRecord = reset($relatedRecords);
         /** @var IndexRecord|OverDriveRecordDriver|BaseEContentDriver $driver */
         $driver = $firstRecord['driver'];
         $linkUrl = $driver->getLinkUrl();
     } else {
         $linkUrl = $this->getLinkUrl() . '?searchId=' . $interface->get_template_vars('searchId') . '&amp;recordIndex=' . $interface->get_template_vars('recordIndex') . '&amp;page=' . $interface->get_template_vars('page');
     }
     $interface->assign('summUrl', $linkUrl);
     $interface->assign('summTitle', $this->getTitle());
     $interface->assign('summSubTitle', $this->getSubtitle());
     $interface->assign('summAuthor', $this->getPrimaryAuthor());
     $isbn = $this->getCleanISBN();
     $interface->assign('summISBN', $isbn);
     $interface->assign('summFormats', $this->getFormats());
     $summPublisher = null;
     $summPubDate = null;
     $summPhysicalDesc = null;
     $summEdition = null;
     $summLanguage = null;
     $isFirst = true;
     foreach ($relatedRecords as $relatedRecord) {
         if ($isFirst) {
             $summPublisher = $relatedRecord['publisher'];
             $summPubDate = $relatedRecord['publicationDate'];
             $summPhysicalDesc = $relatedRecord['physical'];
             $summEdition = $relatedRecord['edition'];
             $summLanguage = $relatedRecord['language'];
         } else {
             if ($summPublisher != $relatedRecord['publisher']) {
                 $summPublisher = null;
             }
             if ($summPubDate != $relatedRecord['publicationDate']) {
                 $summPubDate = null;
             }
             if ($summPhysicalDesc != $relatedRecord['physical']) {
                 $summPhysicalDesc = null;
             }
             if ($summEdition != $relatedRecord['edition']) {
                 $summEdition = null;
             }
             if ($summLanguage != $relatedRecord['language']) {
                 $summLanguage = null;
             }
         }
         $isFirst = false;
     }
     $interface->assign('summPublisher', $summPublisher);
     $interface->assign('summPubDate', $summPubDate);
     $interface->assign('summPhysicalDesc', $summPhysicalDesc);
     $interface->assign('summEdition', $summEdition);
     $interface->assign('summLanguage', $summLanguage);
     $interface->assign('numRelatedRecords', $this->getNumRelatedRecords());
     if ($configArray['System']['debugSolr']) {
         $interface->assign('summScore', $this->getScore());
         $interface->assign('summExplain', $this->getExplain());
     }
     //Get Rating
     $interface->assign('summRating', $this->getRatingData());
     //Description
     $interface->assign('summDescription', $this->getDescriptionFast());
     $timer->logTime('Finished Loading Description');
     if ($this->hasCachedSeries()) {
         $interface->assign('ajaxSeries', false);
         $interface->assign('summSeries', $this->getSeries());
     } else {
         $interface->assign('ajaxSeries', true);
     }
     $timer->logTime('Finished Loading Series');
     //Get information from list entry
     if ($listId) {
         require_once ROOT_DIR . '/sys/LocalEnrichment/UserListEntry.php';
         $listEntry = new UserListEntry();
         $listEntry->groupedWorkPermanentId = $this->getUniqueID();
         $listEntry->listId = $listId;
         if ($listEntry->find(true)) {
             $interface->assign('listEntryNotes', $listEntry->notes);
         }
         $interface->assign('listEditAllowed', $allowEdit);
     }
     $interface->assign('bookCoverUrl', $this->getBookcoverUrl('small'));
     $interface->assign('bookCoverUrlMedium', $this->getBookcoverUrl('medium'));
     // By default, do not display AJAX status; we won't assume that all
     // records exist in the ILS.  Child classes can override this setting
     // to turn on AJAX as needed:
     $interface->assign('summAjaxStatus', false);
     $interface->assign('recordDriver', $this);
     return 'RecordDrivers/GroupedWork/listentry.tpl';
 }
Пример #8
0
 function setListEntryPositions()
 {
     $success = false;
     // assume failure
     $listId = $_REQUEST['listID'];
     $updates = $_REQUEST['updates'];
     if (ctype_digit($listId) && !empty($updates)) {
         global $user;
         require_once ROOT_DIR . '/sys/LocalEnrichment/UserList.php';
         $list = new UserList();
         $list->id = $listId;
         if ($list->find(true) && $user->canEditList($list)) {
             // list exists & user can edit
             require_once ROOT_DIR . '/sys/LocalEnrichment/UserListEntry.php';
             $success = true;
             // assume success now
             foreach ($updates as $update) {
                 $userListEntry = new UserListEntry();
                 $userListEntry->listId = $listId;
                 $userListEntry->groupedWorkPermanentId = $update['id'];
                 if ($userListEntry->find(true) && ctype_digit($update['newOrder'])) {
                     // check entry exists already and the new weight is a number
                     $userListEntry->weight = $update['newOrder'];
                     if (!$userListEntry->update()) {
                         $success = false;
                     }
                 } else {
                     $success = false;
                 }
             }
         }
     }
     return array('success' => $success);
 }