/** * update function * * @method post * @route /{object}/update */ public function updateAction() { $givenParameters = clone $this->getParams('post'); try { $tagId = TagsRepository::isExist($givenParameters['tagname']); if ($tagId > 0 && $tagId != $givenParameters['object_id']) { $this->router->response()->json(array('success' => false, 'error' => "This tag name already exists")); } else { TagsRepository::update($givenParameters, "form", $this->getUri()); unset($_SESSION['form_token']); unset($_SESSION['form_token_time']); $this->router->response()->json(array('success' => true)); } } catch (\Centreon\Internal\Exception $e) { $updateErrorMessage = $e->getMessage(); $this->router->response()->json(array('success' => false, 'error' => $updateErrorMessage)); } }
/** * * @param string $object * @param string $tag */ public function removeTagAction($object, $tag) { $iNbDeleted = 0; $sLibTag = "tag"; $repository = $this->repository; $sName = $this->objectName; $repository::transco($object); $aId = $repository::getListBySlugName($object[$sName]); if (count($aId) > 0) { $object = $aId[0]['id']; } else { throw new \Exception(static::OBJ_NOT_EXIST, 1); } $aTags = explode(",", $tag); foreach ($aTags as $sTag) { $iReturn = TagsRepository::isExist($sTag); $bLinked = TagsRepository::isLink($this->objectName, $object, $iReturn); if (!$bLinked) { throw new \Exception("This tag can't be found on the object", 1); } TagsRepository::delete($sTag, $this->objectName, $object); $iNbDeleted++; } if ($iNbDeleted > 1) { $sLibTag .= "s"; } InputOutput::display($sLibTag . " has been successfully removed from the object", true, 'green'); }