/**
  * Add a contact
  *
  * @param string $parameters
  * @return void
  * @throws CentreonClapiException
  */
 public function add($parameters)
 {
     $params = explode($this->delim, $parameters);
     if (count($params) < $this->nbOfCompulsoryParams) {
         throw new CentreonClapiException(self::MISSINGPARAMETER);
     }
     $addParams = array();
     $addParams[$this->object->getUniqueLabelField()] = $params[self::ORDER_UNIQUENAME];
     $addParams['host_alias'] = $params[self::ORDER_ALIAS];
     $addParams['host_address'] = $params[self::ORDER_ADDRESS];
     $templates = explode("|", $params[self::ORDER_TEMPLATE]);
     $templateIds = array();
     foreach ($templates as $template) {
         if ($template) {
             $tmp = $this->object->getIdByParameter($this->object->getUniqueLabelField(), $template);
             if (count($tmp)) {
                 $templateIds[] = $tmp[0];
             } else {
                 throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $template);
             }
         }
     }
     $instanceName = $params[self::ORDER_POLLER];
     $instanceObject = new Centreon_Object_Instance();
     if ($this->action == "HOST") {
         if ($instanceName) {
             $tmp = $instanceObject->getIdByParameter($instanceObject->getUniqueLabelField(), $instanceName);
             if (!count($tmp)) {
                 throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $instanceName);
             }
             $instanceId = $tmp[0];
         } else {
             throw new CentreonClapiException(self::MISSING_INSTANCE);
         }
     }
     $hostgroups = explode("|", $params[self::ORDER_HOSTGROUP]);
     $hostgroupIds = array();
     $hostgroupObject = new Centreon_Object_Host_Group();
     foreach ($hostgroups as $hostgroup) {
         if ($hostgroup) {
             $tmp = $hostgroupObject->getIdByParameter($hostgroupObject->getUniqueLabelField(), $hostgroup);
             if (count($tmp)) {
                 $hostgroupIds[] = $tmp[0];
             } else {
                 throw new CentreonClapiException(self::OBJECT_NOT_FOUND . ":" . $hostgroup);
             }
         }
     }
     $this->params = array_merge($this->params, $addParams);
     $this->checkParameters();
     $hostId = parent::add();
     $i = 1;
     $templateRelationObject = new Centreon_Object_Relation_Host_Template_Host();
     foreach ($templateIds as $templateId) {
         $templateRelationObject->insert($templateId, $hostId, $i);
         $i++;
     }
     $hostgroupRelationObject = new Centreon_Object_Relation_Host_Group_Host();
     foreach ($hostgroupIds as $hostgroupId) {
         $hostgroupRelationObject->insert($hostgroupId, $hostId);
     }
     if (isset($instanceId)) {
         $instanceRelationObject = new Centreon_Object_Relation_Instance_Host();
         $instanceRelationObject->insert($instanceId, $hostId);
     }
     $extended = new Centreon_Object_Host_Extended();
     $extended->insert(array($extended->getUniqueLabelField() => $hostId));
 }
 /**
  * Export
  *
  * @return void
  */
 public function export()
 {
     parent::export();
     $relObj = new Centreon_Object_Relation_Host_Group_Host();
     $hostObj = new Centreon_Object_Host();
     $hgFieldName = $this->object->getUniqueLabelField();
     $hFieldName = $hostObj->getUniqueLabelField();
     $elements = $relObj->getMergedParameters(array($hgFieldName), array($hFieldName), -1, 0, $hgFieldName, null);
     foreach ($elements as $element) {
         echo $this->action . $this->delim . "addhost" . $this->delim . $element[$hgFieldName] . $this->delim . $element[$hFieldName] . "\n";
     }
 }