/** * Get tags for a list of IDs * * @param array $ids Bulletin ids * @param integer $admin Admin flag * @return array */ public function getTagsForIds($ids = array(), $admin = 0) { $tt = new Tables\Tag($this->_db); $tj = new Tables\Object($this->_db); if (!is_array($ids) || empty($ids)) { return false; } $ids = array_map('intval', $ids); $sql = "SELECT t.tag, t.raw_tag, t.admin, rt.objectid\n\t\t\t\tFROM " . $tt->getTableName() . " AS t \n\t\t\t\tINNER JOIN " . $tj->getTableName() . " AS rt ON (rt.tagid = t.id) AND rt.tbl='" . $this->_scope . "' \n\t\t\t\tWHERE rt.objectid IN (" . implode(',', $ids) . ") "; switch ($admin) { case 1: $sql .= ""; break; case 0: default: $sql .= "AND t.admin=0 "; break; } $sql .= "ORDER BY raw_tag ASC"; $this->_db->setQuery($sql); $tags = array(); if ($items = $this->_db->loadObjectList()) { foreach ($items as $item) { if (!isset($tags[$item->objectid])) { $tags[$item->objectid] = array(); } $tags[$item->objectid][] = $item; } } return $tags; }
/** * Remove all tags from an item * Option User ID to remove tags added by just that user. * * @param string $tagger User ID to remove tags for * @return mixed False if errors, integer on success */ public function removeAll($tagger = 0) { if (!$this->_scope_id) { $this->setError('Unable to remove tags: No objct ID provided.'); return false; } $to = new Tables\Object($this->_db); if (!$to->removeAllTags($this->_scope, $this->_scope_id, $tagger)) { $this->setError($to->getError()); return false; } return true; }
/** * Remove one or more entries * * @return void */ public function removeTask() { // Check for request forgeries Request::checkToken(); $ids = Request::getVar('id', array()); $ids = !is_array($ids) ? array($ids) : $ids; // Make sure we have an ID if (empty($ids)) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_TAGS_ERROR_NO_ITEMS_SELECTED'), 'error'); return; } $row = new Tables\Object($this->database); foreach ($ids as $id) { // Remove entry $row->delete(intval($id)); } App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_TAGS_OBJECT_REMOVED')); }
/** * Get all the substitutions for this tag * * @param integer $tag_id Tag ID * @param boolean $asString Return results as string? * @param integer $offset Record offset * @param integer $limit Number of records to return (returns all if less than 1) * @return mixed Array by default, string if $asString is set to true */ public function saveSubstitutions($tag_string = '', $tag_id = null) { $tag_id = $tag_id ?: $this->id; if (!$tag_id) { $this->setError(Lang::txt('Missing argument.')); return false; } require_once __DIR__ . DS . 'substitute.php'; $ts = new Substitute($this->_db); $subs = $ts->getRecords($tag_id); if (!$subs) { $subs = array(); } $raw_tags = explode(',', trim($tag_string)); $tags = array(); foreach ($raw_tags as $raw_tag) { $nrm = $this->normalize($raw_tag); $tags[] = $nrm; if (isset($subs[$nrm])) { continue; // Substitution already exists } $sub = new Substitute($this->_db); $sub->raw_tag = trim($raw_tag); $sub->tag_id = $tag_id; if ($sub->check()) { if (!$sub->store()) { $this->setError($sub->getError()); } } } // Build list of tags from old list not found in new list and delete them $remove = array(); foreach ($subs as $key => $sub) { if (!in_array($key, $tags)) { $remove[] = $key; } } $ts = new Substitute($this->_db); if (count($remove) > 0) { if (!$ts->removeForTag($tag_id, $remove)) { $this->setError($this->_db->getErrorMsg()); return false; } } // Get all possibly existing tags that are now aliases $sql = "SELECT t.id FROM {$this->_tbl} AS t WHERE t.tag IN ('" . implode("','", $tags) . "')"; $this->_db->setQuery($sql); if ($ids = $this->_db->loadObjectList()) { require_once __DIR__ . DS . 'object.php'; $to = new Object($this->_db); // Move associations on tag and delete tag foreach ($ids as $id) { if ($tag_id != $id->id) { // Get all the associations to this tag // Loop through the associations and link them to a different tag $to->moveObjects($id->id, $tag_id); // Get all the substitutions to this tag // Loop through the records and link them to a different tag $ts->moveSubstitutes($id->id, $tag_id); // Delete the tag $tag = new self($this->_db); $tag->delete($id->id); } } } return true; }