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/User/User.php

    r874 r887  
    77class ModuleUser extends AppModule
    88{
    9   var $UserPanel;
    10 
    11   function __construct($System)
     9  public array $UserPanel;
     10  public User $User;
     11
     12  function __construct(System $System)
    1213  {
    1314    parent::__construct($System);
     
    1920    $this->Dependencies = array();
    2021    $this->UserPanel = array();
    21   }
    22 
    23   function DoInstall()
     22    $this->User = new User($System);
     23  }
     24
     25  function DoInstall(): void
    2426  {
    2527    $this->Database->query("CREATE TABLE IF NOT EXISTS `User` (
     
    108110  }
    109111
    110   function DoUninstall()
     112  function DoUninstall(): void
    111113  {
    112114    $this->Database->query('DROP TABLE `PermissionUserAssignment`');
     
    118120  }
    119121
    120   function DoUpgrade()
     122  function DoUpgrade(): void
    121123  {
    122124    /*
     
    129131  }
    130132
    131   function DoStart()
    132   {
    133     $this->System->User = new User($this->System);
    134     if (isset($_SERVER['REMOTE_ADDR'])) $this->System->User->Check();
    135     $this->System->RegisterPage('userlist', 'PageUserList');
    136     $this->System->RegisterPage('user', 'PageUser');
     133  function DoStart(): void
     134  {
     135    if (isset($_SERVER['REMOTE_ADDR'])) $this->User->Check();
     136    $this->System->RegisterPage(['userlist'], 'PageUserList');
     137    $this->System->RegisterPage(['user'], 'PageUser');
    137138    $this->System->RegisterPageBarItem('Top', 'User', array($this, 'TopBarCallback'));
    138139    $this->System->FormManager->RegisterClass('UserLogin', array(
     
    272273      'Filter' => '1',
    273274    ));
    274     $this->System->ModuleManager->Modules['IS']->RegisterDashboardItem('User',
    275         array('ModuleUser', 'ShowDashboardItem'));
    276   }
    277 
    278   function ShowDashboardItem()
     275    ModuleIS::Cast($this->System->GetModule('IS'))->RegisterDashboardItem('User',
     276      array($this, 'ShowDashboardItem'));
     277  }
     278
     279  function ShowDashboardItem(): string
    279280  {
    280281    $DbResult = $this->Database->select('User', 'COUNT(*)', '1');
     
    284285  }
    285286
    286   function DoStop()
    287   {
    288   }
    289 
    290   function TopBarCallback()
    291   {
    292     if ($this->System->User->User['Id'] == null)
     287  function DoStop(): void
     288  {
     289  }
     290
     291  function TopBarCallback(): string
     292  {
     293    if ($this->User->User['Id'] == null)
    293294    {
    294295      $Output = '<a href="'.$this->System->Link('/user/?Action=LoginForm').'">Přihlášení</a> '.
     
    296297    } else
    297298    {
    298       $Output = $this->System->User->User['Name'].
     299      $Output = $this->User->User['Name'].
    299300        ' <a href="'.$this->System->Link('/user/?Action=UserMenu').'">Nabídka</a>'.
    300301        ' <a href="'.$this->System->Link('/user/?Action=Logout').'">Odhlásit</a>';
     
    303304    return $Output;
    304305  }
     306
     307  static function Cast(AppModule $AppModule): ModuleUser
     308  {
     309    if ($AppModule instanceof ModuleUser)
     310    {
     311      return $AppModule;
     312    }
     313    throw new Exception('Expected ModuleUser type but got '.gettype($AppModule));
     314  }
    305315}
Note: See TracChangeset for help on using the changeset viewer.