Beispiel #1
0
 /**
  * Get information saved in a user's favorites for a particular record.
  *
  * @param string $resourceId ID of record being checked.
  * @param int    $listId     Optional list ID (to limit results to a particular
  * list).
  *
  * @return array
  * @access public
  */
 public function getSavedData($resourceId, $listId = null)
 {
     $savedList = array();
     $sql = 'SELECT "user_resource".*, "user_list"."title" as list_title, ' . '"user_list"."id" as list_id ' . 'FROM "user_resource", "resource", "user_list" ' . 'WHERE "resource"."id" = "user_resource"."resource_id" ' . 'AND "user_resource"."list_id" = "user_list"."id" ' . 'AND "user_resource"."user_id" = ' . "'" . $this->escape($this->id) . "' " . 'AND "resource"."record_id" = ' . "'" . $this->escape($resourceId) . "'";
     if (!is_null($listId)) {
         $sql .= ' AND "user_resource"."list_id"=' . "'" . $this->escape($listId) . "'";
     }
     $saved = new User_resource();
     $saved->query($sql);
     if ($saved->N) {
         while ($saved->fetch()) {
             $savedList[] = clone $saved;
         }
     }
     return $savedList;
 }
Beispiel #2
0
 /**
  * Remove all resources and tags and delete a list.
  *
  * @return bool True on success, false on error.
  * @access public
  */
 public function emptyList()
 {
     // Remove Resources
     $sql = 'DELETE FROM "user_resource" ' . "WHERE \"user_id\" = '" . $this->escape($this->user_id) . "' " . "AND \"list_id\" = '" . $this->escape($this->id) . "'";
     $removeResource = new User_resource();
     $removeResource->query($sql);
     // Remove Resource Tags
     $sql = 'DELETE FROM "resource_tags" ' . "WHERE \"user_id\" = '" . $this->escape($this->user_id) . "' " . "AND \"list_id\" = '" . $this->escape($this->id) . "'";
     $removeTags = new Resource_tags();
     $removeTags->query($sql);
     // Remove the List
     $this->delete();
     // If we got this far, there were no fatal DB errors so report success
     return true;
 }
Beispiel #3
0
 /**
  * @todo: delete any unused tags
  */
 function removeResource($resource)
 {
     // Remove the Saved Resource
     require_once ROOT_DIR . '/services/MyResearch/lib/User_list.php';
     require_once ROOT_DIR . '/services/MyResearch/lib/Resource.php';
     $join = new User_resource();
     $join->user_id = $this->user_id;
     $join->resource_id = $resource->id;
     $join->list_id = $this->id;
     $join->delete();
     // Remove the Tags from the resource
     $join = new Resource_tags();
     $join->user_id = $this->user_id;
     $join->resource_id = $resource->id;
     $join->list_id = $this->id;
     $join->delete();
 }
Beispiel #4
0
 /**
  * Perform a bulk operation.
  *
  * @param array $ids    IDs to process
  * @param int   $listID Target list
  * limit).
  *
  * @return boolean Success
  */
 protected function processRecords($ids, $listID)
 {
     global $user;
     if (empty($ids)) {
         $this->errorMsg = 'bulk_noitems_advice';
         return false;
     }
     if (!$user) {
         $this->errorMsg = 'You must be logged in first';
         return false;
     }
     $list = User_list::staticGet($listID);
     if ($user->id != $list->user_id) {
         $this->errorMsg = 'list_access_denied';
         return false;
     }
     $resources = $user->getResources();
     foreach ($resources as $resource) {
         if (in_array($resource->record_id, $ids)) {
             $notes = '';
             $userResource = new User_resource();
             $userResource->user_id = $user->id;
             $userResource->list_id = $_REQUEST['listID'];
             $userResource->resource_id = $resource->id;
             if ($userResource->find(true)) {
                 $notes = $userResource->notes;
             }
             $tags = array();
             foreach ($user->getTags($resource->record_id) as $tag) {
                 $tags[] = $tag->tag;
             }
             $user->addResource($resource, $list, $tags, $notes);
         }
     }
     $this->infoMsg = 'records_copied';
     return true;
 }
Beispiel #5
0
 function getSavedData($resourceId, $source, $listId = null)
 {
     require_once 'User_resource.php';
     $savedList = array();
     $sql = "SELECT user_resource.*, user_list.title as list_title, user_list.id as list_id " . "FROM user_resource, resource, user_list " . "WHERE resource.id = user_resource.resource_id " . "AND user_resource.list_id = user_list.id " . "AND user_resource.user_id = '{$this->id}' " . "AND resource.source = '{$source}' " . "AND resource.record_id = '{$resourceId}'";
     if (!is_null($listId)) {
         $sql .= " AND user_resource.list_id='{$listId}'";
     }
     $saved = new User_resource();
     $saved->query($sql);
     if ($saved->N) {
         while ($saved->fetch()) {
             $savedList[] = clone $saved;
         }
     }
     return $savedList;
 }