コード例 #1
0
ファイル: JSON.php プロジェクト: bryandease/VuFind-Plus
 function saveToMyList()
 {
     require_once ROOT_DIR . '/services/MyResearch/lib/Resource.php';
     require_once ROOT_DIR . '/services/MyResearch/lib/User.php';
     $listId = $_REQUEST['list'];
     $tags = $_REQUEST['mytags'];
     $notes = $_REQUEST['notes'];
     $ids = $_REQUEST['id'];
     global $user;
     $list = new User_list();
     if ($_GET['list'] != '') {
         $list->id = $listId;
         $list->find(true);
     } else {
         $list->user_id = $user->id;
         $list->title = "My Favorites";
         $list->insert();
     }
     $ctr = 0;
     foreach ($ids as $id) {
         $source = 'VuFind';
         $recordId = $id;
         if (strpos($recordId, 'econtentRecord') === 0) {
             $source = 'eContent';
             $recordId = str_ireplace("econtentrecord", "", $recordId);
         }
         $ctr++;
         $resource = new Resource();
         $resource->record_id = $recordId;
         $resource->source = $source;
         if (!$resource->find(true)) {
             $resource->insert();
         }
         preg_match_all('/"[^"]*"|[^,]+/', $tags, $tagArray);
         //Make sure that Solr is only updated once for performance reasons.
         $user->addResource($resource, $list, $tagArray[0], $notes, $ctr == count($ids));
     }
     return array('status' => 'OK');
 }
コード例 #2
0
ファイル: User.php プロジェクト: bharatm/NDL-VuFind
 /**
  * Get all of the lists associated with this user.
  *
  * @return array
  * @access public
  */
 public function getLists()
 {
     $lists = array();
     // Make sure at least "My Favorites" always exists
     $list = new User_list();
     $list->user_id = $this->id;
     if (!$list->find(true)) {
         $list->title = "My Favorites";
         if (!$list->find(true)) {
             $list->insert();
         }
     }
     $sql = 'SELECT "user_list".*, COUNT("user_resource"."id") AS cnt ' . 'FROM "user_list" LEFT JOIN "user_resource" ' . 'ON "user_list"."id" = "user_resource"."list_id" ' . 'WHERE "user_list"."user_id" = ' . "'" . $this->escape($this->id) . "' " . 'GROUP BY "user_list"."id", "user_list"."user_id", ' . '"user_list"."title", "user_list"."description", ' . '"user_list"."created", "user_list"."public" ' . 'ORDER BY "user_list"."created"';
     $list = new User_list();
     $list->query($sql);
     if ($list->N) {
         while ($list->fetch()) {
             $lists[] = clone $list;
         }
     }
     return $lists;
 }
コード例 #3
0
ファイル: Save.php プロジェクト: bharatm/NDL-VuFind
 /**
  * Save the record specified by GET parameters.
  *
  * @param object $user User who is saving the record.
  *
  * @return bool        True on success, false on failure.
  * @access public
  */
 public static function saveRecord($user)
 {
     // Fail if the user is not logged in:
     if (!$user) {
         return false;
     }
     $list = new User_list();
     if (isset($_GET['list']) && $_GET['list'] != '') {
         $list->id = $_GET['list'];
     } else {
         if (isset($_POST['list']) && $_POST['list'] != '') {
             $list->id = $_POST['list'];
         } else {
             $list->user_id = $user->id;
             $list->title = "My Favorites";
             if (!$list->find(true)) {
                 $list->insert();
             }
         }
     }
     // Remember that the list was used so it can be the default in future
     // dialog boxes:
     $list->rememberLastUsed();
     // Setup Search Engine Connection
     $db = ConnectionManager::connectToIndex('MetaLib');
     // Get Record Information
     $record = $db->getRecord($_GET['id']);
     if (!$record) {
         return false;
     }
     $resource = new Resource();
     $resource->record_id = $_GET['id'];
     $resource->source = 'MetaLib';
     if (!$resource->find(true)) {
         $resource->data = serialize($record);
         $resource->insert();
     } else {
         $resource->data = serialize($record);
         $resource->update();
     }
     preg_match_all('/"[^"]*"|[^ ]+/', isset($_GET['mytags']) ? $_GET['mytags'] : '', $tagArray);
     return $user->addResource($resource, $list, $tagArray[0], isset($_GET['notes']) ? $_GET['notes'] : '');
 }
コード例 #4
0
ファイル: ListEdit.php プロジェクト: bharatm/NDL-VuFind
 /**
  * Create a new list based on the current user and $_REQUEST parameters.
  *
  * @return mixed New list ID on success, PEAR_Error on failure.
  * @access public
  */
 public function addList()
 {
     if ($this->_user) {
         if (strlen(trim($_REQUEST['title'])) == 0) {
             return new PEAR_Error('list_edit_name_required');
         }
         $list = new User_list();
         $list->title = $_REQUEST['title'];
         $list->description = $_REQUEST['desc'];
         $list->public = $_REQUEST['public'];
         $list->user_id = $this->_user->id;
         $list->insert();
         $list->find();
         // Remember that the list was used so it can be the default in future
         // dialog boxes:
         $list->rememberLastUsed();
         return $list->id;
     }
 }
コード例 #5
0
ファイル: SaveToList.php プロジェクト: bryandease/VuFind-Plus
 function saveRecord()
 {
     if ($this->user) {
         $list = new User_list();
         if ($_GET['list'] != '') {
             $list->id = $_GET['list'];
         } else {
             $list->user_id = $this->user->id;
             $list->title = "My Favorites";
             $list->insert();
         }
         $resource = new Resource();
         $resource->record_id = $_GET['id'];
         $resource->service = $_GET['service'];
         if (!$resource->find(true)) {
             $resource->insert();
         }
         preg_match_all('/"[^"]*"|[^,]+/', $_GET['mytags'], $tagArray);
         $this->user->addResource($resource, $list, $tagArray[0], $_GET['notes']);
     } else {
         return false;
     }
 }
コード例 #6
0
ファイル: ListEdit.php プロジェクト: bryandease/VuFind-Plus
 function addList()
 {
     if ($this->user) {
         if (strlen(trim($_REQUEST['title'])) == 0) {
             return new PEAR_Error('list_edit_name_required');
         }
         $list = new User_list();
         $list->title = $_REQUEST['title'];
         $list->description = $_REQUEST['desc'];
         $list->public = $_REQUEST['public'];
         $list->user_id = $this->user->id;
         $list->insert();
         $list->find();
         return $list->id;
     }
 }
コード例 #7
0
ファイル: ListAPI.php プロジェクト: bryandease/VuFind-Plus
 /**
  * Create a User list for the user.
  *
  * 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>title    - The title of the list to create.</li>
  * <li>description - A description for the list (optional).</li>
  * <li>public   - Set to true or 1 if the list should be public.  (optional, defaults to private).</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 list could be created, false if the username or password were incorrect or the list could not be created.</li>
  * <li>listId - te id of the new list that is created.</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 createList()
 {
     $username = $_REQUEST['username'];
     $password = $_REQUEST['password'];
     if (!isset($_REQUEST['title'])) {
         return array('success' => false, 'message' => 'You must provide the title of the list to be created.');
     }
     global $user;
     $user = UserAccount::validateAccount($username, $password);
     if ($user && !PEAR_Singleton::isError($user)) {
         $list = new User_list();
         $list->title = $_REQUEST['title'];
         $list->description = isset($_REQUEST['description']) ? $_REQUEST['description'] : '';
         $list->public = isset($_REQUEST['public']) ? $_REQUEST['public'] == true || $_REQUEST['public'] == 1 ? 1 : 0 : 0;
         $list->user_id = $user->id;
         $list->insert();
         $list->find();
         if (!isset($_REQUEST['recordIds'])) {
             $result = $this->addTitlesToList();
             return $result;
         }
         return array('success' => true, 'listId' => $list->id);
     } else {
         return array('success' => false, 'message' => 'Login unsuccessful');
     }
 }
コード例 #8
0
ファイル: Save.php プロジェクト: bryandease/VuFind-Plus
 function saveRecord()
 {
     if ($this->user) {
         $list = new User_list();
         if ($_GET['list'] != '') {
             $list->id = $_GET['list'];
             $list->find(true);
         } else {
             $list->user_id = $this->user->id;
             $list->title = "My Favorites";
             $list->insert();
         }
         $resource = new Resource();
         $resource->record_id = $_GET['id'];
         if (isset($_GET['service'])) {
             $resource->source = $_GET['service'];
         } else {
             $resource->source = $_GET['source'];
         }
         if (!$resource->find(true)) {
             PEAR_Singleton::raiseError(new PEAR_Error('Unable find a resource for that title.'));
         }
         preg_match_all('/"[^"]*"|[^,]+/', $_GET['mytags'], $tagArray);
         $this->user->addResource($resource, $list, $tagArray[0], $_GET['notes']);
     } else {
         return false;
     }
 }
コード例 #9
0
ファイル: Save.php プロジェクト: bharatm/NDL-VuFind
 /**
  * Save the records
  *
  * @return array A list of successfully saved record ids and the list id
  * @access public
  */
 public function saveRecord()
 {
     // Fail if the user is not logged in:
     if (!$this->user || !isset($_POST['ids'])) {
         return false;
     }
     $list = new User_list();
     if ($_REQUEST['list'] != '') {
         $list->id = $_REQUEST['list'];
     } else {
         $list->user_id = $this->user->id;
         $list->title = "My Favorites";
         $list->insert();
     }
     // Remember that the list was used so it can be the default in future
     // dialog boxes:
     $list->rememberLastUsed();
     foreach ($_POST['ids'] as $id) {
         $resource = new Resource();
         $resource->record_id = $id;
         $resource->source = $_REQUEST['service'];
         if (!$resource->find(true)) {
             $resource->insert();
         }
         preg_match_all('/"[^"]*"|[^ ]+/', $_REQUEST['mytags'], $tagArray);
         $result['details'][$id] = $this->user->addResource($resource, $list, $tagArray[0], false, false);
     }
     $result['list'] = $list->id;
     return $result;
 }
コード例 #10
0
 /**
  * Get data and output in JSON
  *
  * @return void
  * @access public
  */
 public function saveListData()
 {
     global $user;
     if (!($user = UserAccount::isLoggedIn())) {
         $this->output("", JSON::STATUS_NEED_AUTH);
         return;
     }
     // Fetch List object
     $list = User_list::staticGet($_REQUEST['listId']);
     // Ensure user has permissions to edit the list
     if ($list->user_id != $user->id) {
         $this->output("", JSON::STATUS_NEED_AUTH);
         return;
     }
     // Save data and return status to AJAX script
     // Title
     if (isset($_REQUEST['title_change'])) {
         if (!$list->updateListTitle($_REQUEST['title_change'])) {
             $error = true;
         }
         // List Description
     } else {
         if (isset($_REQUEST['description_change'])) {
             if (!$list->updateListDescription($_REQUEST['description_change'])) {
                 $error = true;
             }
             // Visibility
         } else {
             if (isset($_REQUEST['publicity_change'])) {
                 if (!$list->updateListPublicity($_REQUEST['publicity_change'])) {
                     $error = true;
                 }
                 // Add list
             } else {
                 if (isset($_REQUEST['list_add'])) {
                     $value = $_REQUEST['list_add'];
                     $list = new User_list();
                     $list->title = $value;
                     $list->user_id = $user->id;
                     if ($list->insert() && $list->find()) {
                         $this->output("{$list->id}", JSON::STATUS_OK);
                         return;
                     } else {
                         $error = true;
                     }
                     // Entry description
                 } else {
                     if (isset($_REQUEST['entry_description_change'])) {
                         $resource = new Resource();
                         unset($resource->source);
                         $resource->record_id = $_REQUEST['recordId'];
                         $resource->find(true);
                         // Save resource
                         if (!$user->addResource($resource, $list, '', $_REQUEST['entry_description_change'])) {
                             $error = true;
                         }
                     }
                 }
             }
         }
     }
     if ($error) {
         $this->output("An error has occurred", JSON::STATUS_ERROR);
     } else {
         $this->output("", JSON::STATUS_OK);
     }
 }