Exemplo n.º 1
0
 /**
  * Add a tag to a resource
  *
  */
 public static function add($tagName, $resourceName, $resourceId, $bGlobal = 0, $iIdTemplate = '')
 {
     $resourceName = self::convertResource($resourceName);
     if (!in_array($resourceName, static::$resourceType)) {
         throw new Exception("This resource type does not support tags.");
     }
     if ($bGlobal == 0) {
         $userId = $_SESSION['user']->getId();
     } else {
         $userId = NULL;
     }
     $dbconn = Di::getDefault()->get('db_centreon');
     /* Get or create a tagname */
     try {
         $tagId = static::getTagId($tagName, $bGlobal);
     } catch (Exception $e) {
         $tagId = Tag::insert(array('user_id' => $userId, 'tagname' => $tagName));
     }
     /* Insert relation tag */
     if (!self::isLink($resourceName, $resourceId, $tagId)) {
         self::associateTagWithResource($resourceName, $tagId, $resourceId, $iIdTemplate);
     }
     return $tagId;
 }