Exemple #1
0
 /**
  * Get template chain ordinated in tree (id, text) 
  *
  * @param int $hostId The host or host template Id
  * @param array $alreadyProcessed The host templates already processed
  * @param int $depth The depth to search
  * @return array
  */
 public static function getTemplateChainTree($hostId, $depth = -1)
 {
     $templates = array();
     $db = Di::getDefault()->get('db_centreon');
     $router = Di::getDefault()->get('router');
     $sql = "SELECT h.* " . " FROM cfg_hosts h, cfg_hosts_templates_relations htr" . " WHERE h.host_id=htr.host_tpl_id" . " AND htr.host_host_id=:host_id" . " AND host_activate = '1'" . " AND host_register = '0'" . " ORDER BY `order` ASC";
     $stmt = $db->prepare($sql);
     $stmt->bindParam(':host_id', $hostId, \PDO::PARAM_INT);
     $stmt->execute();
     $row = $stmt->fetchAll();
     foreach ($row as $template) {
         $templatesTmp = self::formatDataForSlider($template);
         $templatesTmp['url_edit'] = $router->getPathFor('/centreon-configuration/hosttemplate/' . $template['host_id']);
         $templatesTmp['icon'] = self::getIconImagePath($template['host_id']);
         $templatesTmp['servicesTemplate'] = HostTemplateRepository::getRelationsCustom("\\CentreonConfiguration\\Models\\Relation\\Hosttemplate\\Servicetemplate", $template['host_id']);
         $templatesTmp['templates'] = self::getTemplateChainTree($template['host_id'], $depth);
         $templates[] = $templatesTmp;
     }
     return $templates;
 }