/** * Add this tag to an object * * @param string $scope Object type (ex: resource, ticket) * @param integer $scope_id Object ID (e.g., resource ID, ticket ID) * @param integer $tagger User ID of person adding tag * @param integer $strength Tag strength * @param string $label Label to apply * @return boolean */ public function addTo($scope, $scope_id, $tagger = 0, $strength = 1, $label = '') { // Check if the relationship already exists $to = Object::oneByScoped($scope, $scope_id, $this->get('id'), $tagger); if ($to->get('id')) { return true; } // Set some data $to->set('tbl', (string) $scope); $to->set('objectid', (int) $scope_id); $to->set('tagid', (int) $this->get('id')); $to->set('strength', (int) $strength); if ($label) { $to->set('label', (string) $label); } if ($tagger) { $to->set('taggerid', $tagger); } // Attempt to store the new record if (!$to->save()) { $this->addError($to->getError()); return false; } $this->set('objects', $this->objects()->total()); $this->save(); return true; }