Ignore:
Timestamp:
Mar 10, 2013, 8:15:46 PM (11 years ago)
Author:
chronos
Message:
  • Přidáno: FormManager pro objektové řešení zrušení vazeb na třídu System. FormManager nyní obsluhuje existující formulářové typy a třídy formulářů.
  • Přidáno: Formulářový typ FileContent zajistí načtení obsahu souboru. Typ File pak zajistí i uložení do databáze a přiřazení Id do tabulky File.
  • Odstraněno: Adresář docs obsahoval staré dokumenty. Ty musí být přesunuty do adresáře files a registrovány do databáze.
  • Upraveno: Třídy Database nyní bude hlásit chyby přes výjimky PHP.
Location:
trunk/Common/Form
Files:
1 added
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/Common/Form/Form.php

    r500 r501  
    11<?php
    22
    3 include_once(dirname(__FILE__).'/../form_classes.php');
    4 include_once(dirname(__FILE__).'/Database.php');
     3include_once(dirname(__FILE__).'/../Database.php');
     4include_once(dirname(__FILE__).'/Types/Type.php');
    55
    66class Form
    77{
    8   var $Definition = array();
    9   var $Values = array();
    10   var $OnSubmit = '';
    11  
    12   function __construct($ClassName)
    13   { 
    14     global $FormClasses;
    15 
    16     $this->Definition = &$FormClasses[$ClassName];
    17   }
     8  var $FormManager;
     9  var $Definition;
     10  var $Values;
     11  var $OnSubmit;
     12  var $Database;
     13 
     14  function __construct($FormManager)
     15  {     
     16    $this->FormManager = &$FormManager;
     17    $this->Database = $FormManager->Database;
     18    $this->Definition = array();
     19    $this->Values = array();   
     20    $this->OnSubmit = '';
     21  }
     22 
     23  function SetClass($Name)
     24  {
     25    $this->Definition = &$this->FormManager->Classes[$Name];   
     26  }
    1827
    1928  function ShowViewForm()
    2029  {
    21     global $Database, $FormTypes, $System;
    22 
    2330    $Table = array(
    2431      //'Header' => array('Položka', 'Hodnota'),
     
    2633    );
    2734    foreach($this->Definition['Items'] as $Index => $Item)
    28     if(!array_key_exists($Item['Type'], $FormTypes) or
    29     (array_key_exists($Item['Type'], $FormTypes) and ($FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
    30     {
    31       if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default'];
    32         if(array_key_exists($Item['Type'], $FormTypes))
    33         {           
    34           if(!array_key_exists($Item['Type'], $System->Type->TypeDefinitionList))
    35             $System->Type->RegisterType($Item['Type'], '', $FormTypes[$Item['Type']]);
    36           if($FormTypes[$Item['Type']]['Type'] == 'Reference')
    37             $UseType = 'OneToMany';
    38           else if($FormTypes[$Item['Type']]['Type'] == 'Enumeration')
     35    if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
     36    (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
     37    ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
     38    {
     39      if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default'];
     40        if(array_key_exists($Item['Type'], $this->FormManager->FormTypes))
     41        {           
     42          if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
     43            $this->FormManager->Type->RegisterType($Item['Type'], '', $this->FormManager->FormTypes[$Item['Type']]);
     44          if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
     45            $UseType = 'OneToMany';
     46          else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
    3947            $UseType = 'Enumeration';
    4048        } else $UseType = $Item['Type'];           
    41       $Edit = $System->Type->ExecuteTypeEvent($UseType, 'OnView',
     49      $Edit = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnView',
    4250        array('Value' => $this->Values[$Index], 'Name' => $Index,
    4351        'Type' => $Item['Type'], 'Values' => $this->Values));
    4452      if(array_key_exists('Suffix', $Item)) $Edit .= ' '.$Item['Suffix'];
    45       if(!$System->Type->IsHidden($UseType))
     53      if(!$this->FormManager->Type->IsHidden($UseType))
    4654        array_push($Table['Rows'], array($Item['Caption'].':', $Edit));
    4755    }
     
    6270  function ShowEditBlock($Context = '')
    6371  {
    64     global $Database, $FormTypes, $System;
    65 
    6672    $Hidden = '';
    6773    $IsHidden = false;
     
    7581      if(!array_key_exists('ReadOnly', $Item)) $Item['ReadOnly'] = false;
    7682    if($Item['ReadOnly'] == false)
    77     if(!array_key_exists($Item['Type'], $FormTypes) or
    78     (array_key_exists($Item['Type'], $FormTypes) and ($FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
     83    if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
     84    (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
     85    ($$this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
    7986    {
    8087      if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default'];
     
    8491          else unset($Parameters['Null']);
    8592
    86         if(array_key_exists($Item['Type'], $FormTypes))
    87         {           
    88           if(!array_key_exists($Item['Type'], $System->Type->TypeDefinitionList))
    89             $System->Type->RegisterType($Item['Type'], '',
    90               $FormTypes[$Item['Type']]);
    91           if($FormTypes[$Item['Type']]['Type'] == 'Reference')
     93        if(array_key_exists($Item['Type'], $this->FormManager->FormTypes))
     94        {           
     95          if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
     96            $this->FormManager->Type->RegisterType($Item['Type'], '',
     97              $this->FormManager->FormTypes[$Item['Type']]);
     98          if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
    9299          {
    93100            $UseType = 'OneToMany';
    94           } else if($FormTypes[$Item['Type']]['Type'] == 'Enumeration')
    95             $UseType = 'Enumeration';
    96         } else $UseType = $Item['Type'];
    97         $Edit = $System->Type->ExecuteTypeEvent($UseType, 'OnEdit', $Parameters);
     101          } else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
     102            $UseType = 'Enumeration';
     103        } else $UseType = $Item['Type'];
     104        $Edit = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnEdit', $Parameters);
    98105        if(array_key_exists('Suffix', $Item)) $Edit .= $Item['Suffix'];
    99106
    100       if(!$System->Type->IsHidden($UseType))
     107      if(!$this->FormManager->Type->IsHidden($UseType))
    101108          array_push($Table['Rows'], array($Item['Caption'].':', $Edit));
    102109      else $Hidden .= $Edit;
     
    110117  function LoadValuesFromDatabase($Id)
    111118  {
    112     global $Database, $FormTypes, $System;
    113 
    114     $DbResult = $Database->query('SELECT T.* FROM '.$this->Definition['Table'].' AS T WHERE T.Id='.$Id);
     119    $DbResult = $this->Database->query('SELECT T.* FROM '.$this->Definition['Table'].' AS T WHERE T.Id='.$Id);
    115120    $DbRow = $DbResult->fetch_array();
    116121    foreach($this->Definition['Items'] as $Index => $Item)
    117     if(!array_key_exists($Item['Type'], $FormTypes) or
    118     (array_key_exists($Item['Type'], $FormTypes) and ($FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
    119     {
    120       if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default'];
    121         if(array_key_exists($Item['Type'], $FormTypes))
    122         {           
    123           if(!array_key_exists($Item['Type'], $System->Type->TypeDefinitionList))
    124             $System->Type->RegisterType($Item['Type'], '',
    125               $FormTypes[$Item['Type']]);
    126           if($FormTypes[$Item['Type']]['Type'] == 'Reference')
    127             $UseType = 'OneToMany';
    128           else if($FormTypes[$Item['Type']]['Type'] == 'Enumeration')
    129             $UseType = 'Enumeration';
    130         } else $UseType = $Item['Type'];
    131         $this->Values[$Index] = $System->Type->ExecuteTypeEvent($UseType, 'OnLoadDb',
     122    if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
     123    (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
     124    ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
     125    {
     126      if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default'];
     127        if(array_key_exists($Item['Type'], $this->FormManager->FormTypes))
     128        {           
     129          if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
     130            $this->FormManager->Type->RegisterType($Item['Type'], '',
     131              $this->FormManager->FormTypes[$Item['Type']]);
     132          if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
     133            $UseType = 'OneToMany';
     134          else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
     135            $UseType = 'Enumeration';
     136        } else $UseType = $Item['Type'];
     137        $this->Values[$Index] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnLoadDb',
    132138            array('Value' => $DbRow[$Index], 'Name' => $Index,
    133139            'Type' => $Item['Type'], 'Values' => $this->Values));
     
    139145  function SaveValuesToDatabase($Id)
    140146  {
    141     global $Database, $FormTypes, $System;
    142 
    143147    $Values = array();
    144148    foreach($this->Definition['Items'] as $Index => $Item)
     
    146150      if(!array_key_exists('ReadOnly', $Item)) $Item['ReadOnly'] = false;
    147151      if($Item['ReadOnly'] == false)
    148     if(!array_key_exists($Item['Type'], $FormTypes) or
    149     (array_key_exists($Item['Type'], $FormTypes) and ($FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
     152    if(!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
     153    (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
     154    ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne')))
    150155    {
    151156      if(!array_key_exists($Index, $this->Values) and isset($Item['Default'])) $this->Values[$Index] = $Item['Default'];
     
    153158          'Type' => $Item['Type'], 'Values' => $this->Values);
    154159     
    155         if(array_key_exists($Item['Type'], $FormTypes))
    156         {           
    157           if(!array_key_exists($Item['Type'], $System->Type->TypeDefinitionList))
    158             $System->Type->RegisterType($Item['Type'], '',
    159               $FormTypes[$Item['Type']]);
    160           if($FormTypes[$Item['Type']]['Type'] == 'Reference')
     160        if(array_key_exists($Item['Type'], $this->FormManager->FormTypes))
     161        {           
     162          if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
     163            $this->FormManager->Type->RegisterType($Item['Type'], '',
     164              $this->FormManager->FormTypes[$Item['Type']]);
     165          if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
    161166          {
    162167            $UseType = 'OneToMany';
    163168          }
    164           else if($FormTypes[$Item['Type']]['Type'] == 'Enumeration')
    165             $UseType = 'Enumeration';
    166         } else $UseType = $Item['Type'];
    167         $Values[$Index] = $System->Type->ExecuteTypeEvent($UseType, 'OnSaveDb', $Parameters);
     169          else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
     170            $UseType = 'Enumeration';
     171        } else $UseType = $Item['Type'];
     172        $Values[$Index] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnSaveDb', $Parameters);
    168173        if(($Item['Type'] == 'Password') and ($Values[$Index] == '')) unset($Values[$Index]);
    169174       
     
    174179    {
    175180      $Values['Id'] = $Id;
    176       $DbResult = $Database->insert($this->Definition['Table'], $Values);
     181      $DbResult = $this->Database->insert($this->Definition['Table'], $Values);
    177182    } else
    178       $DbResult = $Database->update($this->Definition['Table'], 'Id='.$Id, $Values);
     183      $DbResult = $this->Database->update($this->Definition['Table'], 'Id='.$Id, $Values);
    179184    //echo($Database->LastQuery);
    180185  }
     
    187192  function LoadValuesFromFormBlock($Context = '')
    188193  {
    189     global $Database, $FormTypes, $System;
    190 
    191194    if($Context != '') $Context = $Context.'-';
    192195    $Values = array();
    193196    foreach($this->Definition['Items'] as $Index => $Item)
    194     if((!array_key_exists($Item['Type'], $FormTypes) or
    195     (array_key_exists($Item['Type'], $FormTypes) and
    196     ($FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) and
     197    if((!array_key_exists($Item['Type'], $this->FormManager->FormTypes) or
     198    (array_key_exists($Item['Type'], $this->FormManager->FormTypes) and
     199    ($this->FormManager->FormTypes[$Item['Type']]['Type'] != 'ManyToOne'))) and
    197200    (!array_key_exists('ReadOnly', $Item) or
    198201    (array_key_exists('ReadOnly', $Item) and
     
    200203    {
    201204      //if(array_key_exists($Context.$Index, $_POST))
    202         if(array_key_exists($Item['Type'], $FormTypes))
    203         {           
    204           if(!array_key_exists($Item['Type'], $System->Type->TypeDefinitionList))
    205             $System->Type->RegisterType($Item['Type'], '',
    206               $FormTypes[$Item['Type']]);
    207           if($FormTypes[$Item['Type']]['Type'] == 'Reference')
    208             $UseType = 'OneToMany';
    209           else if($FormTypes[$Item['Type']]['Type'] == 'Enumeration')
    210             $UseType = 'Enumeration';
    211         } else $UseType = $Item['Type'];
    212         $Values[$Index] = $System->Type->ExecuteTypeEvent($UseType, 'OnLoad',
     205        if(array_key_exists($Item['Type'], $this->FormManager->FormTypes))
     206        {           
     207          if(!array_key_exists($Item['Type'], $this->FormManager->Type->TypeDefinitionList))
     208            $this->FormManager->Type->RegisterType($Item['Type'], '',
     209              $this->FormManager->FormTypes[$Item['Type']]);
     210          if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Reference')
     211            $UseType = 'OneToMany';
     212          else if($this->FormManager->FormTypes[$Item['Type']]['Type'] == 'Enumeration')
     213            $UseType = 'Enumeration';
     214        } else $UseType = $Item['Type'];
     215        $Values[$Index] = $this->FormManager->Type->ExecuteTypeEvent($UseType, 'OnLoad',
    213216          array('Name' => $Index, 'Type' => $Item['Type'], 'Values' => $this->Values));
    214217    }
     
    246249}
    247250
    248 function ShowEditTable($ClassName, $Values)
    249 {
     251class FormManager
     252{
     253  var $Classes;
     254  var $FormTypes;
     255  var $Database;
     256  var $Type;
     257 
     258  function __construct($Database)
     259  {
     260    $this->Database = &$Database;
     261    $this->Classes = array();
     262    $this->FormTypes = array();
     263    $this->Type = new Type($this);
     264  }
     265 
     266  function RegisterClass($Name, $Class)
     267  {
     268    $this->Classes[$Name] = $Class;
     269  }
     270 
     271  function UnregisterClass($Name)
     272  {
     273    unset($this->Classes[$Name]);
     274  }
    250275}
    251276
Note: See TracChangeset for help on using the changeset viewer.