Changeset 21 for base.php


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í.
File:
1 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
Note: See TracChangeset for help on using the changeset viewer.