source: trunk/Modules/User/ModuleUser.php

Last change on this file was 893, checked in by chronos, 21 months ago
  • Fixed: Class types casting for better type checking.
  • Fixed: XML direct export.
  • Modified: User class instance moved from Core class to ModuleUser class.
File size: 3.8 KB
Line 
1<?php
2
3class ModuleUser extends Module
4{
5 public User $User;
6
7 function __construct(System $System)
8 {
9 parent::__construct($System);
10 $this->Name = 'User';
11 $this->Version = '1.1';
12 $this->Creator = 'Chronos';
13 $this->License = 'GNU/GPL';
14 $this->Description = 'User and permission management';
15 $this->Dependencies = array();
16
17 $this->User = new User($this->System);
18 }
19
20 function DoStart(): void
21 {
22 $this->System->RegisterPage(['users'], 'PageUserList');
23 $this->System->RegisterPage(['options'], 'PageUserOptions');
24 $this->System->RegisterPage(['registration'], 'PageUserRegistration');
25 $this->System->RegisterPage(['user'], 'PageUserProfile');
26 $this->System->RegisterPage(['login'], 'PageUserLogin');
27 Core::Cast($this->System)->RegisterMenuItem(array(
28 'Title' => T('Translators'),
29 'Hint' => 'Seznam registrovaných uživatelů',
30 'Link' => $this->System->Link('/users/'),
31 'Permission' => LICENCE_ANONYMOUS,
32 'Icon' => '',
33 ), 0);
34 if (array_key_exists('Search', $this->System->ModuleManager->Modules))
35 $this->System->ModuleManager->Modules['Search']->RegisterSearch('user',
36 T('Translators'), array('Name'), '`User`', $this->System->Link('/users/?search='));
37 Core::Cast($this->System)->RegisterPageBarItem('Top', 'User', array($this, 'TopBarCallback'));
38 Core::Cast($this->System)->RegisterPageBarItem('Left', 'User', array($this, 'ShowOnlineList'));
39 }
40
41 function ShowOnlineList()
42 {
43 $Output = T('Online translators').':<br />';
44 $DbResult = $this->System->Database->query('SELECT * FROM ('.
45 'SELECT `User`.`Name`, `User`.`ID` FROM `UserOnline` '.
46 'JOIN `User` ON `User`.`ID` = `UserOnline`.`User` '.
47 'WHERE (`ActivityTime` >= NOW() - 300) '.
48 'ORDER BY `ActivityTime` DESC ) AS `T` GROUP BY `Name`');
49 while ($DbUser = $DbResult->fetch_assoc())
50 {
51 $Name = '<a href="'.$this->System->Link('/user/?user='.$DbUser['ID']).'">'.$DbUser['Name'].'</a>';
52 $Output .= $Name.'<br />';
53 }
54 return $Output;
55 }
56
57 function TopBarCallback()
58 {
59 $Output = '';
60 $User = ModuleUser::Cast($this->System->GetModule('User'))->User;
61 if ($User->Licence(LICENCE_USER))
62 {
63 //$DbResult =$this->Database->query('SELECT `Id`, `Name` FROM `Team` WHERE `Id`='.$this->System->User->Team);
64 //$Team = $DbResult->fetch_assoc();
65 //$Output .= ''<span class="MenuItem">Moje překlady: <a href="">Dokončené</a> <a href="">Rozpracované</a> <a href="">Exporty</a> Tým: <a href="">'.$Team['name'].'</a></span>';
66 $Output .= $User->Name.' <a href="'.$this->System->Link('/?action=logout').'">'.T('Logout').'</a>'.
67 ' <a href="'.$this->System->Link('/user/?user='.$User->Id).'">'.T('My page').'</a>'.
68 ' <a href="'.$this->System->Link('/options/').'">'.T('Options').'</a>'.
69 ' <a title="Vámi přeložené texty" href="'.$this->System->Link('/TranslationList.php?user='.
70 $User->Id.'&amp;group=0&amp;state=2&amp;text=&amp;entry=').'">'.T('Translated').'</a>'.
71 ' <a title="Vaše rozpracované text" href="'.$this->System->Link('/TranslationList.php?user='.
72 $User->Id.'&amp;group=0&amp;state=3&amp;text=&amp;entry=').'">'.T('Unfinished').'</a>'.
73 ' <a title="Nikým nepřeložené texty" href="'.
74 $this->System->Link('/TranslationList.php?user=0&amp;group=0&amp;state=1&amp;text=&amp;entry=').'">'.T('Untranslated').'</a>';
75 } else
76 {
77 $Output .= '<a href="'.$this->System->Link('/login/').'">'.T('Login').'</a>&nbsp;'.
78 '<a href="'.$this->System->Link('/registration/').'">'.T('Registration').'</a>';
79 }
80 return $Output;
81 }
82
83 static function Cast(Module $Module): ModuleUser
84 {
85 if ($Module instanceof ModuleUser)
86 {
87 return $Module;
88 }
89 throw new Exception('Expected '.ModuleUser::GetClassName().' type but got '.gettype($Module));
90 }
91}
Note: See TracBrowser for help on using the repository browser.