Exemple #1
0
 /**
  * Add a tag to an object
  * This will:
  * 1) First, check if the tag already exists
  *    a) if not, creates a database entry for the tag
  * 2) Adds a reference linking tag with object
  *
  * @param      integer $tagger_id Tagger ID
  * @param      integer $object_id Object ID
  * @param      string  $tag       Tag
  * @param      integer $strength  Tag strength
  * @return     boolean True on success, false if errors
  */
 public function safe_tag($tagger_id, $object_id, $tag, $strength = 1, $label = '')
 {
     if (!isset($tagger_id) || !isset($object_id) || !isset($tag)) {
         $this->setError('safe_tag argument missing');
         return false;
     }
     if ($this->normalize_tag($tag) === '0') {
         return true;
     }
     $to = new \Components\Tags\Tables\Object($this->_db);
     $to->objectid = $object_id;
     $to->tbl = $this->_tbl;
     $to->label = $label;
     // First see if the tag exists.
     $t = new \Components\Tags\Tables\Tag($this->_db);
     $t->loadTag($t->normalize($tag));
     if (!$t->id) {
         // Add new tag!
         $t->tag = $t->normalize($tag);
         $t->raw_tag = addslashes($tag);
         $t->created = \Date::toSql();
         $t->created_by = $tagger_id;
         if (!$t->check()) {
             $this->setError($t->getError());
             return false;
         }
         if (!$t->store()) {
             $this->setError($t->getError());
             return false;
         }
         if (!$t->id) {
             return false;
         }
         $to->tagid = $t->id;
     } else {
         $to->tagid = $t->id;
         // Check if the object has already been tagged
         if ($to->getCountForObject() > 0) {
             return true;
         }
     }
     // Add an entry linking the tag to the object it was used on
     $to->strength = $strength;
     $to->taggerid = $tagger_id;
     $to->taggedon = Date::toSql();
     if (!$to->store()) {
         $this->setError($to->getError());
         return false;
     }
     return true;
 }
 /**
  * Save a type
  *
  * @return     void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Initiate extended database class
     $fields = Request::getVar('fields', array(), 'post', 'none', 2);
     $fields = array_map('trim', $fields);
     $row = new \Plugins\Resources\Sponsors\Tables\Sponsor($this->database);
     if (!$row->bind($fields)) {
         $this->setError($row->getError());
         return $this->editTask($row);
     }
     // Check content
     if (!$row->check()) {
         $this->setError($row->getError());
         return $this->editTask($row);
     }
     // Store new content
     if (!$row->store()) {
         $this->setError($row->getError());
         return $this->editTask($row);
     }
     require_once PATH_CORE . DS . 'components' . DS . 'com_tags' . DS . 'tables' . DS . 'tag.php';
     $t = new \Components\Tags\Tables\Tag($this->database);
     $t->loadTag($row->alias);
     if (!$t->id) {
         // Add new tag!
         $t->tag = $row->alias;
         $t->raw_tag = addslashes($row->title);
         if (!$t->store()) {
             $this->setError($t->getError());
         }
     }
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&task=manage&plugin=sponsors', false), Lang::txt('PLG_RESOURCES_SPONSORS_ITEM_SAVED'));
 }