Changeset 816 for trunk/Modules/Search


Ignore:
Timestamp:
Feb 22, 2015, 11:20:50 PM (10 years ago)
Author:
chronos
Message:
  • Modified: Tabs converted to spaces.
  • Modified: Remove spaces from end of lines.
  • Added: Code format script.
File:
1 edited

Legend:

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

    r760 r816  
    33class ModuleSearch extends AppModule
    44{
    5         var $SearchItems;
    6        
    7         function __construct($System)
    8         {
    9                 parent::__construct($System);
    10                 $this->Name = 'Search';
    11                 $this->Version = '1.0';
    12                 $this->Creator = 'Chronos';
    13                 $this->License = 'GNU/GPL';
    14                 $this->Description = 'Allow test search in other modules content.';
    15                 $this->Dependencies = array();
    16                 $this->SearchItems = array();
    17         }
     5  var $SearchItems;
    186
    19         function Start()
    20         {
    21                 $this->System->RegisterPage('search', 'PageSearch');
    22         }
    23        
    24         function RegisterSearch($Name, $Title, $Columns, $Query, $Link)
    25         {
    26                 // Query can be table name or subselect query
    27           $this->SearchItems[$Name] = array('Name' => $Title, 'Columns' => $Columns,
    28       'Query' => $Query, 'Link' => $Link);     
    29         }
     7  function __construct($System)
     8  {
     9    parent::__construct($System);
     10    $this->Name = 'Search';
     11    $this->Version = '1.0';
     12    $this->Creator = 'Chronos';
     13    $this->License = 'GNU/GPL';
     14    $this->Description = 'Allow test search in other modules content.';
     15    $this->Dependencies = array();
     16    $this->SearchItems = array();
     17  }
    3018
    31         function UnregisterSearch($Name)
    32         {
    33           unset($this->SearchItems[$Name]);     
    34         }
     19  function Start()
     20  {
     21    $this->System->RegisterPage('search', 'PageSearch');
     22  }
     23
     24  function RegisterSearch($Name, $Title, $Columns, $Query, $Link)
     25  {
     26    // Query can be table name or subselect query
     27    $this->SearchItems[$Name] = array('Name' => $Title, 'Columns' => $Columns,
     28      'Query' => $Query, 'Link' => $Link);
     29  }
     30
     31  function UnregisterSearch($Name)
     32  {
     33    unset($this->SearchItems[$Name]);
     34  }
    3535}
    3636
    3737class PageSearch extends Page
    3838{
    39         function Show()
    40         {
    41                 $this->Title = T('Search');
    42                 if(array_key_exists('text', $_GET)) $Search = $_GET['text'];
    43                 else if(array_key_exists('text', $_POST)) $Search = $_POST['text'];
    44                 else $Search = '';
    45                 $SearchHTML = urlencode($Search);
    46                
    47                 $Output = '<table class="BaseTable"><tr><th>'.T('Section').'</th><th>'.T('Found count').'</th></tr>';
    48                 foreach($this->System->ModuleManager->Modules['Search']->SearchItems as $SearchItem)
    49                 {
    50                         $ColumnQuery = array();
    51                         foreach($SearchItem['Columns'] as $Column)
    52                         {
    53                           $ColumnQuery[] = '(`'.$Column.'` LIKE "%'.$Search.'%")';
    54                   }
    55                   $ColumnQuery = implode(' OR ', $ColumnQuery);
    56                   if($SearchItem['Query'] != '')
    57                   {                     
    58                     $DbResult = $this->Database->query('SELECT COUNT(*) FROM '.$SearchItem['Query'].' WHERE '.$ColumnQuery);
    59                   $Line = $DbResult->fetch_row();
    60                   $Line = $Line[0];
    61                   } else $Line = '';
     39  function Show()
     40  {
     41    $this->Title = T('Search');
     42    if(array_key_exists('text', $_GET)) $Search = $_GET['text'];
     43    else if(array_key_exists('text', $_POST)) $Search = $_POST['text'];
     44    else $Search = '';
     45    $SearchHTML = urlencode($Search);
     46
     47    $Output = '<table class="BaseTable"><tr><th>'.T('Section').'</th><th>'.T('Found count').'</th></tr>';
     48    foreach($this->System->ModuleManager->Modules['Search']->SearchItems as $SearchItem)
     49    {
     50      $ColumnQuery = array();
     51      foreach($SearchItem['Columns'] as $Column)
     52      {
     53        $ColumnQuery[] = '(`'.$Column.'` LIKE "%'.$Search.'%")';
     54      }
     55      $ColumnQuery = implode(' OR ', $ColumnQuery);
     56      if($SearchItem['Query'] != '')
     57      {
     58        $DbResult = $this->Database->query('SELECT COUNT(*) FROM '.$SearchItem['Query'].' WHERE '.$ColumnQuery);
     59        $Line = $DbResult->fetch_row();
     60        $Line = $Line[0];
     61      } else $Line = '';
    6262      if ($Line <> 0)
    63                   $Output .= '<tr><td><a href="'.$SearchItem['Link'].$SearchHTML.'">'.$SearchItem['Name'].'</a></td><td>'.$Line.'</td></tr>';
    64                 }
    65  
    66         $Output .= '</table>';
    67                 return($Output);
    68         }
     63        $Output .= '<tr><td><a href="'.$SearchItem['Link'].$SearchHTML.'">'.$SearchItem['Name'].'</a></td><td>'.$Line.'</td></tr>';
     64    }
     65
     66    $Output .= '</table>';
     67    return($Output);
     68  }
    6969}
Note: See TracChangeset for help on using the changeset viewer.