/** * Given an array of item ids, remove them from all lists * * @param array $ids IDs to remove from the list * @param string $source Type of resource identified by IDs * * @return bool True on success, false on error. * @access public */ public function removeResourcesById($ids, $source = 'VuFind') { $sqlIDS = array(); foreach ($ids as $id) { if (!empty($id)) { $sqlIDS[] = "'" . $this->escape($id) . "'"; } } // No work is needed if we have no IDs to delete: if (empty($sqlIDS)) { return true; } // Get Resource Ids $sql = 'SELECT "id" from "resource" ' . 'WHERE ("record_id" = ' . implode($sqlIDS, ' OR "record_id" = ') . ") " . "AND \"source\"='" . $this->escape($source) . "'"; $resources = new Resource(); $resources->query($sql); if ($resources->N) { while ($resources->fetch()) { $resourceList[] = "'" . $this->escape($resources->id) . "'"; } } // Remove Resource $sql = 'DELETE FROM "user_resource" ' . "WHERE \"user_id\" = '" . $this->escape($this->id) . "' " . 'AND ("resource_id" =' . implode($resourceList, ' OR "resource_id" =') . ")"; $removeResource = new User_resource(); $removeResource->query($sql); // Remove Resource Tags $sql = 'DELETE FROM "resource_tags" ' . "WHERE \"user_id\" = '" . $this->escape($this->id) . "' " . 'AND ("resource_id" =' . implode($resourceList, ' OR "resource_id" =') . ")"; $removeTags = new Resource_tags(); $removeTags->query($sql); // Update mofidication dates for all lists $this->updateListModifiedDates(); // If we got this far, there were no fatal DB errors so report success return true; }
function removeTag($tagId, $user, $removeFromAllResources = false) { require_once ROOT_DIR . '/services/MyResearch/lib/Tags.php'; require_once ROOT_DIR . '/services/MyResearch/lib/Resource_tags.php'; $rTag = new Resource_tags(); if (!$removeFromAllResources) { $rTag->resource_id = $this->id; } $rTag->tag_id = $tagId; $rTag->user_id = $user->id; $rTag->find(); if ($rTag->N > 0) { while ($rTag->fetch()) { $rTag->delete(); } } else { //the tag was not found. return false; } //Check to see if the tag is still in use by any user for any resource. $rTag = new Resource_tags(); $rTag->tag_id = $tagId; $rTag->find(); if ($rTag->N == 0) { //Tag is still in use, delete it. $tags = new Tags(); $tags->id = $tagId; if ($tags->find(true)) { $tags->delete(); } } return true; }
/** * 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; }
/** * @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(); }
/** * @todo: delete any unused tags */ function removeResource($resource) { require_once 'User_resource.php'; // Remove the Saved Resource $join = new User_resource(); $join->user_id = $this->id; $join->resource_id = $resource->id; $join->delete(); // Remove the Tags from the resource require_once 'Resource_tags.php'; $join = new Resource_tags(); $join->user_id = $this->id; $join->resource_id = $resource->id; $join->delete(); }
/** * Add a tag to the current resource. * * @param string $tag The tag to save. * @param object $user The user posting the tag. * * @return bool True on success, false on failure. * @access public */ public function addTag($tag, $user) { $tag = trim($tag); if (!empty($tag)) { include_once 'services/MyResearch/lib/Tags.php'; include_once 'services/MyResearch/lib/Resource_tags.php'; $tags = new Tags(); $tags->tag = $tag; if (!$tags->find(true)) { $tags->insert(); } $rTag = new Resource_tags(); $rTag->resource_id = $this->id; $rTag->tag_id = $tags->id; if (!$rTag->find()) { $rTag->user_id = $user->id; $rTag->insert(); } } return true; }