Beispiel #1
0
 public function testGetIdByParameter()
 {
     $testResult = array(2);
     $result = Host::getIdByParameter('host_name', 'Host 1');
     $this->assertEquals($testResult, $result);
     $testResult = array(2, 3);
     $result = Host::getIdByParameter('host_name', array('Host 1', 'Host 2'));
     $this->assertEquals($testResult, $result);
     $this->setExpectedException('PDOException', '', '42S22');
     Host::getIdByParameter('errColumn', 'Host');
 }
Beispiel #2
0
 /**
  * 
  * @param string $host_name
  * @return string
  */
 public static function getIconImage($host_name)
 {
     // Initializing connection
     $di = Di::getDefault();
     $dbconn = $di->get('db_centreon');
     $router = $di->get('router');
     $finalRoute = "";
     $templates = array();
     $alreadyProcessed = false;
     $hostIdTab = Host::getIdByParameter('host_name', array($host_name));
     if (count($hostIdTab) == 0) {
         $finalRoute = "<i class='icon-host ico-20'></i>";
     } else {
         $hostId = $hostIdTab[0];
     }
     $stmt = $dbconn->prepare("SELECT b.filename " . "FROM cfg_hosts h, cfg_hosts_images_relations hir, cfg_binaries b " . "WHERE h.host_id = :hostId " . "AND h.host_id = hir.host_id " . "AND hir.binary_id = b.binary_id");
     while (empty($finalRoute)) {
         $stmt->bindParam(':hostId', $hostId, \PDO::PARAM_INT);
         $stmt->execute();
         $ehiResult = $stmt->fetch(\PDO::FETCH_ASSOC);
         if (!is_null($ehiResult['filename'])) {
             $filenameExploded = explode('.', $ehiResult['filename']);
             $nbOfOccurence = count($filenameExploded);
             $fileFormat = $filenameExploded[$nbOfOccurence - 1];
             $filenameLength = strlen($ehiResult['filename']);
             $routeAttr = array('image' => substr($ehiResult['filename'], 0, $filenameLength - (strlen($fileFormat) + 1)), 'format' => '.' . $fileFormat);
             $imgSrc = $router->getPathFor('/uploads/[*:image][png|jpg|gif|jpeg:format]', $routeAttr);
             $finalRoute = '<img src="' . $imgSrc . '">';
         } else {
             if (count($templates) == 0 && !$alreadyProcessed) {
                 $templates = static::getTemplateChain($hostId, array(), -1);
                 $alreadyProcessed = true;
             } else {
                 if (count($templates) == 0 && $alreadyProcessed) {
                     $finalRoute = "<i class='icon-host ico-20'></i>";
                 }
             }
             $currentHost = array_shift($templates);
             $hostId = $currentHost['id'];
         }
     }
     return $finalRoute;
 }