コード例 #1
0
ファイル: entries.php プロジェクト: mined-gatech/hubzero-cms
 /**
  * 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;
     }
 }