Commit | Line | Data |
---|---|---|
320f4a6d | 1 | <?php |
a9229942 | 2 | |
320f4a6d | 3 | namespace wcf\data\user\profile\menu\item; |
a9229942 | 4 | |
320f4a6d | 5 | use wcf\data\DatabaseObject; |
c1b907f3 MS |
6 | use wcf\data\TDatabaseObjectOptions; |
7 | use wcf\data\TDatabaseObjectPermissions; | |
26b1551b | 8 | use wcf\system\exception\ClassNotFoundException; |
a9229942 TD |
9 | use wcf\system\exception\ImplementationException; |
10 | use wcf\system\exception\ParentClassException; | |
320f4a6d | 11 | use wcf\system\exception\SystemException; |
a9229942 | 12 | use wcf\system\menu\user\profile\content\IUserProfileMenuContent; |
592454d4 | 13 | use wcf\system\SingletonFactory; |
5929567d | 14 | use wcf\system\WCF; |
320f4a6d MW |
15 | |
16 | /** | |
db8a92cc | 17 | * Represents a user profile menu item. |
e9335ed9 | 18 | * |
a9229942 TD |
19 | * @author Alexander Ebert |
20 | * @copyright 2001-2019 WoltLab GmbH | |
21 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | |
a9229942 TD |
22 | * |
23 | * @property-read int $menuItemID unique id of the user profile menu item | |
24 | * @property-read int $packageID id of the package which delivers the user profile menu item | |
25 | * @property-read string $menuItem textual identifier of the user profile menu item | |
26 | * @property-read int $showOrder position of the user profile menu item in relation to its siblings | |
27 | * @property-read string $permissions comma separated list of user group permissions of which the active user needs to have at least one to see the user profile menu item | |
28 | * @property-read string $options comma separated list of options of which at least one needs to be enabled for the user profile menu item to be shown | |
29 | * @property-read string $className name of the PHP class implementing `wcf\system\menu\user\profile\content\IUserProfileMenuContent` handling outputting the content of the user profile tab | |
320f4a6d | 30 | */ |
a9229942 TD |
31 | class UserProfileMenuItem extends DatabaseObject |
32 | { | |
33 | use TDatabaseObjectOptions; | |
34 | use TDatabaseObjectPermissions; | |
35 | ||
36 | /** | |
37 | * content manager | |
38 | * @var IUserProfileMenuContent | |
39 | */ | |
40 | protected $contentManager; | |
41 | ||
42 | /** | |
43 | * @inheritDoc | |
44 | */ | |
45 | protected static $databaseTableIndexName = 'menuItemID'; | |
46 | ||
47 | /** | |
48 | * Returns the item identifier, dots are replaced by underscores. | |
49 | * | |
50 | * @return string | |
51 | */ | |
52 | public function getIdentifier() | |
53 | { | |
54 | return \str_replace('.', '_', $this->menuItem); | |
55 | } | |
56 | ||
57 | /** | |
58 | * Returns the content manager for this menu item. | |
59 | * | |
60 | * @return IUserProfileMenuContent | |
61 | * @throws SystemException | |
62 | */ | |
63 | public function getContentManager() | |
64 | { | |
65 | if ($this->contentManager === null) { | |
66 | if (!\class_exists($this->className)) { | |
26b1551b | 67 | throw new ClassNotFoundException($this->className); |
a9229942 TD |
68 | } |
69 | ||
70 | if (!\is_subclass_of($this->className, SingletonFactory::class)) { | |
71 | throw new ParentClassException($this->className, SingletonFactory::class); | |
72 | } | |
73 | ||
74 | if (!\is_subclass_of($this->className, IUserProfileMenuContent::class)) { | |
75 | throw new ImplementationException($this->className, IUserProfileMenuContent::class); | |
76 | } | |
77 | ||
78 | $this->contentManager = \call_user_func([$this->className, 'getInstance']); | |
79 | } | |
80 | ||
81 | return $this->contentManager; | |
82 | } | |
83 | ||
83c324d3 | 84 | public function __toString(): string |
a9229942 TD |
85 | { |
86 | return WCF::getLanguage()->get('wcf.user.profile.menu.' . $this->menuItem); | |
87 | } | |
320f4a6d | 88 | } |