/**
  * Export
  *
  * @return void
  */
 public function export()
 {
     $elements = $this->object->getList("*", -1, 0, "service_template_model_stm_id", null, array("service_register" => $this->register), "AND");
     $templateTree = $this->sortTemplates($elements);
     $macroObj = new Centreon_Object_Service_Macro_Custom();
     $this->parseTemplateTree($templateTree);
     // contact groups
     $cgRel = new Centreon_Object_Relation_Contact_Group_Service();
     $elements = $cgRel->getMergedParameters(array("cg_name"), array('service_description'), -1, 0, null, null, array("service_register" => $this->register), "AND");
     foreach ($elements as $element) {
         echo $this->action . $this->delim . "addcontactgroup" . $this->delim . $element['service_description'] . $this->delim . $element['cg_name'] . "\n";
     }
     // contacts
     $contactRel = new Centreon_Object_Relation_Contact_Service();
     $elements = $contactRel->getMergedParameters(array("contact_name"), array('service_description'), -1, 0, null, null, array("service_register" => $this->register), "AND");
     foreach ($elements as $element) {
         echo $this->action . $this->delim . "addcontact" . $this->delim . $element['service_description'] . $this->delim . $element['contact_name'] . "\n";
     }
     // macros
     $macros = $macroObj->getList("*", -1, 0, null, null, array('svc_svc_id' => $element[$this->object->getPrimaryKey()]), "AND");
     foreach ($macros as $macro) {
         echo $this->action . $this->delim . "setmacro" . $this->delim . $element['service_description'] . $this->delim . $this->stripMacro($macro['svc_macro_name']) . $this->delim . $macro['svc_macro_value'] . "\n";
     }
     // traps
     $trapRel = new Centreon_Object_Relation_Trap_Service();
     $telements = $trapRel->getMergedParameters(array("traps_name"), array('service_description'), -1, 0, null, null, array("service_register" => $this->register), "AND");
     foreach ($telements as $telement) {
         echo $this->action . $this->delim . "addtrap" . $this->delim . $telement['service_description'] . $this->delim . $telement['traps_name'] . "\n";
     }
     // hosts
     $hostRel = new Centreon_Object_Relation_Host_Service();
     $helements = $hostRel->getMergedParameters(array("host_name"), array('service_description'), -1, 0, null, null, array("service_register" => $this->register), "AND");
     foreach ($helements as $helement) {
         echo $this->action . $this->delim . "addhost" . $this->delim . $helement['service_description'] . $this->delim . $helement['host_name'] . "\n";
     }
 }
 /**
  * Export
  *
  * @return void
  */
 public function export()
 {
     $hostRel = new Centreon_Object_Relation_Host_Service();
     $elements = $hostRel->getMergedParameters(array("host_name"), array('*'), -1, 0, null, null, array("service_register" => $this->register), "AND");
     $extendedObj = new Centreon_Object_Service_Extended();
     $commandObj = new Centreon_Object_Command();
     $tpObj = new Centreon_Object_Timeperiod();
     $macroObj = new Centreon_Object_Service_Macro_Custom();
     foreach ($elements as $element) {
         $addStr = $this->action . $this->delim . "ADD";
         foreach ($this->insertParams as $param) {
             $addStr .= $this->delim;
             if ($param == "service_template_model_stm_id") {
                 $tmp = $this->object->getParameters($element[$param], 'service_description');
                 if (isset($tmp) && isset($tmp['service_description']) && $tmp['service_description']) {
                     $element[$param] = $tmp['service_description'];
                 }
                 if (!$element[$param]) {
                     $element[$param] = "";
                 }
             }
             $addStr .= $element[$param];
         }
         $addStr .= "\n";
         echo $addStr;
         foreach ($element as $parameter => $value) {
             if (!in_array($parameter, $this->exportExcludedParams) && !is_null($value) && $value != "") {
                 if ($parameter == "timeperiod_tp_id" || $parameter == "timeperiod_tp_id2") {
                     $tmpObj = $tpObj;
                 } elseif ($parameter == "command_command_id" || $parameter == "command_command_id2") {
                     $tmpObj = $commandObj;
                 }
                 if (isset($tmpObj)) {
                     $tmp = $tmpObj->getParameters($value, $tmpObj->getUniqueLabelField());
                     if (isset($tmp) && isset($tmp[$tmpObj->getUniqueLabelField()])) {
                         $value = $tmp[$tmpObj->getUniqueLabelField()];
                     }
                     unset($tmpObj);
                 }
                 $value = CentreonUtils::convertLineBreak($value);
                 echo $this->action . $this->delim . "setparam" . $this->delim . $element['host_name'] . $this->delim . $element['service_description'] . $this->delim . $this->getClapiActionName($parameter) . $this->delim . $value . "\n";
             }
         }
         $params = $extendedObj->getParameters($element[$this->object->getPrimaryKey()], array("esi_notes", "esi_notes_url", "esi_action_url", "esi_icon_image", "esi_icon_image_alt"));
         if (isset($params) && is_array($params)) {
             foreach ($params as $k => $v) {
                 if (!is_null($v) && $v != "") {
                     $v = CentreonUtils::convertLineBreak($v);
                     echo $this->action . $this->delim . "setparam" . $this->delim . $element['host_name'] . $this->delim . $element['service_description'] . $this->delim . $this->getClapiActionName($k) . $this->delim . $v . "\n";
                 }
             }
         }
         $macros = $macroObj->getList("*", -1, 0, null, null, array('svc_svc_id' => $element[$this->object->getPrimaryKey()]), "AND");
         foreach ($macros as $macro) {
             echo $this->action . $this->delim . "setmacro" . $this->delim . $element['host_name'] . $this->delim . $element['service_description'] . $this->delim . $this->stripMacro($macro['svc_macro_name']) . $this->delim . $macro['svc_macro_value'] . "\n";
         }
         $cgRel = new Centreon_Object_Relation_Contact_Group_Service();
         $cgelements = $cgRel->getMergedParameters(array("cg_name"), array('service_description'), -1, 0, null, null, array("service_register" => $this->register, "service_id" => $element['service_id']), "AND");
         foreach ($cgelements as $cgelement) {
             echo $this->action . $this->delim . "addcontactgroup" . $this->delim . $element['host_name'] . $this->delim . $cgelement['service_description'] . $this->delim . $cgelement['cg_name'] . "\n";
         }
         $contactRel = new Centreon_Object_Relation_Contact_Service();
         $celements = $contactRel->getMergedParameters(array("contact_name"), array('service_description'), -1, 0, null, null, array("service_register" => $this->register, "service_id" => $element['service_id']), "AND");
         foreach ($celements as $celement) {
             echo $this->action . $this->delim . "addcontact" . $this->delim . $element['host_name'] . $this->delim . $celement['service_description'] . $this->delim . $celement['contact_name'] . "\n";
         }
         $trapRel = new Centreon_Object_Relation_Trap_Service();
         $telements = $trapRel->getMergedParameters(array("traps_name"), array('service_description'), -1, 0, null, null, array("service_register" => $this->register, "service.service_id" => $element['service_id']), "AND");
         foreach ($telements as $telement) {
             echo $this->action . $this->delim . "addtrap" . $this->delim . $element['host_name'] . $this->delim . $telement['service_description'] . $this->delim . $telement['traps_name'] . "\n";
         }
     }
 }