Exemple #1
0
 /**
  * Copy all tag associations from one tag to another
  *
  * @return     void
  */
 public function pierceTask()
 {
     // 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)) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false));
         return;
     }
     $idstr = implode(',', $ids);
     switch ($step) {
         case 1:
             Request::setVar('hidemainmenu', 1);
             $this->view->step = 2;
             $this->view->idstr = $idstr;
             $this->view->tags = array();
             // Loop through the IDs of the tags we want to merge
             foreach ($ids as $id) {
                 // Load the tag's info
                 $this->view->tags[] = new Tag(intval($id));
             }
             // Get all tags
             $cloud = new Cloud();
             // Set any errors
             if ($this->getError()) {
                 $this->view->setError($this->getError());
             }
             // Output the HTML
             $this->view->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 = new Tag($tag_new);
                 if (!$newtag->exists()) {
                     $newtag->set('raw_tag', $tag_new);
                 }
                 if (!$newtag->store(true)) {
                     $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 = new Tag(intval($id));
                 if (!$oldtag->copyTo($mtag)) {
                     $this->setError($oldtag->getError());
                 }
             }
             App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_TAGS_TAGS_COPIED'));
             break;
     }
 }
 /**
  * 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);
     if (!$tag->exists()) {
         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);
 }