/**
  * Set parameters
  *
  * @param string $parameters
  * @return void
  * @throws CentreonClapiException
  */
 public function setparam($parameters = null)
 {
     $params = explode($this->delim, $parameters);
     if (count($params) < self::NB_UPDATE_PARAMS) {
         throw new CentreonClapiException(self::MISSINGPARAMETER);
     }
     $serviceDesc = $params[0];
     $elements = $this->object->getList("service_id", -1, 0, null, null, array('service_description' => $serviceDesc, 'service_register' => 0), "AND");
     if (!count($elements)) {
         throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $serviceDesc);
     }
     $objectId = $elements[0]['service_id'];
     $extended = false;
     $commandObject = new CentreonCommand();
     switch ($params[1]) {
         case "check_command":
             $params[1] = "command_command_id";
             $params[2] = $commandObject->getId($params[2]);
             break;
         case "check_command_arguments":
             $params[1] = "command_command_id_arg";
             break;
         case "event_handler":
             $params[1] = "command_command_id2";
             $params[2] = $commandObject->getId($params[2]);
             break;
         case "event_handler_arguments":
             $params[1] = "command_command_id_arg2";
             break;
         case "check_period":
             $params[1] = "timeperiod_tp_id";
             $tpObj = new CentreonTimePeriod();
             $params[2] = $tpObj->getTimeperiodId($params[2]);
             break;
         case "notification_period":
             $params[1] = "timeperiod_tp_id2";
             $tpObj = new CentreonTimePeriod();
             $params[2] = $tpObj->getTimeperiodId($params[2]);
             break;
         case "flap_detection_options":
             break;
         case "template":
             $params[1] = "service_template_model_stm_id";
             $tmp = $this->object->getList($this->object->getPrimaryKey(), -1, 0, null, null, array('service_description' => $params[2], 'service_register' => '0'), "AND");
             if (!count($tmp)) {
                 throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[2]);
             }
             $params[2] = $tmp[0][$this->object->getPrimaryKey()];
             break;
         case "graphtemplate":
             $extended = true;
             $graphObj = new Centreon_Object_Graph_Template();
             $tmp = $graphObj->getIdByParameter($graphObj->getUniqueLabelField(), $params[2]);
             if (!count($tmp)) {
                 throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[2]);
             }
             $params[1] = "graph_id";
             $params[2] = $tmp[0];
             break;
         case "contact_additive_inheritance":
             break;
         case "cg_additive_inheritance":
             break;
         case "notes":
             $extended = true;
             break;
         case "notes_url":
             $extended = true;
             break;
         case "action_url":
             $extended = true;
             break;
         case "icon_image":
             $extended = true;
             break;
         case "icon_image_alt":
             $extended = true;
             break;
         default:
             if (!preg_match("/^service_/", $params[1])) {
                 $params[1] = "service_" . $params[1];
             }
             break;
     }
     if ($extended == false) {
         $updateParams = array($params[1] => $params[2]);
         parent::setparam($objectId, $updateParams);
     } else {
         if ($params[1] != "graph_id") {
             $params[1] = "esi_" . $params[1];
             if ($params[1] == "esi_icon_image") {
                 if ($params[2]) {
                     $id = CentreonUtils::getImageId($params[2]);
                     if (is_null($id)) {
                         throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[2]);
                     }
                     $params[2] = $id;
                 } else {
                     $params[2] = null;
                 }
             }
         }
         $extended = new Centreon_Object_Service_Extended();
         $extended->update($objectId, array($params[1] => $params[2]));
     }
 }
 /**
  * This method get the macro attached to the host
  * 
  * @param int $iHostId
  * @param int $bIsTemplate
  * @param array $aListTemplate
  * @param int $iIdCommande
  * @return array
  */
 public function getMacros($iHostId, $bIsTemplate, $aListTemplate, $iIdCommande)
 {
     $aMacro = array();
     $macroArray = array();
     $aMacroInCommande = array();
     $aMacroInService = array();
     //Get macro attached to the host
     $macroArray = $this->getCustomMacroInDb($iHostId);
     //Get macro attached to the template
     $aMacroTemplate = array();
     foreach ($aListTemplate as $template) {
         if (!empty($template['host_id'])) {
             $aMacroTemplate[] = $this->getCustomMacroInDb($template['host_id'], $template);
         }
     }
     if (empty($iIdCommande)) {
         foreach ($aListTemplate as $template) {
             if (!empty($template['command_command_id'])) {
                 $iIdCommande = $template['command_command_id'];
                 break;
             }
         }
     }
     //Get macro attached to the command
     if (!empty($iIdCommande)) {
         $oCommand = new CentreonCommand($this->db);
         $aMacroInCommande[] = $oCommand->getMacroByIdAndType($iIdCommande, 'host');
     }
     //filter a macro
     $aTempMacro = array();
     if (count($macroArray) > 0) {
         foreach ($macroArray as $directMacro) {
             $directMacro['macroOldValue'] = $directMacro["host_macro_value"];
             $directMacro['macroFrom'] = 'direct';
             $directMacro['source'] = 'direct';
             $aTempMacro[] = $directMacro;
         }
     }
     if (count($aMacroTemplate) > 0) {
         foreach ($aMacroTemplate as $key => $macr) {
             foreach ($macr as $mm) {
                 $mm['macroOldValue'] = $mm["host_macro_value"];
                 $mm['macroFrom'] = 'fromTpl';
                 $mm['source'] = 'fromTpl';
                 $aTempMacro[] = $mm;
             }
         }
     }
     if (count($aMacroInCommande) > 0) {
         $macroCommande = current($aMacroInCommande);
         for ($i = 0; $i < count($macroCommande); $i++) {
             $macroCommande[$i]['macroOldValue'] = $macroCommande[$i]["host_macro_value"];
             $macroCommande[$i]['macroFrom'] = 'fromCommand';
             $macroCommande[$i]['source'] = 'fromCommand';
             $aTempMacro[] = $macroCommande[$i];
         }
     }
     $aFinalMacro = $this->macro_unique($aTempMacro);
     return $aFinalMacro;
 }
 /**
  * Set parameters
  *
  * @param string $parameters
  * @return void
  * @throws CentreonClapiException
  */
 public function setparam($parameters = null)
 {
     $params = explode($this->delim, $parameters);
     if (count($params) < self::NB_UPDATE_PARAMS) {
         throw new CentreonClapiException(self::MISSINGPARAMETER);
     }
     if (($objectId = $this->getObjectId($params[self::ORDER_UNIQUENAME])) != 0) {
         $extended = false;
         $commandObject = new CentreonCommand();
         switch ($params[1]) {
             case "check_command":
                 $params[1] = "command_command_id";
                 $params[2] = $commandObject->getId($params[2]);
                 break;
             case "check_command_arguments":
                 $params[1] = "command_command_id_arg1";
                 break;
             case "event_handler":
                 $params[1] = "command_command_id2";
                 $params[2] = $commandObject->getId($params[2]);
                 break;
             case "event_handler_arguments":
                 $params[1] = "command_command_id_arg2";
                 break;
             case "check_period":
                 $params[1] = "timeperiod_tp_id";
                 $tpObj = new CentreonTimePeriod();
                 $params[2] = $tpObj->getTimeperiodId($params[2]);
                 break;
             case "notification_period":
                 $params[1] = "timeperiod_tp_id2";
                 $tpObj = new CentreonTimePeriod();
                 $params[2] = $tpObj->getTimeperiodId($params[2]);
                 break;
             case "contact_additive_inheritance":
                 break;
             case "cg_additive_inheritance":
                 break;
             case "flap_detection_options":
                 break;
             case "notes":
                 $extended = true;
                 break;
             case "notes_url":
                 $extended = true;
                 break;
             case "action_url":
                 $extended = true;
                 break;
             case "icon_image":
                 $extended = true;
                 break;
             case "icon_image_alt":
                 $extended = true;
                 break;
             case "vrml_image":
                 $extended = true;
                 break;
             case "statusmap_image":
                 $extended = true;
                 break;
             case "2d_coords":
                 $extended = true;
                 break;
             case "3d_coords":
                 $extended = true;
                 break;
             default:
                 if (!preg_match("/^host_/", $params[1])) {
                     $params[1] = "host_" . $params[1];
                 }
                 break;
         }
         if ($extended == false) {
             $updateParams = array($params[1] => $params[2]);
             parent::setparam($objectId, $updateParams);
         } else {
             $params[1] = "ehi_" . $params[1];
             if ($params[1] == "ehi_icon_image" || $params[1] == "ehi_statusmap_image" || $params[1] == "ehi_vrml_image") {
                 if ($params[2]) {
                     $id = CentreonUtils::getImageId($params[2]);
                     if (is_null($id)) {
                         throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[2]);
                     }
                     $params[2] = $id;
                 } else {
                     $params[2] = null;
                 }
             }
             $extended = new Centreon_Object_Host_Extended();
             $extended->update($objectId, array($params[1] => $params[2]));
         }
     } else {
         throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $params[self::ORDER_UNIQUENAME]);
     }
 }
 /**
  * This method get the macro attached to the service
  * 
  * @param int $iServiceId
  * @param array $aListTemplate
  * @param int $iIdCommande
  * 
  * @return array
  */
 public function getMacros($iServiceId, $aListTemplate, $iIdCommande)
 {
     $aMacro = array();
     $macroArray = array();
     $aMacroInService = array();
     //Get macro attached to the service
     $macroArray = $this->getCustomMacroInDb($iServiceId);
     $iNb = count($macroArray);
     //Get macro attached to the template
     $aMacroTemplate = array();
     // clear current template/service from the list.
     unset($aListTemplate[count($aListTemplate) - 1]);
     foreach ($aListTemplate as $template) {
         if (!empty($template)) {
             $aMacroTemplate[] = $this->getCustomMacroInDb($template['service_id'], $template);
         }
     }
     if (empty($iIdCommande)) {
         foreach ($aListTemplate as $template) {
             if (!empty($template['command_command_id'])) {
                 $iIdCommande = $template['command_command_id'];
             }
         }
     }
     //Get macro attached to the command
     if (!empty($iIdCommande)) {
         $oCommand = new CentreonCommand($this->db);
         $aMacroInService[] = $oCommand->getMacroByIdAndType($iIdCommande, 'service');
     }
     //filter a macro
     $aTempMacro = array();
     $serv = current($aMacroInService);
     if (count($aMacroInService) > 0) {
         for ($i = 0; $i < count($serv); $i++) {
             $serv[$i]['macroOldValue_#index#'] = $serv[$i]["svc_macro_value"];
             $serv[$i]['macroFrom_#index#'] = 'fromService';
             $serv[$i]['source'] = 'fromService';
             $aTempMacro[] = $serv[$i];
         }
     }
     if (count($aMacroTemplate) > 0) {
         foreach ($aMacroTemplate as $key => $macr) {
             foreach ($macr as $mm) {
                 $mm['macroOldValue_#index#'] = $mm["svc_macro_value"];
                 $mm['macroFrom_#index#'] = 'fromTpl';
                 $mm['source'] = 'fromTpl';
                 $aTempMacro[] = $mm;
             }
         }
     }
     if (count($macroArray) > 0) {
         foreach ($macroArray as $directMacro) {
             $directMacro['macroOldValue_#index#'] = $directMacro["svc_macro_value"];
             $directMacro['macroFrom_#index#'] = 'direct';
             $directMacro['source'] = 'direct';
             $aTempMacro[] = $directMacro;
         }
     }
     $aFinalMacro = $this->macro_unique($aTempMacro);
     return $aFinalMacro;
 }