Changeset 21


Ignore:
Timestamp:
Oct 22, 2008, 10:33:11 AM (16 years ago)
Author:
george
Message:
  • Upraveno: Načítání definic typů "na přání" namísto načtení všech najednou. Úspora paměti, více SQL dotazů, možné zpomalení načítání.
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • base.php

    r20 r21  
    33function ShowList($List, $Column = '', $ColumnValue = 0, $Title = '')
    44{
    5   global $Database, $Types, $Config;
     5  global $Database, $Config;
    66
    77  if(!CheckPermission('Read', $List['ItemId']))
     
    8585function ShowHistory($List, $Id, $Title = '')
    8686{
    87   global $Database, $Types, $Config, $TypeNames;
     87  global $Database, $Config;
    8888
    8989  if($Title == '') $Output = '<div>'.$List['Title'].'</div>';
     
    136136      }
    137137    }
    138     $Item = array('Name' => 'Author', 'Type' => $TypeNames['PointerToUser']);
     138    $Item = array('Name' => 'Author', 'Type' => TypePointerToUserId);
    139139    $ItemDefinition = array('Name' => $Item['Name'], 'Value' => $DbRow[$Item['Name']], 'SourceTable' => $List['TableName'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']);
    140140    $Output .= '<td>'.ExecuteTypeEvent($Item['Type'], 'OnView', $ItemDefinition).'</td>';
     
    151151function ShowEditItem($List, $Id)
    152152{
    153   global $Database, $Types;
     153  global $Database;
    154154
    155155  if(!CheckPermission('Write', $List['ItemId'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
     
    160160    foreach($List['Items'] as $Index => $Item)
    161161    {
    162       if($Types[$Item['Type']]['BaseType'] != 'PointerOneToMany')
     162      $Type = GetTypeDefinition($Item['Type']);
     163      if($Type['BaseType'] != 'PointerOneToMany')
    163164      {
    164165        if($Item['Editable'] == 1)
     
    190191function ShowEditItemFinish($List, $Id)
    191192{
    192   global $Database, $Types, $System, $LogActionType;
     193  global $Database, $System, $LogActionType;
    193194
    194195  if(!CheckPermission('Write', $List['ItemId'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
     
    199200    foreach($List['Items'] as $Index => $Item)
    200201    {
    201       if($Types[$Item['Type']]['BaseType'] != 'PointerOneToMany')
     202      $Type = GetTypeDefinition($Item['Type']);
     203      if($Type['BaseType'] != 'PointerOneToMany')
    202204      {
    203205        $DefinitionItems[] = array('Name' => $Index, 'Caption' => $Item['TextBefore'].$Required, 'Value' => $DbRow[$Index], 'SourceTable' => $List['TableName'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']);
     
    227229function ShowAddItem($List, $Column = '', $ColumnValue = 0)
    228230{
    229   global $Database, $Types;
     231  global $Database;
    230232
    231233  if(!CheckPermission('Write', $List['ItemId'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
     
    235237  {
    236238    //echo($Item['Name'].',');
    237     if(($Types[$Item['Type']]['BaseType'] != 'PointerOneToMany') and ($Item['Name'] != $Column))
     239    $Type = GetTypeDefinition($Item['Type']);
     240    if(($Type['BaseType'] != 'PointerOneToMany') and ($Item['Name'] != $Column))
    238241    {
    239242      if($Item['Required'] == 1) $Required = '*'; else $Required = '';
     
    269272function ShowAddItemFinish($List)
    270273{
    271   global $Database, $Types, $System, $LogActionType;
     274  global $Database, $System, $LogActionType;
    272275
    273276  if(!CheckPermission('Write', $List['ItemId'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
     
    277280  {
    278281    //echo($Item['Name'].',');
    279     if(($Types[$Item['Type']]['BaseType'] != 'PointerOneToMany') and ($Item['Name'] != $Column))
     282    $Type = GetTypeDefinition($Item['Type']);
     283    if(($Type['BaseType'] != 'PointerOneToMany') and ($Item['Name'] != $Column))
    280284    {
    281285      if($Item['Required'] == 1) $Required = '*'; else $Required = '';
     
    308312function ShowViewItem($List, $Id,  $Column = '', $ColumnValue = 0)
    309313{
    310   global $Database, $Types;
     314  global $Database;
    311315
    312316  if(!CheckPermission('Read', $List['ItemId'])) return(SystemMessage('Řízení přístupu', 'Nemáte dostatečná oprávnění'));
     
    319323    foreach($List['Items'] as $Index => $Item)
    320324    {
    321       if($Types[$Item['Type']]['BaseType'] != 'PointerOneToMany')
     325      $Type = GetTypeDefinition($Item['Type']);
     326      if($Type['BaseType'] != 'PointerOneToMany')
    322327      {
    323328        $DefinitionItems[] = array('Name' => $Index, 'Type' => $Item['Type'], 'Caption' => $Item['TextBefore'].$Required, 'Value' => $DbRow[$Index], 'SourceTable' => $List['TableName'], 'SourceItemId' => 0);
     
    344349    foreach($List['Items'] as $Index => $Item)
    345350    {
    346       if($Types[$Item['Type']]['BaseType'] == 'PointerOneToMany')
    347       {
    348         $SubList = GetListDefinition($Types[$Item['Type']]['Parameters'][0]);
    349         $Output .= ShowList($SubList, $Types[$Item['Type']]['Parameters'][1], $DbRow['ItemId'], $Item['TextBefore']).'<br /><br />';
     351      $Type = GetTypeDefinition($Item['Type']);
     352      if($Type['BaseType'] == 'PointerOneToMany')
     353      {
     354        $SubList = GetListDefinition($Type['Parameters'][0]);
     355        $Output .= ShowList($SubList, $Type['Parameters'][1], $DbRow['ItemId'], $Item['TextBefore']).'<br /><br />';
    350356      }
    351357    }
     
    469475}
    470476
    471 function LoadTypeDefinition()
    472 {
    473   global $Database, $Types, $TypeNames;
    474 
    475   $Types = array();
    476   $TypeNames = array();
    477   $DbResult = $Database->query('SELECT t1.* FROM `SystemType` AS t1 LEFT JOIN `SystemType` AS t2 ON t1.ItemId=t2.ItemId AND t1.Id < t2.Id WHERE (t2.ItemId IS NULL) AND (t1.DeletionTime IS NULL)');
    478   while($DbRow = $DbResult->fetch_assoc())
    479   {
    480     $DbRow['Parameters'] = explode('|', $DbRow['Parameters']);
    481     $DbRow['BaseType'] = $DbRow['Name'];
    482     $Types[$DbRow['ItemId']] = $DbRow;
    483     $TypeNames[$DbRow['Name']] = $DbRow['ItemId'];
    484   }
    485 
    486   // Merge parent type definition
    487   foreach($Types as $Index => $Type)
    488   {
    489     if($Type['ParentType'] != 0)
    490     {
    491       foreach($Type as $Index2 => $Item)
    492         if($Item == '')
    493       {
    494         $Types[$Index][$Index2] = $Types[$Type['ParentType']][$Index2];
    495       }
    496       $Types[$Index]['BaseType'] = $Types[$Type['ParentType']]['Name'];
    497     }
     477function GetTypeDefinition($Id)
     478{
     479  global $Database, $Types;
     480
     481  if(!array_key_exists($Id, $Types))
     482  {
     483    $DbResult = $Database->query('SELECT t1.* FROM `SystemType` AS t1 LEFT JOIN `SystemType` AS t2 ON t1.ItemId=t2.ItemId AND t1.Id < t2.Id WHERE (t2.ItemId IS NULL) AND (t1.DeletionTime IS NULL) AND t1.ItemId='.$Id);
     484    if($DbResult->num_rows > 0)
     485    {
     486      $DbRow = $DbResult->fetch_assoc();
     487      $DbRow['Parameters'] = explode('|', $DbRow['Parameters']);
     488      $DbRow['BaseType'] = $DbRow['Name'];
     489
     490      // Merge parent type definition
     491      if($DbRow['ParentType'] != 0)
     492      {
     493        $ParentType = GetTypeDefinition($DbRow['ParentType']);
     494        foreach($DbRow as $Index => $Item)
     495        if($Item == '')
     496        {
     497          $DbRow[$Index] = $ParentType[$Index];
     498        }
     499        $DbRow['BaseType'] = $ParentType['Name'];
     500      }
     501      $Types[$DbRow['ItemId']] = $DbRow;
     502    } else $Types[$DbRow['ItemId']] = NULL;
    498503  }
    499504  //print_r($Types);
     505  return($Types[$Id]);
    500506}
    501507
     
    508514function ExecuteTypeEvent($Type, $Event, $Parameters)
    509515{
    510   global $Types, $TypeDefinitionList;
    511 
    512   $TypeObject = $TypeDefinitionList[$Types[$Type]['BaseType']];
    513   //echo($Callback.',');
     516  global $TypeDefinitionList;
     517
     518  $TypeDefinition = GetTypeDefinition($Type);
     519  $TypeObject = $TypeDefinitionList[$TypeDefinition['BaseType']];
    514520  if(is_callable(array($TypeObject, $Event))) return($TypeObject->$Event($Parameters));
    515     else return($Types[$Type]['BaseType'].'->'.$Event.'('.$Type.')');
     521    else return($TypeDefinition['BaseType'].'->'.$Event.'('.$Type.')');
    516522}
    517523
  • forms.php

    r20 r21  
    99  var $OnSubmit = '';
    1010
    11   function DefinitionTextTypeToNumericType()
    12   {
    13     global $TypeNames;
    14 
    15     foreach($this->Definition['Items'] as $Index => $Definition)
    16       if(!is_numeric($Definition['Type'])) $this->Definition['Items'][$Index]['Type'] = $TypeNames[$Definition['Type']];
    17   }
    18 
    1911  function ShowEditForm()
    2012  {
    21     $this->DefinitionTextTypeToNumericType();
    2213    $Output = '<center><form enctype="multipart/form-data" action="'.$this->OnSubmit.'" method="post"><div align="center">';
    2314    $Table = $this->ShowEditBlock();
     
    2819  function ShowEditBlock($Context = '')
    2920  {
    30     global $Database, $Types, $TypeNames;
     21    global $Database;
    3122
    3223    $Table = array(
     
    3728    foreach($this->Definition['Items'] as $Index => $Item)
    3829    {
    39       if($Item['Type'] != $TypeNames['Hidden'])
     30      if($Item['Type'] != TypeHiddenId)
    4031      {
    4132        if(!array_key_exists($Index, $this->Values) and isset($Item['Value'])) $this->Values[$Index] = $Item['Value'];
     
    4940  function ShowHiddenBlock($Context = '')
    5041  {
    51     global $Database, $Types, $TypeNames;
     42    global $Database;
    5243
    5344    $Output = '';
     
    5546    foreach($this->Definition['Items'] as $Item)
    5647    {
    57       if($Item['Type'] == $TypeNames['Hidden'])
     48      if($Item['Type'] == TypeHiddenId)
    5849      {
    5950        if(!array_key_exists($Item['Name'], $this->Values) and isset($Item['Value'])) $this->Values[$Item['Name']] = $Item['Value'];
     
    6758  function ShowReadOnlyForm()
    6859  {
    69     $this->DefinitionTextTypeToNumericType();
    70 
    7160    $Output = '<center><div align="center">';
    7261    $Table = $this->ShowReadOnlyBlock();
     
    7766  function ShowReadOnlyBlock($Context = '')
    7867  {
    79     global $Database, $Types;
     68    global $Database;
    8069
    8170    $Table = array(
     
    138127  function LoadValuesFromForm()
    139128  {
    140     $this->DefinitionTextTypeToNumericType();
    141129    $this->Values = $this->LoadValuesFromFormBlock();
    142130  }
     
    144132  function LoadValuesFromFormBlock($Context = '')
    145133  {
    146     global $FormTypes;
    147 
    148134    $Values = array();
    149135    foreach($this->Definition['Items'] as $Index => $Item)
  • global.php

    r20 r21  
    4949$System->AddModule(new User());
    5050$System->Modules['User']->Check();
    51 LoadTypeDefinition();
    5251
    5352$MonthNames = array('', 'Leden', 'Únor', 'Březen', 'Duben', 'Květen', 'Červen', 'Červenec', 'Srpen', 'Září', 'Říjen', 'Listopad', 'Prosinec');
  • index.php

    r18 r21  
    1515      'SubmitBuffonText' => 'Přihlásit',
    1616      'Items' => array(
    17         array('Name' => 'UserName', 'Type' => 'String', 'Caption' => 'Jméno', 'Value' => ''),
    18         array('Name' => 'Password', 'Type' => 'Password', 'Caption' => 'Heslo', 'Value' => ''),
     17        array('Name' => 'UserName', 'Type' => TypeStringId, 'Caption' => 'Jméno', 'Value' => ''),
     18        array('Name' => 'Password', 'Type' => TypePasswordId, 'Caption' => 'Heslo', 'Value' => ''),
    1919      ),
    2020    );
     
    2525      'SubmitBuffonText' => 'Registrovat',
    2626      'Items' => array(
    27         array('Name' => 'UserName', 'Type' => 'String', 'Caption' => 'Přihlašovací jméno', 'Value' => ''),
    28         array('Name' => 'Password', 'Type' => 'Password', 'Caption' => 'Heslo', 'Value' => ''),
    29         array('Name' => 'Password2', 'Type' => 'Password', 'Caption' => 'Potvrzení hesla', 'Value' => ''),
    30         array('Name' => 'Email', 'Type' => 'String', 'Caption' => 'E-mail', 'Value' => ''),
    31         array('Name' => 'FirstName', 'Type' => 'String', 'Caption' => 'Křestní jméno', 'Value' => ''),
    32         array('Name' => 'SecondName', 'Type' => 'String', 'Caption' => 'Příjmení', 'Value' => ''),
     27        array('Name' => 'UserName', 'Type' => TypeStringId, 'Caption' => 'Přihlašovací jméno', 'Value' => ''),
     28        array('Name' => 'Password', 'Type' => TypePasswordId, 'Caption' => 'Heslo', 'Value' => ''),
     29        array('Name' => 'Password2', 'Type' => TypePasswordId, 'Caption' => 'Potvrzení hesla', 'Value' => ''),
     30        array('Name' => 'Email', 'Type' => TypeStringId, 'Caption' => 'E-mail', 'Value' => ''),
     31        array('Name' => 'FirstName', 'Type' => TypeStringId, 'Caption' => 'Křestní jméno', 'Value' => ''),
     32        array('Name' => 'SecondName', 'Type' => TypeStringId, 'Caption' => 'Příjmení', 'Value' => ''),
    3333      ),
    3434    );
  • types/Enumeration.php

    r19 r21  
    55  function OnView($Item)
    66  {
    7     global $Types;
    8 
    9     $Output = $Types[$Item['Type']]['Parameters'][$Item['Value']];
     7    $Type = GetTypeDefinition($Item['Type']);
     8    $Output = $Type['Parameters'][$Item['Value']];
    109    return($Output);
    1110  }
     
    1312  function OnEdit($Item)
    1413  {
    15     global $Types;
    16 
     14    $Type = GetTypeDefinition($Item['Type']);
    1715    $Output = '<select name="'.$Item['Name'].'">';
    18     foreach($Types[$Item['Type']]['Parameters'] as $Index => $StateName)
     16    foreach($Type['Parameters'] as $Index => $StateName)
    1917    {
    2018      if($Item['Value'] == $Index) $Selected = ' selected="1"'; else $Selected = '';
  • types/File/FileDownload.php

    r19 r21  
    1010}
    1111
    12 chdir('..');
     12chdir('../..');
    1313include('global.php');
    1414$DbResult = $Database->select('SystemFile', '*', 'Id='.addslashes($_GET['Id']));
  • types/PointerOneToOne.php

    r20 r21  
    4747  function OnView($Item)
    4848  {
    49     global $Database, $Types;
     49    global $Database;
    5050
    51     $Type = $Types[$Item['Type']];
     51    $Type = GetTypeDefinition($Item['Type']);
    5252    $TargetTable = $Type['Parameters'][0];
    5353    $TargetName = $this->GetTablePointerName($Type, $Item);
  • types/include.php

    r19 r21  
    1717include('types/GPS.php');
    1818
     19define(TypeIntegerId, 1);
     20define(TypeBooleanId, 4);
     21define(TypeStringId, 3);
     22define(TypeDateId, 2);
     23define(TypePasswordId, 15);
     24define(TypeFloatId, 16);
     25define(TypeHiddenId, 20);
     26define(TypePointerToUserId, 37);
     27
    1928?>
Note: See TracChangeset for help on using the changeset viewer.