Ignore:
Timestamp:
Jan 17, 2015, 9:24:47 PM (10 years ago)
Author:
chronos
Message:
  • Added: NetworkDomain table for managing multiple network domains. It is not completed and linked to real functionality yet.
  • Added: ModuleLinks and Model tables as preparation for better modules and models in-database representation.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/System/System.php

    r712 r731  
    1414  {
    1515    $Output = '';
    16     $DbResult = $this->Database->query('SELECT COUNT(*) FROM `SystemModule`');
     16    $DbResult = $this->Database->query('SELECT COUNT(*) FROM `Module`');
    1717    $DbRow = $DbResult->fetch_row();
    1818    $PageList = GetPageList($DbRow[0]);
     
    2222     
    2323    $TableColumns = array(
    24         array('Name' => 'Name', 'Title' => 'Jméno'),
    25         array('Name' => 'Creator', 'Title' => 'Tvůrce'),
    26         array('Name' => 'Version', 'Title' => 'Verze'),
    27         array('Name' => 'License', 'Title' => 'Licence'),
    28         array('Name' => 'Installed', 'Title' => 'Instalováno'),
    29         array('Name' => 'Description', 'Title' => 'Popis'),
    30         array('Name' => 'Dependencies', 'Title' => 'Závislosti'),
    31         array('Name' => '', 'Title' => 'Akce'),
     24      array('Name' => 'Name', 'Title' => 'Jméno'),
     25      array('Name' => 'Creator', 'Title' => 'Tvůrce'),
     26      array('Name' => 'Version', 'Title' => 'Verze'),
     27      array('Name' => 'License', 'Title' => 'Licence'),
     28      array('Name' => 'Installed', 'Title' => 'Instalováno'),
     29      array('Name' => 'Description', 'Title' => 'Popis'),
     30      array('Name' => 'Dependencies', 'Title' => 'Závislosti'),
     31      array('Name' => '', 'Title' => 'Akce'),
    3232    );
    3333    $Order = GetOrderTableHeader($TableColumns, 'Name', 0);
    3434    $Output .= $Order['Output'];
    35     $Query = 'SELECT *, (SELECT GROUP_CONCAT(`T1`.`Name` SEPARATOR ", ") FROM `SystemModuleDependency` '.
    36         'LEFT JOIN `SystemModule` AS `T1` ON `T1`.`Id` = `SystemModuleDependency`.`DependencyModule` '.
    37         'WHERE `SystemModuleDependency`.`Module` = `SystemModule`.`Id`) AS `Dependencies` '.
    38         'FROM `SystemModule` '.$Order['SQL'].$PageList['SQLLimit'];
     35    $Query = 'SELECT *, (SELECT GROUP_CONCAT(`T1`.`Name` SEPARATOR ", ") FROM `ModuleLink` '.
     36        'LEFT JOIN `Module` AS `T1` ON `T1`.`Id` = `ModuleLink`.`LinkedModule` '.
     37        'WHERE `ModuleLink`.`Module` = `Module`.`Id`) AS `Dependencies` '.
     38        'FROM `Module` '.$Order['SQL'].$PageList['SQLLimit'];
    3939   
    4040    $DbResult = $this->Database->query($Query);
     
    6969      if($_GET['A'] == 'SaveToDb')
    7070      {
    71         $this->System->ModuleManager->Modules['System']->SaveToDatabase();
     71        $Output .= $this->System->ModuleManager->Modules['System']->SaveToDatabase();
    7272        $Output .= $this->SystemMessage('Načtení modulů', 'Seznam modulů v databázi zaktualizován');   
    7373      } else
     
    225225                'Name' => array('Type' => 'String', 'Caption' => 'Systémové jméno', 'Default' => ''),
    226226                  'Title' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
     227                'Description' => array('Type' => 'Text', 'Caption' => 'Popis', 'Default' => ''),
     228                'Version' => array('Type' => 'String', 'Caption' => 'Verze', 'Default' => ''),
     229                'License' => array('Type' => 'String', 'Caption' => 'Licence', 'Default' => ''),
     230                'Creator' => array('Type' => 'String', 'Caption' => 'Tvůrce', 'Default' => ''),
     231        'HomePage' => array('Type' => 'Hyperlink', 'Caption' => 'Domovské stránky', 'Default' => ''),           
     232                'Installed' => array('Type' => 'Boolean', 'Caption' => 'Instalováno', 'Default' => '', 'ReadOnly' => true),
     233                'Models' => array('Type' => 'TModelListModule', 'Caption' => 'Modely', 'Default' => ''),
     234                'Links' => array('Type' => 'TModuleLinkListModule', 'Caption' => 'Vazby', 'Default' => ''),
     235          ),
     236        'Actions' => array(
     237                array('Caption' => 'Aktualizovat z disku', 'URL' => '/module/?A=SaveToDb'),
     238          ),
     239    ));
     240    $this->System->FormManager->RegisterFormType('TModule', array(
     241        'Type' => 'Reference',
     242        'Table' => 'Module',
     243        'Id' => 'Id',
     244        'Name' => 'Title',
     245        'Filter' => '1',
     246    ));
     247    $this->System->FormManager->RegisterFormType('TModelListModule', array(
     248      'Type' => 'ManyToOne',
     249      'Table' => 'Model',
     250      'Id' => 'Id',
     251      'Ref' => 'Module',
     252      'Filter' => '1',
     253    ));
     254    $this->System->FormManager->RegisterClass('Model', array(
     255        'Title' => 'Modely',
     256          'Table' => 'Model',
     257          'Items' => array(
     258                'Name' => array('Type' => 'String', 'Caption' => 'Systémové jméno', 'Default' => ''),
     259                  'Title' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
     260                'Module' => array('Type' => 'TModule', 'Caption' => 'Module', 'Default' => ''),
     261            'Query' => array('Type' => 'String', 'Caption' => 'SQL dotaz', 'Default' => ''),
     262                'DefaultSortColumn' => array('Type' => 'String', 'Caption' => 'Výchozí sloupce řazení', 'Default' => ''),
     263                'DefaultSortOrder' => array('Type' => 'Text', 'Caption' => 'Výchozí směr řazení', 'Default' => ''),
     264                'Fields' => array('Type' => 'TModelFieldListModel', 'Caption' => 'Pole', 'Default' => ''),
     265          ),
     266    ));
     267    $this->System->FormManager->RegisterFormType('TModel', array(
     268        'Type' => 'Reference',
     269        'Table' => 'Model',
     270        'Id' => 'Id',
     271        'Name' => 'Title',
     272        'Filter' => '1',
     273    ));
     274    $this->System->FormManager->RegisterFormType('TModelFieldListModel', array(
     275      'Type' => 'ManyToOne',
     276      'Table' => 'ModelField',
     277      'Id' => 'Id',
     278      'Ref' => 'Model',
     279      'Filter' => '1',
     280    ));
     281    $this->System->FormManager->RegisterClass('ModelField', array(
     282        'Title' => 'Pole modelu',
     283          'Table' => 'ModelField',
     284          'Items' => array(
     285                'Name' => array('Type' => 'String', 'Caption' => 'Systémové jméno', 'Default' => ''),
     286                  'Title' => array('Type' => 'String', 'Caption' => 'Název', 'Default' => ''),
     287                'Model' => array('Type' => 'TModel', 'Caption' => 'Model', 'Default' => ''),
     288            'Query' => array('Type' => 'String', 'Caption' => 'SQL dotaz', 'Default' => ''),
     289                'Type' => array('Type' => 'String', 'Caption' => 'Typ', 'Default' => ''),
     290                'DefaultValue' => array('Type' => 'String', 'Caption' => 'Výchozí hodnota', 'Default' => ''),
     291                'IsNull' => array('Type' => 'Boolean', 'Caption' => 'Také nulová hodnota', 'Default' => ''),
     292                'Suffix' => array('Type' => 'String', 'Caption' => 'Text za', 'Default' => ''),
     293          ),
     294    ));
     295    $this->System->FormManager->RegisterFormType('TModuleLink', array(
     296        'Type' => 'Reference',
     297        'Table' => 'ModuleLink',
     298        'Id' => 'Id',
     299        'Name' => 'Module',
     300        'Filter' => '1',
     301    ));
     302    $this->System->FormManager->RegisterFormType('TModuleLinkListModule', array(
     303      'Type' => 'ManyToOne',
     304      'Table' => 'ModuleLink',
     305      'Id' => 'Id',
     306      'Ref' => 'Module',
     307      'Filter' => '1',
     308    ));
     309    $this->System->FormManager->RegisterClass('ModuleLink', array(
     310        'Title' => 'Vazby modulu',
     311          'Table' => 'ModuleLink',
     312          'Items' => array(
     313                'Module' => array('Type' => 'TModule', 'Caption' => 'Modul', 'Default' => ''),
     314                'LinkedModule' => array('Type' => 'TModule', 'Caption' => 'Vázaný modul', 'Default' => ''),
     315            'Type' => array('Type' => 'String', 'Caption' => 'Typ vazby', 'Default' => ''),
    227316          ),
    228317    ));
     
    232321          'DefaultSortColumn' => 'Name',
    233322          'Items' => array(
    234                 'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''),
     323                'Name' => array('Type' => 'String', 'Caption' => 'Jméno', 'Default' => ''),                     
    235324          ),
    236325    ));
     
    337426      if($Module->IsInstalled()) $Installed = 1;
    338427        else $Installed = 0;
    339       $this->Database->query('UPDATE `SystemModule` SET `Installed`=1 WHERE `Name`="'.$Module->Name.'"');
     428      $this->Database->query('UPDATE `Module` SET `Installed`=1 WHERE `Name`="'.$Module->Name.'"');
    340429    }
    341430  }
     
    345434    //DebugLog('Loading modules...');
    346435    $this->Modules = array();
    347     $Query = 'SELECT `Id`, `Name`,`Installed` FROM `SystemModule`';
     436    $Query = 'SELECT `Id`, `Name`,`Installed` FROM `Module`';
    348437    $DbResult = $this->Database->query($Query);
    349438    while($Module = $DbResult->fetch_array())
     
    361450  function SaveToDatabase()
    362451  {
     452        $Output = '';
    363453    $Modules = array();
    364     $DbResult = $this->Database->query('SELECT * FROM `SystemModule`');
     454    $DbResult = $this->Database->query('SELECT * FROM `Module`');
    365455    while($DbRow = $DbResult->fetch_assoc())
    366456    {
     
    375465      if(!array_key_exists($Module->Name, $Modules))
    376466      {
    377         $this->Database->insert('SystemModule', array('Name' => $Module->Name,
    378           'Version' => $Module->Version, 'Creator' => $Module->Creator,
     467        $this->Database->insert('Module', array('Name' => $Module->Name,
     468          'Version' => $Module->Version, 'Creator' => $Module->Creator,
     469                'HomePage' => $Module->HomePage, 'Title' => $Module->Title,
    379470          'Description' => $Module->Description, 'License' => $Module->License,
    380471          'Installed' => $Module->Installed));
    381472        $this->System->ModuleManager->Modules[$Module->Name]->Id = $this->Database->insert_id;
    382473      }
    383       else $this->Database->update('SystemModule', 'Name = "'.$Module->Name.'"', array(
    384         'Version' => $Module->Version, 'Creator' => $Module->Creator,
     474      else $this->Database->update('Module', 'Name = "'.$Module->Name.'"', array(
     475        'Version' => $Module->Version, 'Creator' => $Module->Creator,
     476        'HomePage' => $Module->HomePage, 'Title' => $Module->Title,
    385477        'Description' => $Module->Description, 'License' => $Module->License,
    386478        'Installed' => $Module->Installed));
     
    391483    if(!$this->System->ModuleManager->ModulePresent($Module['Name']))
    392484    {
    393       DebugLog('Removing module '.$Module['Name'].' from list');
    394       $this->Database->query('DELETE FROM `SystemModule` WHERE `Id` = '.$Module['Id']);
     485      $Output .= 'Removing module '.$Module['Name'].' from list</br/>';
     486      $this->Database->query('DELETE FROM `ModuleLink` WHERE `Module` = '.$Module['Id']);
     487      $this->Database->query('DELETE FROM `ModuleLink` WHERE `LinkedModule` = '.$Module['Id']);
     488      $DbResult = $this->Database->query('SELECT Id FROM `PermissionOperation` WHERE `Module` = '.$Module['Id']);
     489      while($DbRow = $DbResult->fetch_assoc())
     490      {
     491        $this->Database->query('DELETE FROM `PermissionGroupAssignment` WHERE `AssignedOperation` = '.$DbRow['Id']);
     492        $this->Database->query('DELETE FROM `PermissionUserAssignment` WHERE `AssignedOperation` = '.$DbRow['Id']);
     493      }
     494      $this->Database->query('DELETE FROM `PermissionOperation` WHERE `Module` = '.$Module['Id']);
     495      $this->Database->query('DELETE FROM `Model` WHERE `Module` = '.$Module['Id']);
     496      $DbResult = $this->Database->query('SELECT Id FROM `Model` WHERE `Module` = '.$Module['Id']);
     497      while($DbRow = $DbResult->fetch_assoc())
     498        $this->Database->query('DELETE FROM `ModelField` WHERE `Model` = '.$DbRow['Id']);
     499      $this->Database->query('DELETE FROM `Module` WHERE `Id` = '.$Module['Id']);
    395500    }   
    396501   
    397502    // Reload dependencies
    398503    $DbDependency = array();
    399     $DbResult = $this->Database->query('SELECT * FROM `SystemModuleDependency`');
     504    $DbResult = $this->Database->query('SELECT * FROM `ModuleLink`');
    400505    while($DbRow = $DbResult->fetch_assoc())
    401       $DbDependency[$DbRow['Module']][] = $DbRow['DependencyModule'];
     506      $DbDependency[$DbRow['Module']][] = $DbRow['LinkedModule'];
    402507   
    403508    foreach($this->System->ModuleManager->Modules as $Module)
     
    412517            $DependencyId = $this->System->ModuleManager->Modules[$Dependency]->Id;
    413518            else throw new Exception('Dependent module '.$Dependency.' not found');
    414           $this->Database->insert('SystemModuleDependency', array('Module' => $Module->Id,
    415             'DependencyModule' => $DependencyId));
     519          $this->Database->insert('ModuleLink', array('Module' => $Module->Id,
     520            'LinkedModule' => $DependencyId, 'Type' => 'DependOn'));
    416521        }       
    417522      }
     
    423528        $DepModName = $this->System->ModuleManager->SearchModuleById($Dep);
    424529        if(!in_array($DepModName, $Module->Dependencies))
    425         $this->Database->query('DELETE FROM `SystemModuleDependency` WHERE `Module` = '.
    426           $Module->Id.' AND DependencyModule='.$Dep);
     530        $this->Database->query('DELETE FROM `ModuleLink` WHERE `Module` = '.
     531          $Module->Id.' AND LinkedModule='.$Dep);
    427532      }     
    428533    }
     534    return($Output);
    429535  }
    430536}
Note: See TracChangeset for help on using the changeset viewer.