Ignore:
Timestamp:
Nov 20, 2020, 12:08:12 AM (3 years ago)
Author:
chronos
Message:
  • Added: Static types added to almost all classes, methods and function. Supported by PHP 7.4.
  • Fixed: Various found code issues.
File:
1 edited

Legend:

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

    r873 r887  
    55class PageIS extends Page
    66{
    7   var $FullTitle = 'Správa dat';
    8   var $ShortTitle = 'Správa dat';
    9   var $ParentClass = 'PagePortal';
    10   var $MenuItems;
    11   var $HideMenu;
    12   var $ShowActionName;
     7  public array $MenuItems;
     8  public bool $HideMenu;
     9  public bool $ShowActionName;
    1310
    1411  function __construct($System)
    1512  {
    1613    parent::__construct($System);
     14    $this->FullTitle = 'Správa dat';
     15    $this->ShortTitle = 'Správa dat';
     16    $this->ParentClass = 'PagePortal';
     17
    1718    $this->MenuItems = array();
    1819    $this->HideMenu = false;
     
    2021  }
    2122
    22   function Show()
    23   {
    24     if (!$this->System->User->CheckPermission('IS', 'Manage'))
     23  function Show(): string
     24  {
     25    if (!ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission('IS', 'Manage'))
    2526      return 'Nemáte oprávnění';
    2627    $this->System->FormManager->ShowRelation = true;
     
    7879  }
    7980
    80   function Dashboard()
     81  function Dashboard(): string
    8182  {
    8283    $Output = '<strong>Nástěnka:</strong><br/>';
    83     foreach ($this->System->ModuleManager->Modules['IS']->DashboardItems as $Item)
     84    foreach (ModuleIS::Cast($this->System->GetModule('IS'))->DashboardItems as $Item)
    8485    {
    8586      if (is_string($Item['Callback'][0]))
     
    9394  }
    9495
    95   function ShowFavoriteAdd($Table, $ItemId)
    96   {
    97     $DbResult = $this->Database->select('MenuItemFavorite', 'Id', '(`MenuItem`='.($_GET['i'] * 1).') AND (`User`='.$this->System->User->User['Id'].')');
     96  function ShowFavoriteAdd(string $Table, string $ItemId): string
     97  {
     98    $DbResult = $this->Database->select('MenuItemFavorite', 'Id', '(`MenuItem`='.($_GET['i'] * 1).') AND (`User`='.$this->ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'].')');
    9899    if ($DbResult->num_rows > 0)
    99100    {
     
    101102    } else
    102103    {
    103       $this->Database->insert('MenuItemFavorite', array('MenuItem' => ($_GET['i'] * 1), 'User' => $this->System->User->User['Id']));
     104      $this->Database->insert('MenuItemFavorite', array('MenuItem' => ($_GET['i'] * 1), 'User' => ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id']));
    104105      $Output = $this->SystemMessage('Oblíbené', 'Přidáno do oblíbených');
    105106    }
     
    108109  }
    109110
    110   function ShowFavoriteDel($Table, $ItemId)
    111   {
    112     $DbResult = $this->Database->select('MenuItemFavorite', 'Id', '(`MenuItem`='.($_GET['i'] * 1).') AND (`User`='.$this->System->User->User['Id'].')');
     111  function ShowFavoriteDel(string $Table, string $ItemId): string
     112  {
     113    $DbResult = $this->Database->select('MenuItemFavorite', 'Id', '(`MenuItem`='.($_GET['i'] * 1).') AND (`User`='.ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'].')');
    113114    if ($DbResult->num_rows > 0)
    114115    {
     
    124125  }
    125126
    126   function LogChange($Form, $Action, $NewId, $OldId)
     127  function LogChange(Form $Form, string $Action, string $NewId, string $OldId): void
    127128  {
    128129    $Values = $Form->Definition['Table'].' (Id: '.$OldId.' => '.$NewId.'):'."\n";
     
    152153      }
    153154    }
    154     $this->System->ModuleManager->Modules['Log']->NewRecord('IS', $Action, $Values);
    155   }
    156 
    157   function ShowEdit($Table, $Id)
     155    ModuleLog::Cast($this->System->GetModule('Log'))->NewRecord('IS', $Action, $Values);
     156  }
     157
     158  function ShowEdit(string $Table, string $Id): string
    158159  {
    159160    $Output = '';
    160161    if (!array_key_exists($Table, $this->System->FormManager->Classes))
    161162      return $this->SystemMessage('Chyba', 'Tabulka '.$Table.' nenalezena');
    162     if (defined('NEW_PERMISSION') and !$this->System->User->CheckPermission($this->TableToModule($Table), 'Write'))
     163    if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Write'))
    163164      return $this->SystemMessage('Oprávnění', 'Nemáte oprávnění');
    164165    if (array_key_exists('o', $_GET))
     
    226227  }
    227228
    228   function ShowDelete($Table, $Id)
     229  function ShowDelete(string $Table, string $Id): string
    229230  {
    230231    $Output = '';
     
    232233      return $this->SystemMessage('Chyba', 'Tabulka '.$Table.' nenalezena');
    233234    $FormClass = $this->System->FormManager->Classes[$Table];
    234     if (defined('NEW_PERMISSION') and !$this->System->User->CheckPermission($this->TableToModule($Table), 'Write'))
     235    if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Write'))
    235236      return 'Nemáte oprávnění';
    236237    $DbResult = $this->Database->select($Table, '*', '`Id`='.$Id);
     
    266267  }
    267268
    268   function ShowAdd($Table, $Actions = array())
     269  function ShowAdd(string $Table, array $Actions = array()): string
    269270  {
    270271    $Output = '';
    271272    if (!array_key_exists($Table, $this->System->FormManager->Classes))
    272273      return $this->SystemMessage('Chyba', 'Tabulka '.$Table.' nenalezena');
    273     if (defined('NEW_PERMISSION') and !$this->System->User->CheckPermission($this->TableToModule($Table), 'Write'))
     274    if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Write'))
    274275      return 'Nemáte oprávnění';
    275276    if (array_key_exists('o', $_GET))
     
    315316
    316317        //$this->Database->update($Table, 'Id='.$Id,
    317         //  array('UserCreate' => $this->System->User->User['Id'],
     318        //  array('UserCreate' => ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'],
    318319        //  'TimeCreate' => 'NOW()'));
    319320        } catch (Exception $E)
     
    357358  }
    358359
    359   function ShowAddSub($Table, $Filter = '', $Title = '')
    360   {
    361     if (defined('NEW_PERMISSION') and !$this->System->User->CheckPermission($this->TableToModule($Table), 'Write'))
     360  function ShowAddSub(string $Table, string $Filter = '', string $Title = ''): string
     361  {
     362    if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Write'))
    362363      return 'Nemáte oprávnění';
    363364    $this->BasicHTML = true;
     
    367368  }
    368369
    369   function ShowTabs($Tabs, $QueryParamName, $TabContent)
     370  function ShowTabs(array $Tabs, string $QueryParamName, string $TabContent): string
    370371  {
    371372    $QueryItems = GetQueryStringArray($_SERVER['QUERY_STRING']);
     
    388389  }
    389390
    390   function ShowView($Table, $Id, $WithoutActions = false)
     391  function ShowView(string $Table, string $Id, bool $WithoutActions = false): string
    391392  {
    392393    if (!array_key_exists($Table, $this->System->FormManager->Classes))
    393394      return $this->SystemMessage('Chyba', 'Tabulka '.$Table.' nenalezena');
    394395    $FormClass = $this->System->FormManager->Classes[$Table];
    395     if (defined('NEW_PERMISSION') and !$this->System->User->CheckPermission($this->TableToModule($Table), 'Read'))
     396    if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Read'))
    396397      return 'Nemáte oprávnění';
    397398
     
    473474  }
    474475
    475   function ShowTable($Table, $Filter = '', $Title = '', $RowActions = array(), $ExcludeColumn = '')
     476  function ShowTable(string $Table, string $Filter = '', string $Title = '', string $RowActions = '', string $ExcludeColumn = ''): string
    476477  {
    477478    if (!array_key_exists($Table, $this->System->FormManager->Classes))
     
    673674  }
    674675
    675   function ShowSelect($Table, $Filter = '', $Title = '')
    676   {
    677     if (defined('NEW_PERMISSION') and !$this->System->User->CheckPermission($this->TableToModule($Table), 'Read'))
     676  function ShowSelect(string $Table, string $Filter = '', string $Title = ''): string
     677  {
     678    if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Read'))
    678679      return 'Nemáte oprávnění';
    679680    $this->BasicHTML = true;
     
    686687  }
    687688
    688   function ShowMapSelect($Table, $Filter = '', $Title = '')
    689   {
    690     if (defined('NEW_PERMISSION') and !$this->System->User->CheckPermission($this->TableToModule($Table), 'Write'))
     689  function ShowMapSelect(string $Table, string $Filter = '', string $Title = ''): string
     690  {
     691    if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Write'))
    691692      return 'Nemáte oprávnění';
    692693    $Map = new MapOpenStreetMaps($this->System);
     
    701702  }
    702703
    703   function ShowList($Table, $Filter = '', $Title = '', $ExcludeColumn = '', $ExcludeValue = '')
     704  function ShowList(string $Table, string $Filter = '', string $Title = '', string $ExcludeColumn = '', string $ExcludeValue = ''): string
    704705  {
    705706    $Output = '';
    706     if (defined('NEW_PERMISSION') and !$this->System->User->CheckPermission($this->TableToModule($Table), 'Read'))
     707    if (defined('NEW_PERMISSION') and !ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Read'))
    707708      return 'Nemáte oprávnění';
    708709    if (!array_key_exists($Table, $this->System->FormManager->Classes))
     
    738739    if (array_key_exists('mi', $_GET))
    739740    {
    740       $DbResult = $this->Database->select('MenuItemFavorite', 'Id', '(`MenuItem`='.($_GET['mi'] * 1).') AND (`User`='.$this->System->User->User['Id'].')');
     741      $DbResult = $this->Database->select('MenuItemFavorite', 'Id', '(`MenuItem`='.($_GET['mi'] * 1).') AND (`User`='.ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'].')');
    741742      if ($DbResult->num_rows > 0)
    742743      {
     
    761762  }
    762763
    763   function ShowFavorites()
     764  function ShowFavorites(): string
    764765  {
    765766    $this->MenuItems = array();
     
    768769      'LEFT JOIN `Action` ON `Action`.`Id` = `MenuItem`.`Action` '.
    769770      'LEFT JOIN `ActionIcon` ON `ActionIcon`.`Id` = `Action`.`Icon` '.
    770       'WHERE `MenuItemFavorite`.`User`='.$this->System->User->User['Id'].' '.
     771      'WHERE `MenuItemFavorite`.`User`='.ModuleUser::Cast($this->System->GetModule('User'))->User->User['Id'].' '.
    771772      'ORDER BY `MenuItem`.`Parent`,`MenuItem`.`Name`');
    772773    while ($DbRow = $DbResult->fetch_assoc())
     
    778779  }
    779780
    780   function ShowMenu()
     781  function ShowMenu(): string
    781782  {
    782783    $this->MenuItems = array();
     
    794795  }
    795796
    796   function ShowMenuItem($Parent, $All = false)
     797  function ShowMenuItem(string $Parent, bool $All = false): string
    797798  {
    798799    $Output = '<ul style="list-style: none; margin-left:1em; padding-left:0em;">';
     
    810811        if ($MenuItem['IconName'] != '') $Image = '<img src="'.$this->System->Link('/images/favicons/'.$MenuItem['IconName']).'"/>&nbsp;';
    811812          else $Image = '<img src="'.$this->System->Link('/images/favicons/'.$Icon).'"/>&nbsp;';
    812         //if ($this->System->User->CheckPermission($this->TableToModule($Table), 'Write') or !defined('NEW_PERMISSION'))
     813        //if (ModuleUser::Cast($this->System->GetModule('User'))->User->CheckPermission($this->TableToModule($Table), 'Write') or !defined('NEW_PERMISSION'))
    813814          $Output .= '<li>'.$Image.$LinkTitle.'</li>';
    814815        if ($All == false) $Output .= $this->ShowMenuItem($MenuItem['Id']);
     
    819820  }
    820821
    821   function TableToModule($Table)
     822  function TableToModule(string $Table): string
    822823  {
    823824    $DbResult = $this->Database->query('SELECT (SELECT `Name` FROM `Module` '.
     
    830831  }
    831832
    832   function ShowAction($Name, $Target, $Icon, $Confirm = '')
     833  function ShowAction(string $Name, string $Target, string $Icon, string $Confirm = ''): string
    833834  {
    834835    $Output = '<img alt="'.$Name.'" title="'.$Name.'" src="'.
     
    846847  var $DashboardItems;
    847848
    848   function __construct($System)
     849  function __construct(System $System)
    849850  {
    850851    parent::__construct($System);
     
    855856    $this->License = 'GNU/GPLv3';
    856857    $this->Description = 'User interface for generic information system';
    857     $this->Dependencies = array();
     858    $this->Dependencies = array('User');
    858859
    859860    $this->DashboardItems = array();
    860861  }
    861862
    862   function DoInstall()
    863   {
    864   }
    865 
    866   function DoUninstall()
    867   {
    868   }
    869 
    870   function DoStart()
    871   {
    872     $this->System->RegisterPage('is', 'PageIS');
     863  function DoInstall(): void
     864  {
     865  }
     866
     867  function DoUninstall(): void
     868  {
     869  }
     870
     871  function DoStart(): void
     872  {
     873    $this->System->RegisterPage(['is'], 'PageIS');
    873874    $this->System->FormManager->RegisterClass('MenuItem', array(
    874875      'Title' => 'Položky nabídky',
     
    914915  }
    915916
    916   function DoStop()
    917   {
    918   }
    919 
    920   function RegisterDashboardItem($Name, $Callback)
     917  function DoStop(): void
     918  {
     919  }
     920
     921  function RegisterDashboardItem(string $Name, callable $Callback): void
    921922  {
    922923    $this->DashboardItems[$Name] = array('Callback' => $Callback);
    923924  }
    924925
    925   function UnregisterDashboardItem($Name)
     926  function UnregisterDashboardItem(string $Name): void
    926927  {
    927928    unset($this->DashboardItems[$Name]);
    928929  }
     930
     931  static function Cast(AppModule $AppModule): ModuleIS
     932  {
     933    if ($AppModule instanceof ModuleIS)
     934    {
     935      return $AppModule;
     936    }
     937    throw new Exception('Expected ModuleIS type but '.gettype($AppModule));
     938  }
    929939}
Note: See TracChangeset for help on using the changeset viewer.