cablingplan: put code to tab-indented Allman style
authorDenis Ovsienko <infrastation@yandex.ru>
Tue, 9 Apr 2013 19:18:20 +0000 (23:18 +0400)
committerDenis Ovsienko <infrastation@yandex.ru>
Tue, 9 Apr 2013 19:18:20 +0000 (23:18 +0400)
cablingplan/cablingplan.php

index 074b04b..482eac2 100644 (file)
@@ -15,9 +15,8 @@ This extension requires an installed PEAR Image-GraphViz module.
 
 require_once 'Image/GraphViz.php';
 
-if (isset($indexlayout)) {
-    array_push($indexlayout[2], 'cablingplan');
-}
+if (isset ($indexlayout))
+       array_push ($indexlayout[2], 'cablingplan');
 
 $page['cablingplan']['title'] = 'Cabling plan';
 $page['cablingplan']['parent'] = 'index';
@@ -30,87 +29,87 @@ $image['cablingplan']['path'] = 'pix/cablingplan.png';
 $image['cablingplan']['width'] = 218;
 $image['cablingplan']['height'] = 200;
 
-function showCablingPlan ()
+function showCablingPlan()
 {
-    // Show cabling plan image
-    echo "<img hspace='10' vspace='10' src='?module=rendercablingplan&format=png' />\n";
+       // Show cabling plan image
+       echo "<img hspace='10' vspace='10' src='?module=rendercablingplan&format=png' />\n";
 }
 
-function showCablingPlanSvg ()
+function showCablingPlanSvg()
 {
-    // Show cabling plan image
-    echo "<img hspace='10' vspace='10' src='?module=rendercablingplan&format=svg' />\n";
+       // Show cabling plan image
+       echo "<img hspace='10' vspace='10' src='?module=rendercablingplan&format=svg' />\n";
 }
 
-function renderCablingPlan ()
+function renderCablingPlan()
 {
-    // Build cabling plan
-
-    // Select edges
-    $sql = "SELECT oa.id AS source, ob.id AS target, CONCAT(pa.name, _utf8' <> ', pb.name) AS label, 0 AS weight " .
-    "FROM ((Link l JOIN Port pa ON l.porta = pa.id) JOIN RackObject oa ON pa.object_id = oa.id " .
-    "JOIN Port pb ON l.portb = pb.id JOIN RackObject ob ON pb.object_id = ob.id)";
-
-    $result = usePreparedSelectBlade($sql); 
-    $edges = array();
-    while ($row = $result->fetch (PDO::FETCH_ASSOC)) {
-        $found = false;
-        foreach ($edges as $key => $edge) {
-            if (($edge['source'] == $row['source']) && ($edge['target'] == $row['target'])) {
-                // Edge already exists ("Parallel"). Alter label and add weight
-                $edges[$key]['label'] .= "\n" . $row['label'];
-                $edges[$key]['weight']++;
-                $found = true;
-            }
-        }
-
-        if (!$found) {
-            $edges[] = $row;
-        }
-    }
-
-    // Select nodes
-    $sql = "SELECT DISTINCT o.id AS id, o.name AS label, '' AS url " .
-    "FROM Port p JOIN RackObject o ON p.object_id = o.id " .
-    "WHERE (p.id IN (SELECT Link.porta AS porta FROM Link) OR p.id IN " .
-    "(SELECT Link.portb AS portb FROM Link))";
-    $result = usePreparedSelectBlade($sql); 
-    $nodes = $result->fetchAll (PDO::FETCH_ASSOC);
-
-    $graph = new Image_GraphViz(
-        true, 
-        array(
-        ), 
-        'Cabling Plan', 
-        false, 
-        false
-    );
-
-    foreach ($nodes as $node) {
-        $graph->addNode(
-            $node['id'],
-            array(
-                'label' => $node['label'],
-                'shape' => 'box3d'
-            )
-        );
-    }
-
-    foreach ($edges as $edge) {
-        $graph->addEdge(
-            array($edge['source'] => $edge['target']),
-            array(
-                'label' => $edge['label'],
-                'weight' => floatval($edge['weight']),
-                'fontsize' => 8.0,
-                'arrowhead' => 'dot',
-                'arrowtail' => 'dot',
-                'arrowsize' => 0.5
-            )
-        );
-    }
-
-    if (in_array($_REQUEST['format'], array('svg', 'png'))) {
-        $graph->image($_REQUEST['format']);
-    }
+       // Build cabling plan
+
+       // Select edges
+       $sql = "SELECT oa.id AS source, ob.id AS target, CONCAT(pa.name, _utf8' <> ', pb.name) AS label, 0 AS weight " .
+               "FROM ((Link l JOIN Port pa ON l.porta = pa.id) JOIN RackObject oa ON pa.object_id = oa.id " .
+               "JOIN Port pb ON l.portb = pb.id JOIN RackObject ob ON pb.object_id = ob.id)";
+
+       $result = usePreparedSelectBlade ($sql);
+       $edges = array();
+       while ($row = $result->fetch (PDO::FETCH_ASSOC))
+       {
+               $found = FALSE;
+               foreach ($edges as $key => $edge)
+                       if (($edge['source'] == $row['source']) && ($edge['target'] == $row['target']))
+                       {
+                               // Edge already exists ("Parallel"). Alter label and add weight
+                               $edges[$key]['label'] .= "\n" . $row['label'];
+                               $edges[$key]['weight']++;
+                               $found = TRUE;
+                       }
+               if (! $found)
+                       $edges[] = $row;
+       }
+
+       // Select nodes
+       $sql = "SELECT DISTINCT o.id AS id, o.name AS label, '' AS url " .
+               "FROM Port p JOIN RackObject o ON p.object_id = o.id " .
+               "WHERE (p.id IN (SELECT Link.porta AS porta FROM Link) OR p.id IN " .
+               "(SELECT Link.portb AS portb FROM Link))";
+       $result = usePreparedSelectBlade ($sql);
+       $nodes = $result->fetchAll (PDO::FETCH_ASSOC);
+
+       $graph = new Image_GraphViz
+       (
+               TRUE,
+               array(),
+               'Cabling Plan',
+               FALSE,
+               FALSE
+       );
+
+       foreach ($nodes as $node)
+               $graph->addNode
+               (
+                       $node['id'],
+                       array
+                       (
+                               'label' => $node['label'],
+                               'shape' => 'box3d'
+                       )
+               );
+
+       foreach ($edges as $edge)
+               $graph->addEdge
+               (
+                       array ($edge['source'] => $edge['target']),
+                       array
+                       (
+                               'label' => $edge['label'],
+                               'weight' => floatval ($edge['weight']),
+                               'fontsize' => 8.0,
+                               'arrowhead' => 'dot',
+                               'arrowtail' => 'dot',
+                               'arrowsize' => 0.5
+                       )
+               );
+
+       if (in_array ($_REQUEST['format'], array ('svg', 'png')))
+               $graph->image ($_REQUEST['format']);
 }