Changeset 626 for trunk/Modules/Search


Ignore:
Timestamp:
Dec 4, 2013, 9:50:16 PM (11 years ago)
Author:
chronos
Message:
  • Modified: Search page generalized as dynamic configurable list. Other modules can register their search ability.
  • Modified: If sarch is invoked on some module then filter is added to table. Filter have to be disabled to view all items again.
  • Added: Shoutbox can be searched.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Search/Search.php

    r595 r626  
    1414                $this->Description = 'Allow test search in other modules content.';
    1515                $this->Dependencies = array();
     16                $this->SearchItems = array();
    1617        }
    1718
     
    2122        }
    2223       
    23         function RegisterContent($Name, $Columns, $Query)
     24        function RegisterSearch($Name, $Title, $Columns, $Query, $Link)
    2425        {
    25           $this->SearchItems[$Name] = array('Columns' => $Columns, 'Query' => $Query); 
     26                // Query can be table name or subselect query
     27          $this->SearchItems[$Name] = array('Name' => $Title, 'Columns' => $Columns,
     28      'Query' => $Query, 'Link' => $Link);     
    2629        }
    2730
    28         function UnregisterContent($Name)
     31        function UnregisterSearch($Name)
    2932        {
    3033          unset($this->SearchItems[$Name]);     
     
    3639        function Show()
    3740        {
    38                 global $TranslationTree;
    39        
    4041                if(array_key_exists('text', $_GET)) $Search = $_GET['text'];
    4142                else if(array_key_exists('text', $_POST)) $Search = $_POST['text'];
    4243                else $Search = '';
    4344                $SearchHTML = htmlentities($Search);
    44        
    45                 $Output = '<table class="BaseTable"><tr><th>Skupina</th><th>Výsledků</th></tr>';
    46                 foreach($TranslationTree as $Group)
     45               
     46                $Output = '<table class="BaseTable"><tr><th>'.T('Section').'</th><th>'.T('Found count').'</th></tr>';
     47                foreach($this->System->ModuleManager->Modules['Search']->SearchItems as $SearchItem)
    4748                {
    48                         $Table = $Group['TablePrefix'];
    49        
    50                         $sql = 'SELECT COUNT(*) FROM `'.$Table.'` WHERE '.
    51                                         ' (`ID` LIKE "%'.$Search.'%")'.
    52                                         ' OR (`Entry` LIKE "%'.$Search.'%")';
    53                         foreach($Group['Items'] as $Item)
     49                        $ColumnQuery = array();
     50                        foreach($SearchItem['Columns'] as $Column)
    5451                        {
    55                                 if($Item['Column'] != '') $sql .= ' OR (`'.$Item['Column'].'` LIKE "%'.$Search.'%")';
    56                         }
    57                         $DbResult = $this->Database->query($sql);
    58                         $Line = $DbResult->fetch_row();
    59                         if ($Line[0] <> '0')
    60                           $Output .= '<tr><td><a href="'.$this->System->Link('/TranslationList.php?group='.
    61                           $Group['Id'].'&amp;user=0&amp;state=0&amp;text='.$SearchHTML.'&amp;entry=').'">'.
    62                           $Group['Name'].'</a></td><td>'.$Line[0].'</td></tr>';
     52                          $ColumnQuery[] = '(`'.$Column.'` LIKE "%'.$Search.'%")';
     53                  }
     54                  $ColumnQuery = implode(' OR ', $ColumnQuery);
     55                  if($SearchItem['Query'] != '')
     56                  {
     57                    $DbResult = $this->Database->query('SELECT COUNT(*) FROM '.$SearchItem['Query'].' WHERE '.$ColumnQuery);
     58                  $Line = $DbResult->fetch_row();
     59                  $Line = $Line[0];
     60                  } else $Line = '';
     61                $Output .= '<tr><td><a href="'.$SearchItem['Link'].$SearchHTML.'">'.$SearchItem['Name'].'</a></td><td>'.$Line.'</td></tr>';
    6362                }
    64        
    65                 $DbResult = $this->Database->query('SELECT count(*) FROM `User` WHERE `Name` LIKE "%'.$Search.'%"');
    66                 $Line = $DbResult->fetch_row();
    67                 $Output .= '<tr><td><a href="'.$this->System->Link('/userlist.php?search='.$SearchHTML).'">Uživatelé</a></td><td>'.$Line[0].'</td></tr>';
    68        
    69                 $DbResult = $this->Database->query('SELECT count(*) FROM `Team` WHERE `Name` LIKE "%'.$Search.'%" OR `Description` LIKE "%'.$Search.'%"');
    70                 $Line = $DbResult->fetch_row();
    71                 $Output .= '<tr><td><a href="'.$this->System->Link('/team/?search='.$SearchHTML).'">Týmy</a></td><td>'.$Line[0].'</td></tr>';
    72        
    73                 $DbResult = $this->Database->query('SELECT count(*) FROM `CzWoWPackageVersion` WHERE `Text` LIKE "%'.$Search.'%"');
    74                 $Line = $DbResult->fetch_row();
    75                 $Output .= '<tr><td><a href="'.$this->System->Link('/download.php?addon').'">Čeština pro klienta</a></td><td>'.$Line[0].'</td></tr>';
    76                 $Output .= '<tr><td><a href="'.$this->System->Link('/aowow/?search='.$SearchHTML).'">Vyhledávací databáze AoWoW</a></td></tr>';
    77        
    78                 $DbResult = $this->Database->query('SELECT count(*) FROM `Dictionary` WHERE '.
    79                         '(`Text` LIKE "%'.$Search.'%" OR `Description` LIKE "%'.$Search.'%") AND `Language` = '.$this->System->Config['OriginalLanguage']);
    80                 $Line = $DbResult->fetch_row();
    81                 $Output .= '<tr><td><a href="'.$this->System->Link('/dictionary/?search='.$SearchHTML).
    82       '">Slovníček</a></td><td>'.$Line[0].'</td></tr>';
    83        
    84                 $Output .= '</table>';
     63 
     64        $Output .= '</table>';
    8565                return($Output);
    8666        }
Note: See TracChangeset for help on using the changeset viewer.