Ignore:
Timestamp:
Jan 23, 2012, 10:37:31 AM (13 years ago)
Author:
chronos
Message:
  • Přidáno: Kostra základního systémového modulu System.
  • Přidáno: Obsluha datových typů pro HTML kód a HTTP protokol.
  • Upraveno: Do ViewList zkopírování generování tabulky se stránkováním a řazením.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Common/ViewList.php

    r373 r383  
    33class ViewList extends View
    44{
    5   function __construct($Database)
     5  var $DefaultOrder;
     6  var $Columns;
     7  var $SQL;
     8  var $SQLJoin;
     9  var $Rows;
     10  var $Actions;
     11  var $PageList;
     12  var $TableHeader;
     13  var $FilterColumn;
     14  var $Module;
     15  var $PanelAction;
     16
     17  function __construct($System)
    618  {
    7     $this->Database = &$Database;   
     19    parent::__construct($System);
     20    $this->FilterColumn = '';
     21    $this->FilterId = 0;
     22    $this->PageList = new PageList($this->System);
     23    $this->TableHeader = new TableHeader($this->System);
     24    $this->Rows = array();
     25    $this->PanelAction = 'ListPanel';
     26    $this->DefaultOrder = array();
    827  }
    928
     29  function Show()
     30  {
     31    $Output = $this->PageList->Output;
     32    $Output .= '<table class="WideTable">';
     33    $Output .= $this->TableHeader->Output;
     34    foreach($this->Rows as $Row2)
     35    {
     36      $Row = array();
     37      foreach($Row2 as $Index => $Item)
     38        $Row[$Index]['Value'] = $Item;
     39      $Row = $this->ProcessRow($Row);
     40
     41      $Output .= '<tr>';
     42      foreach($this->Columns as $ColumnName => $Column)
     43      if($Column['Type'] != 'Hidden')
     44      {
     45        if(array_key_exists('Class', $Row[$ColumnName]) and ($Row[$ColumnName]['Class'] != ''))
     46          $Style = ' class="'.$Row[$ColumnName]['Class'].'"'; else $Style ='';
     47        $Output .= '<td'.$Style.'>';
     48        $Output .= $this->System->Type->ExecuteTypeEvent($Column['Type'],
     49          'OnView', array('Name' => $ColumnName, 'Value' => $Row[$ColumnName]['Value'], 'Type' => $Column['Type']));
     50        $Output .= '</td>';
     51      }
     52      if(is_array($this->Actions))
     53      {
     54        $Output .= '<td>';
     55        foreach($this->Actions as $Action)
     56        {
     57          if(array_key_exists('Confirm', $Action)) $Confirm = ' onclick="return confirmAction(\''.$this->System->Localization->Translate($Action['Confirm']).'\');"';
     58            else $Confirm = '';
     59          if(strpos($Action['Name'], '<') !== false) $ActionName = $Action['Name'];
     60            else $ActionName = $this->System->Localization->Translate($Action['Name']);
     61          $Output .= '<a'.$Confirm.' href="'.$this->System->Navigation->MakeLink($Action['Module'], $Action['Action'], array('Id' => $Row['Id']['Value'])).'">'.
     62            $ActionName.'</a> ';
     63        }
     64        $Output .= '</td>';
     65      }
     66      $Output .= '</tr>';
     67    }
     68    $Output .= '</table>';
     69    $Output .= $this->PageList->Output;
     70    return($Output);
     71  }
     72
     73  function LoadFromDatabase()
     74  {
     75    // Get total item count
     76    $DbResult = $this->System->Database->query('SELECT COUNT(*) FROM '.$this->Name.
     77      ' '.$this->SQLJoin);
     78    $DbRow = $DbResult->fetch_row();
     79    $this->PageList->TotalCount = $DbRow[0];
     80    $this->PageList->HTMLId = $this->Module;
     81    $this->PageList->QueryItems->Data['M'] = $this->Module;
     82    $this->PageList->QueryItems->Data['A'] = $this->PanelAction;
     83    $this->PageList->QueryItems->Data['FilterColumn'] = $this->FilterColumn;
     84    $this->PageList->Process();
     85
     86    // Build table header and ordering
     87    $this->TableHeader->QueryItems = $this->PageList->QueryItems;
     88    $this->TableHeader->HTMLId = $this->Module;
     89    $this->TableHeader->Columns = array();
     90    foreach($this->Columns as $Item)
     91    {
     92      $this->TableHeader->Columns[$Item['Name']] = array('Title' => $Item['Title'],
     93        'Type' => $Item['Type'], 'SQL' => $Item['SQL']);
     94    }
     95    if(is_array($this->Actions))
     96      $this->TableHeader->Columns['Actions'] = array('Type' => 'String', 'SQL' => '');
     97    $this->TableHeader->DefaultOrder = $this->DefaultOrder;
     98    $this->TableHeader->Process();
     99
     100    //$this->System->Navigation->UnsetParameter('Panel');
     101
     102    // Build column list
     103    $Columns = $this->Name.'.Id';
     104    foreach($this->Columns as $ColumnName => $Column)
     105      $Columns .= ', '.$Column['SQL'].' AS `'.$ColumnName.'`';
     106
     107    $this->DbRows = array();
     108    $DbResult = $this->System->Database->query('SELECT '.$Columns.' FROM '.$this->Name.
     109      ' '.$this->SQLJoin.$this->TableHeader->SQL.$this->PageList->SQLLimit);
     110    while($DbRow = $DbResult->fetch_assoc())
     111    {
     112      $this->Rows[] = $DbRow;
     113    }
     114  }
     115
     116  function ProcessRow($Row)
     117  {
     118    return($Row);
     119  }
     120 
    10121  function AddItemString($Name, $Title)
    11122  {
    12     $this->Items[$Name] = array('Name' => $Name, 'Title' => $Title,
    13       'Type' => ViewItemTypeString);
    14   }
    15  
     123    $this->Columns[$Name] = array('Name' => $Name, 'Title' => $Title,
     124      'Type' => ViewItemTypeString, 'SQL' => $Name);
     125  }   
    16126}
    17127
Note: See TracChangeset for help on using the changeset viewer.