/** * Add a tag to an item * * @return void */ public function addTask() { $this->requiresAuthentication(); $name = Request::getWord('tag', ''); $id = Request::getInt('id', 0); $id = $id ? $id : $name; //$tag = new Tag($id); $tag = $id ? Tag::oneOrFail($id) : Tag::oneByTag($name); if (!$tag->get('id')) { throw new Exception(Lang::txt('Specified tag does not exist.'), 404); } $scope = Request::getWord('scope', ''); $scope_id = Request::getInt('scope_id', 0); $tagger = Request::getInt('tagger', 0); if (!$scope || !$scope_id) { throw new Exception(Lang::txt('Invalid scope and/or scope_id.'), 500); } if (!$tag->addTo($scope, $scope_id, $tagger)) { throw new Exception(Lang::txt('Failed to add tag to object.'), 500); } $this->send(null, 202); }
} ?> </select> <input type="hidden" name="tagid" value="<?php echo $this->filters['tagid']; ?> " /> </fieldset> <table class="adminlist"> <?php if ($this->filters['tagid']) { ?> <caption><?php $tag = \Components\Tags\Models\Tag::oneOrFail($this->filters['tagid']); echo Lang::txt('COM_TAGS_TAG') . ': ' . $this->escape($tag->get('raw_tag')) . ' (' . $this->escape($tag->get('tag')) . ')'; ?> </caption> <?php } ?> <thead> <tr> <th scope="col"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo $this->rows->count(); ?> );" /></th> <th scope="col" class="priority-5"><?php echo Html::grid('sort', 'COM_TAGS_COL_ID', 'id', @$this->filters['sort_Dir'], @$this->filters['sort']); ?>
/** * Copy all tag associations from one tag to another * * @return void */ public function pierceTask() { if (!User::authorise('core.edit', $this->_option) && !User::authorise('core.manage', $this->_option)) { App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR')); } // Incoming $ids = Request::getVar('id', array()); $ids = !is_array($ids) ? array($ids) : $ids; $step = Request::getInt('step', 1); $step = $step ? $step : 1; // Make sure we have some IDs to work with if ($step == 1 && (!$ids || count($ids) < 1)) { return $this->cancelTask(); } $idstr = implode(',', $ids); switch ($step) { case 1: Request::setVar('hidemainmenu', 1); $tags = array(); // Loop through the IDs of the tags we want to merge foreach ($ids as $id) { // Load the tag's info $tags[] = Tag::oneOrFail(intval($id)); } // Output the HTML $this->view->set('step', 2)->set('idstr', $idstr)->set('tags', $tags)->display(); break; case 2: // Check for request forgeries Request::checkToken(); // Get the string of tag IDs we plan to merge $ind = Request::getVar('ids', '', 'post'); if ($ind) { $ids = explode(',', $ind); } else { $ids = array(); } // Incoming $tag_exist = Request::getInt('existingtag', 0, 'post'); $tag_new = Request::getVar('newtag', '', 'post'); // Are we merging tags into a totally new tag? if ($tag_new) { // Yes, we are $newtag = Tag::oneByAlias($tag_new); if (!$newtag->get('id')) { $newtag->set('raw_tag', $tag_new); } if (!$newtag->save()) { $this->setError($newtag->getError()); } $mtag = $newtag->get('id'); } else { // No, we're merging into an existing tag $mtag = $tag_exist; } foreach ($ids as $id) { if ($mtag == $id) { continue; } $oldtag = Tag::oneOrFail(intval($id)); if (!$oldtag->copyTo($mtag)) { $this->setError($oldtag->getError()); } } if ($this->getError()) { Notify::error($this->getError()); } else { Lang::txt('COM_TAGS_TAGS_COPIED'); } $this->cancelTask(); break; } }
/** * Delete one or more tags * * @return void */ public function deleteTask() { // Check that the user is authorized if (!$this->config->get('access-delete-tag')) { throw new Exception(Lang::txt('ALERTNOTAUTH'), 403); } // Incoming $ids = Request::getVar('id', array()); if (!is_array($ids)) { $ids = array(); } // Make sure we have an ID if (empty($ids)) { App::redirect(Route::url('index.php?option=' . $this->_option . '&task=browse')); return; } foreach ($ids as $id) { $id = intval($id); // Remove references to the tag Event::trigger('tags.onTagDelete', array($id)); // Remove the tag $tag = Tag::oneOrFail($id); $tag->destroy(); } $this->cleancacheTask(false); // Get the browse filters so we can go back to previous view $search = Request::getVar('search', ''); $sortby = Request::getVar('sortby', ''); $limit = Request::getInt('limit', 25); $start = Request::getInt('limitstart', 0); $count = Request::getInt('count', 1); // Redirect back to browse mode App::redirect(Route::url('index.php?option=' . $this->_option . '&task=browse&search=' . $search . '&sortby=' . $sortby . '&limit=' . $limit . '&limitstart=' . $start . '#count' . $count)); }
/** * 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 = Object::all()->whereEquals('tbl', $this->_scope)->whereEquals('objectid', $this->_scope_id); if ($tagger) { $to->whereEquals('taggerid', $tagger); } $tags = array(); foreach ($to->rows() as $row) { $tags[] = $row->get('tagid'); if (!$row->destroy()) { $this->setError($row->getError()); return false; } } foreach ($tags as $tag_id) { $tag = Tag::oneOrFail($tag_id); $tag->set('objects', $tag->objects()->total())->save(); } return true; }