Ignore:
Timestamp:
Apr 6, 2020, 11:17:40 PM (4 years ago)
Author:
chronos
Message:
  • Modified: Improved code format.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/NetworkTopology/topologie2.php

    r858 r873  
    2929    $Hosts = array();
    3030    $DbResult = $Database->select('hosts', 'id, name, ip, parent, online', 'used=1');
    31     while($DbRow = $DbResult->fetch_array())
     31    while ($DbRow = $DbResult->fetch_array())
    3232    {
    33       if(!array_key_exists($DbRow['id'], $Hosts)) $Hosts[$DbRow['id']] = array('subitems' => array());
     33      if (!array_key_exists($DbRow['id'], $Hosts)) $Hosts[$DbRow['id']] = array('subitems' => array());
    3434      $Hosts[$DbRow['id']] = array('id' => $DbRow['id'], 'name' => $DbRow['name'], 'parent' => $DbRow['parent'], 'online' => $DbRow['online'], 'subitems' => $Hosts[$DbRow['id']]['subitems']);
    35       if(!array_key_exists($DbRow['parent'], $Hosts)) $Hosts[$DbRow['parent']] = array('subitems' => array());
     35      if (!array_key_exists($DbRow['parent'], $Hosts)) $Hosts[$DbRow['parent']] = array('subitems' => array());
    3636      $Hosts[$DbRow['parent']]['subitems'][] = &$Hosts[$DbRow['id']];
    3737      $Hosts[$DbRow['id']]['parent_node'] = &$Hosts[$DbRow['parent']];
     
    4444  {
    4545    $Result = array('min' => $Host['displacement'], 'max' => $Host['displacement']);
    46     foreach($Host['subitems'] as $Index => $SubHost)
     46    foreach ($Host['subitems'] as $Index => $SubHost)
    4747    {
    4848      $SubitemResult = $this->CalculateDimension($Host['subitems'][$Index]);
     
    5050      $Result['max'] = max($SubitemResult['max'], $Result['max']);
    5151    }
    52     return($Result);
     52    return ($Result);
    5353  }
    5454
    5555  function CalculateDisplacement(&$Host, $Level = 0)
    5656  {
    57     if(!array_key_exists('displacement', $Host)) $Host['displacement'] = 0;
     57    if (!array_key_exists('displacement', $Host)) $Host['displacement'] = 0;
    5858    $Host['level'] = $Level;
    59     foreach($Host['subitems'] as $Index => $SubHost)
     59    foreach ($Host['subitems'] as $Index => $SubHost)
    6060    {
    6161      $Host['subitems'][$Index]['rel_displacement'] = (-(count($Host['subitems']) - 1) * 0.5 + $Index) * $this->HostWidth;
     
    6868  {
    6969    $Host['displacement'] = $Host['displacement'] + $Displacement;
    70     foreach($Host['subitems'] as $Index => $SubHost)
     70    foreach ($Host['subitems'] as $Index => $SubHost)
    7171    {
    7272      $this->MoveNode($Host['subitems'][$Index], $Displacement);
     
    7676  function CheckColision()
    7777  {
    78     foreach($this->Levels as $Index => $Level)
     78    foreach ($this->Levels as $Index => $Level)
    7979    {
    80       for($I = 0; $I < count($Level) - 1; $I++)
    81         if($Level[$I]['displacement'] >= $Level[$I + 1]['displacement'])
     80      for ($I = 0; $I < count($Level) - 1; $I++)
     81        if ($Level[$I]['displacement'] >= $Level[$I + 1]['displacement'])
    8282        {
    8383          // Search for common parent
    8484          $LeftHost = $Level[$I];
    8585          $RightHost = $Level[$I + 1];
    86           while(($LeftHost['level'] > 0) and ($LeftHost['parent'] != $RightHost['parent']))
     86          while (($LeftHost['level'] > 0) and ($LeftHost['parent'] != $RightHost['parent']))
    8787          {
    8888            $LeftHost = $LeftHost['parent_node'];
     
    9191          $Host = $RightHost['parent_node']['subitems'][0];
    9292          $II = 0;
    93           while($RightHost['parent_node']['subitems'][$II]['id'] != $RightHost['id']) $II++;
    94           while($II < count($RightHost['parent_node']['subitems']))
     93          while ($RightHost['parent_node']['subitems'][$II]['id'] != $RightHost['id']) $II++;
     94          while ($II < count($RightHost['parent_node']['subitems']))
    9595          {
    9696            $this->MoveNode($RightHost['parent_node']['subitems'][$II], $Level[$I]['displacement'] - $Level[$I + 1]['displacement']);
     
    104104  {
    105105    $this->Levels[$Host['level']][] = &$Host;
    106     foreach($Host['subitems'] as $Index => $SubHost)
     106    foreach ($Host['subitems'] as $Index => $SubHost)
    107107    {
    108108      $this->BuildLevels($Host['subitems'][$Index]);
     
    113113  {
    114114    $ParentHostPos = array('x' => -$this->RelPos['min'] + $Host['displacement'], 'y' => $Host['level'] * $this->HostHeight);
    115     foreach($Host['subitems'] as $Index => $SubHost)
     115    foreach ($Host['subitems'] as $Index => $SubHost)
    116116    {
    117117      $HostPos = array('x' => -$this->RelPos['min'] + $SubHost['displacement'], 'y' => $SubHost['level'] * $this->HostHeight);
Note: See TracChangeset for help on using the changeset viewer.