Ejemplo n.º 1
0
 private function saveChanges($user)
 {
     require_once ROOT_DIR . '/sys/LocalEnrichment/UserListEntry.php';
     $userListEntry = new UserListEntry();
     $userListEntry->id = $_REQUEST['listEntry'];
     if ($userListEntry->find(true)) {
         $userListEntry->notes = $_REQUEST['notes'];
         $userListEntry->update();
     }
 }
Ejemplo n.º 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');
     }
 }
Ejemplo n.º 3
0
 function saveToList()
 {
     $result = array();
     global $user;
     if ($user === false) {
         $result['result'] = false;
         $result['message'] = 'Please login before adding a title to list.';
     } else {
         require_once ROOT_DIR . '/sys/LocalEnrichment/UserList.php';
         require_once ROOT_DIR . '/sys/LocalEnrichment/UserListEntry.php';
         $result['result'] = true;
         $id = $_REQUEST['id'];
         $listId = $_REQUEST['listId'];
         $notes = $_REQUEST['notes'];
         //Check to see if we need to create a list
         $userList = new UserList();
         $listOk = true;
         if (empty($listId)) {
             $userList->title = "My Favorites";
             $userList->user_id = $user->id;
             $userList->public = 0;
             $userList->description = '';
             $userList->insert();
         } else {
             $userList->id = $listId;
             if (!$userList->find(true)) {
                 $result['result'] = false;
                 $result['message'] = 'Sorry, we could not find that list in the system.';
                 $listOk = false;
             }
         }
         if ($listOk) {
             $userListEntry = new UserListEntry();
             $userListEntry->listId = $userList->id;
             $userListEntry->groupedWorkPermanentId = $id;
             $existingEntry = false;
             if ($userListEntry->find(true)) {
                 $existingEntry = true;
             }
             $userListEntry->notes = $notes;
             $userListEntry->dateAdded = time();
             if ($existingEntry) {
                 $userListEntry->update();
             } else {
                 $userListEntry->insert();
             }
         }
         $result['result'] = true;
         $result['message'] = 'This title was saved to your list successfully.';
     }
     return json_encode($result);
 }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
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);
 }