/** * Deletes the tag relation specified by $pn_relation_id (a ca_items_x_tags.relation_id value) from the currently loaded row. Will only delete * tags attached to the currently loaded row. If you attempt to delete a ca_items_x_tags.relation_id not attached to the current row * removeTag() will return false and post an error. If you attempt to call removeTag() with no row loaded null will be returned. * If $pn_user_id is specified then only tags created by the specified user will be deleted; if the tag being * deleted is not created by the user then false is returned and an error posted. * * @param $pn_relation_id [integer] a valid ca_items_x_tags.relation_id to be removed; must be related to the currently loaded row (mandatory) * @param $pn_user_id [integer] a valid ca_users.user_id value; if specified then only tag relations added by the specified user will be deleted (optional - default is null) */ public function removeTag($pn_relation_id, $pn_user_id = null) { if (!($vn_row_id = $this->getPrimaryKey())) { return null; } $t_ixt = new ca_items_x_tags($pn_relation_id); if (!$t_ixt->getPrimaryKey()) { $this->postError(2800, _t('Tag relation id is invalid'), 'BaseModel->removeTag()', 'ca_item_tags'); return false; } if ($t_ixt->get('table_num') != $this->tableNum() || $t_ixt->get('row_id') != $vn_row_id) { $this->postError(2810, _t('Tag is not part of the current row'), 'BaseModel->removeTag()', 'ca_item_tags'); return false; } if ($pn_user_id) { if ($t_ixt->get('user_id') != $pn_user_id) { $this->postError(2820, _t('Tag was not created by specified user'), 'BaseModel->removeTag()', 'ca_item_tags'); return false; } } $t_ixt->setMode(ACCESS_WRITE); $t_ixt->delete(); if ($t_ixt->numErrors()) { $this->errors = $t_ixt->errors; return false; } return true; }