Changeset 10 for base.php


Ignore:
Timestamp:
Oct 12, 2008, 8:43:23 PM (16 years ago)
Author:
george
Message:
  • Upraveno: Odkazy na datové typy jsou nyní uváděny přímo jako ukazatele do tabulky SystemTypes oproti dřívějšímu textovému zápisu. Veškeré parametrické typy je nutno nyní definovat přes tabulku SystemTypes.
  • Upraveno: Sloupec ParentType v tabulce SystemTypes nyní ukazuje na rodičovský typ pomocí ukazatele typu INT.
  • Upraveno: Názvy funkcí vykreslování datových typů sjednoceny na systém událostí a tedy OnView a OnEdit.
  • Přidáno: Událost OnAdd pro tabulky SystemList a SystemListItem, které zajistí automatické vytvoření uživatelských tabulek.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • base.php

    r9 r10  
    1212include('types/Float.php');
    1313include('types/Hyperlink.php');
     14include('types/Hidden.php');
     15
     16// Include list events definitions
     17include('lists/SystemList.php');
     18include('lists/SystemListItem.php');
    1419
    1520function ShowList($List, $Column = '', $ColumnValue = 0, $Title = '')
     
    7378      if($Item['VisibleInList'] == 1)
    7479      {
    75         $ItemType = explode(':', $Item['Type']);
    76         $Type = $Types[$ItemType[0]];
    7780        $ItemDefinition = array('Name' => $Index, 'Value' => $DbRow[$Index], 'SourceTable' => $List['TableName'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']);
    78         if(is_callable($Type['CallbackView'])) $Value = $Type['CallbackView']($Type, $ItemDefinition);
    79         else $Value = $Type['CallbackView'];
    80         $Output .= '<td>'.$Value.'</td>';
     81        $Output .= '<td>'.ExecuteTypeEvent($Item['Type'], 'OnView', $ItemDefinition).'</td>';
    8182      }
    8283    }
     
    101102      $Output .= '<th><a href="?OrderColumn='.$Item['Name'].'">'.$Item['TextBefore'].'</a></th>';
    102103  }
    103   $Output .= '<th>Akce</th></tr>';
     104  $Output .= '<th><a href="?OrderColumn=Author">Autor</a></th><th><a href="?OrderColumn=CreationTime">Čas vytvoření</a></th><th>Akce</th></tr>';
    104105
    105106  $Where = ' AND (ItemId='.$Id.')';
     
    129130  $TotalItemCount = $DbRow[0];
    130131
    131   $DbResult = $Database->query('SELECT * FROM `'.$List['TableName'].'` WHERE 1'.$Where.' LIMIT '.($Page * $Config['Web']['ItemsPerPage']).', '.$Config['Web']['ItemsPerPage']);
     132  $DbResult = $Database->query('SELECT * FROM `'.$List['TableName'].'` AS t1 WHERE 1'.$Where.' LIMIT '.($Page * $Config['Web']['ItemsPerPage']).', '.$Config['Web']['ItemsPerPage']);
    132133  //echo($Database->LastQuery.'<br>');
    133134  while($DbRow = $DbResult->fetch_array())
    134135  {
    135136    $Output .= '<tr>';
    136     foreach($List['Items'] as $Index => $Item)
     137    foreach($List['Items'] as $Item)
    137138    {
    138139      if($Item['VisibleInList'] == 1)
    139140      {
    140         $ItemType = explode(':', $Item['Type']);
    141         $Type = $Types[$ItemType[0]];
    142         $ItemDefinition = array('Name' => $Index, 'Value' => $DbRow[$Index], 'SourceTable' => $List['TableName'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']);
    143         if(is_callable($Type['CallbackView'])) $Value = $Type['CallbackView']($Type, $ItemDefinition);
    144         else $Value = $Type['CallbackView'];
    145         $Output .= '<td>'.$Value.'</td>';
    146       }
    147     }
     141        $ItemDefinition = array('Name' => $Item['Name'], 'Value' => $DbRow[$Item['Name']], 'SourceTable' => $List['TableName'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']);
     142        $Output .= '<td>'.ExecuteTypeEvent($Item['Type'], 'OnView', $ItemDefinition).'</td>';
     143      }
     144    }
     145    $Item = array('Name' => 'Author', 'Type' => 'PointerOneToOne:User');
     146    $ItemType = explode(':', $Item['Type']);
     147    $Type = $Types[$ItemType[0]];
     148    $ItemDefinition = array('Name' => $Item['Name'], 'Value' => $DbRow[$Item['Name']], 'SourceTable' => $List['TableName'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']);
     149    if(is_callable($Type['CallbackView'])) $Value = $Type['CallbackView']($Type, $ItemDefinition);
     150      else $Value = $Type['CallbackView'];
     151    $Output .= '<td>'.$Value.'</td>';
     152
     153    $Output .= '<td>'.$DbRow['CreationTime'].'</td>';
    148154    $Output .= '<td><a href="?Action=ViewItem&amp;Table='.$List['TableName'].'&amp;Item='.$DbRow['Id'].'">Zobrazit</a> </td></tr>';
    149155  }
    150156  $Output .= '</table>';
    151157  $Output .= PagesList($Page, $TotalItemCount);
    152   $Output .= '<a href="?Action=AddItem&amp;Table='.$List['TableName'].$ColumnSelection.'">Přidat</a> '.$FullListLink;
     158  $Output .= '<a href="?Action=ShowList&amp;Table='.$List['TableName'].'">Celkový seznam</a>';
    153159  return($Output);
    154160}
     
    164170    foreach($List['Items'] as $Index => $Item)
    165171    {
    166       $ItemType = explode(':', $Item['Type']);
    167       if($ItemType[0] != 'PointerOneToMany')
     172      if($Types[$Item['Type']]['BaseType'] != 'PointerOneToMany')
    168173      {
    169174        $DefinitionItems[] = array('Name' => $Index, 'Caption' => $Item['TextBefore'].$Required, 'Value' => $DbRow[$Index], 'SourceTable' => $List['TableName'], 'SourceItemId' => $DbRow['Id'], 'Type' => $Item['Type']);
     
    197202  foreach($List['Items'] as $Index => $Item)
    198203  {
    199     $ItemType = explode(':', $Item['Type']);
    200     if($ItemType[0] != 'PointerOneToMany')
     204    if($Types[$Item['Type']]['BaseType'] != 'PointerOneToMany')
    201205    {
    202206      $Values[$Index] = $_POST[$Index];
     
    222226  $DefinitionItems = array();
    223227  $AfterTableOutput = '';
    224   foreach($List['Items'] as $Index => $Item)
    225   {
    226     $ItemType = explode(':', $Item['Type']);
    227     if(($ItemType[0] != 'PointerOneToMany') and ($Item['Name'] != $Column))
     228  foreach($List['Items'] as $Item)
     229  {
     230    //echo($Item['Name'].',');
     231    if(($Types[$Item['Type']]['BaseType'] != 'PointerOneToMany') and ($Item['Name'] != $Column))
    228232    {
    229233      if($Item['Required'] == 1) $Required = '*'; else $Required = '';
    230       $DefinitionItems[] = array('Name' => $Index, 'Type' => $Item['Type'], 'Caption' => $Item['TextBefore'].$Required, 'Value' => '', 'SourceTable' => $List['TableName'], 'SourceItemId' => 0);
     234      $DefinitionItems[] = array('Name' => $Item['Name'], 'Type' => $Item['Type'], 'Caption' => $Item['TextBefore'].$Required, 'Value' => '', 'SourceTable' => $List['TableName'], 'SourceItemId' => 0);
    231235    } else
    232236    if($Item['Name'] == $Column)
    233237    {
    234       $DefinitionItems[] = array('Name' => $Column, 'Type' => 'String', 'Caption' => '', 'Value' => $ColumnValue);
    235     }
    236   }
     238      $DefinitionItems[] = array('Name' => $Column, 'Type' => 'Hidden', 'Caption' => '', 'Value' => $ColumnValue);
     239    }
     240  }
     241  $DefinitionItems[] = array('Name' => 'Column', 'Type' => 'Hidden', 'Caption' => '', 'Value' => $Column);
     242
    237243  $Form = new Form();
    238244  $Form->Definition = array
     
    261267  foreach($List['Items'] as $Index => $Item)
    262268  {
    263     $ItemType = explode(':', $Item['Type']);
    264     if($ItemType[0] != 'PointerOneToMany')
     269    if($Types[$Item['Type']]['BaseType'] != 'PointerOneToMany')
    265270    {
    266271      $Values[$Index] = $_POST[$Index];
     
    278283  $Output = 'Položka přidána';
    279284  $Output .= ShowViewItem($List, $Database->insert_id);
     285  $Values['Column'] = $_POST['Column'];
     286  ExecuteListEvent($List['TableName'], 'OnAdd', $Values);
    280287  return($Output);
    281288}
     
    292299    foreach($List['Items'] as $Index => $Item)
    293300    {
    294       $ItemType = explode(':', $Item['Type']);
    295       if($ItemType[0] != 'PointerOneToMany')
     301      if($Types[$Item['Type']]['BaseType'] != 'PointerOneToMany')
    296302      {
    297303        $DefinitionItems[] = array('Name' => $Index, 'Type' => $Item['Type'], 'Caption' => $Item['TextBefore'].$Required, 'Value' => $DbRow[$Index], 'SourceTable' => $List['TableName'], 'SourceItemId' => 0);
     
    318324    foreach($List['Items'] as $Index => $Item)
    319325    {
    320       $ItemType = explode(':', $Item['Type']);
    321       if($ItemType[0] == 'PointerOneToMany')
    322       {
    323         $SubList = $Lists[$ItemType[1]];
    324         $Output .= ShowList($SubList, $ItemType[2], $DbRow['Id'], $Item['TextBefore']).'<br /><br />';
     326      if($Types[$Item['Type']]['BaseType'] == 'PointerOneToMany')
     327      {
     328        $SubList = $Lists[$Types[$Item['Type']]['Parameters'][0]];
     329        $Output .= ShowList($SubList, $Types[$Item['Type']]['Parameters'][1], $DbRow['Id'], $Item['TextBefore']).'<br /><br />';
    325330      }
    326331    }
     
    362367    if(array_key_exists($Var, $_GET)) $_SESSION[$Var] = $_GET[$Var];
    363368  }
    364 
    365369  $Output = '';
    366370  if(array_key_exists('Table', $_SESSION) and array_key_exists($_SESSION['Table'], $Lists))
     
    434438  {
    435439    $DbRow['Parameters'] = explode('|', $DbRow['Parameters']);
    436     $Types[$DbRow['Name']] = $DbRow;
     440    $DbRow['BaseType'] = $DbRow['Name'];
     441    $Types[$DbRow['Id']] = $DbRow;
    437442  }
    438443
     
    440445  foreach($Types as $Index => $Type)
    441446  {
    442     if($Type['ParentType'] != '')
     447    if($Type['ParentType'] != 0)
    443448    {
    444449      foreach($Type as $Index2 => $Item)
     
    447452        $Types[$Index][$Index2] = $Types[$Type['ParentType']][$Index2];
    448453      }
     454      $Types[$Index]['BaseType'] = $Types[$Type['ParentType']]['Name'];
    449455    }
    450456  }
     
    452458}
    453459
     460function ExecuteListEvent($Table, $Event, $Parameters)
     461{
     462  $Callback = 'List'.$Table.$Event;
     463  if(is_callable($Callback)) $Callback($Parameters);
     464}
     465
     466function ExecuteTypeEvent($Type, $Event, $Parameters)
     467{
     468  global $Types;
     469
     470  $Callback = 'Type'.$Types[$Type]['BaseType'].$Event;
     471  //echo($Callback.',');
     472  if(is_callable($Callback)) return($Callback($Parameters));
     473    else return($Callback);
     474}
     475
    454476?>
Note: See TracChangeset for help on using the changeset viewer.