r2760 - getRackSearchResult(): another variation of a standard helper (cloned from...
authorDenis Ovsienko <infrastation@yandex.ru>
Sat, 16 May 2009 16:06:24 +0000 (16:06 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Sat, 16 May 2009 16:06:24 +0000 (16:06 +0000)
 - renderCell(): initial implementation in the 'rack' realm
 - renderSearchResults(): enable searching the 'rack' realm

inc/database.php
inc/interface.php

index f0c554bf0d42684075a7d976294ee9391c3c8c5a..1c1b83000a98755f22ecb66e97515af59d93ab25 100644 (file)
@@ -1578,7 +1578,7 @@ function getAccountSearchResult ($terms)
 
 function getFileSearchResult ($terms)
 {
-       $byFilename = getSearchResultByField
+       $byName = getSearchResultByField
        (
                'File',
                array ('id'),
@@ -1595,7 +1595,7 @@ function getFileSearchResult ($terms)
                'name'
        );
        // Filter out dupes.
-       foreach ($byFilename as $res1)
+       foreach ($byName as $res1)
                foreach (array_keys ($byComment) as $key2)
                        if ($res1['id'] == $byComment[$key2]['id'])
                        {
@@ -1603,11 +1603,43 @@ function getFileSearchResult ($terms)
                                continue 2;
                        }
        $ret = array();
-       foreach (array_merge ($byFilename, $byComment) as $row)
+       foreach (array_merge ($byName, $byComment) as $row)
                $ret[] = spotEntity ('file', $row['id']);
        return $ret;
 }
 
+function getRackSearchResult ($terms)
+{
+       $byName = getSearchResultByField
+       (
+               'Rack',
+               array ('id'),
+               'name',
+               $terms,
+               'name'
+       );
+       $byComment = getSearchResultByField
+       (
+               'Rack',
+               array ('id'),
+               'comment',
+               $terms,
+               'name'
+       );
+       // Filter out dupes.
+       foreach ($byName as $res1)
+               foreach (array_keys ($byComment) as $key2)
+                       if ($res1['id'] == $byComment[$key2]['id'])
+                       {
+                               unset ($byComment[$key2]);
+                               continue 2;
+                       }
+       $ret = array();
+       foreach (array_merge ($byName, $byComment) as $row)
+               $ret[] = spotEntity ('rack', $row['id']);
+       return $ret;
+}
+
 function getSearchResultByField ($tname, $rcolumns, $scolumn, $terms, $ocolumn = '')
 {
        $pfx = '';
index 0e3ef1904fecad924ef83fd50c05cb96955b985c..b4669af85a2b5e4ac6c283631217cc3ebae4a3d8 100644 (file)
@@ -2965,6 +2965,13 @@ function renderSearchResults ()
                        $lasthit = 'file';
                        $summary['file'] = $tmp;
                }
+               $tmp = getRackSearchResult ($terms);
+               if (count ($tmp))
+               {
+                       $nhits += count ($tmp);
+                       $lasthit = 'rack';
+                       $summary['rack'] = $tmp;
+               }
        }
        if ($nhits == 0)
                echo "<center><h2>Nothing found for '${terms}'</h2></center>";
@@ -3012,6 +3019,9 @@ function renderSearchResults ()
                        case 'file':
                                echo "<script language='Javascript'>document.location='${root}?page=file&file_id=${record['id']}';//</script>";
                                break;
+                       case 'rack':
+                               echo "<script language='Javascript'>document.location='${root}?page=rack&rack_id=${record['id']}';//</script>";
+                               break;
                }
                return;
        }
@@ -3125,6 +3135,19 @@ function renderSearchResults ()
                                        echo '</table>';
                                        finishPortlet();
                                        break;
+                               case 'rack':
+                                       startPortlet ("<a href='${root}?page=rackspace'>Racks</a>");
+                                       echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
+                                       foreach ($what as $cell)
+                                       {
+                                               echo "<tr class=row_${order}><td class=tdleft>";
+                                               renderCell ($cell);
+                                               echo "</td></tr>";
+                                               $order = $nextorder[$order];
+                                       }
+                                       echo '</table>';
+                                       finishPortlet();
+                                       break;
                        }
        }
 }
@@ -5631,6 +5654,20 @@ function renderCell ($cell)
                echo count ($cell['etags']) ? ("<small>" . serializeTags ($cell['etags']) . "</small>") : '&nbsp;';
                echo "</td></tr></table>";
                break;
+       case 'rack':
+               echo "<table class='slbcell vscell'><tr><td rowspan=3 width='5%'>";
+               $thumbwidth = getRackImageWidth();
+               $thumbheight = getRackImageHeight ($cell['height']);
+               echo "<img border=0 width=${thumbwidth} height=${thumbheight} title='${cell['height']} units' ";
+               echo "src='render_image.php?img=minirack&rack_id=${cell['id']}'>";
+               echo "</td><td>";
+               printf ("<a href='${root}?page=rack&rack_id=%s'><strong>%s</strong></a>", $cell['id'], niftyString ($cell['name']));
+               echo "</td></tr><tr><td>";
+               echo count ($cell['etags']) ? ("<small>" . serializeTags ($cell['etags']) . "</small>") : '&nbsp;';
+               echo "</td></tr><tr><td>";
+               echo niftyString ($cell['comment']);
+               echo "</td></tr></table>";
+               break;
        default:
                showError ('odd data', __FUNCTION__);
                break;