/** * 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; }
/** * 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; }