| 1 | <?php |
| 2 | |
| 3 | namespace wcf\data\user\profile\menu\item; |
| 4 | |
| 5 | use wcf\data\DatabaseObject; |
| 6 | use wcf\data\TDatabaseObjectOptions; |
| 7 | use wcf\data\TDatabaseObjectPermissions; |
| 8 | use wcf\system\exception\ClassNotFoundException; |
| 9 | use wcf\system\exception\ImplementationException; |
| 10 | use wcf\system\exception\ParentClassException; |
| 11 | use wcf\system\exception\SystemException; |
| 12 | use wcf\system\menu\user\profile\content\IUserProfileMenuContent; |
| 13 | use wcf\system\SingletonFactory; |
| 14 | use wcf\system\WCF; |
| 15 | |
| 16 | /** |
| 17 | * Represents a user profile menu item. |
| 18 | * |
| 19 | * @author Alexander Ebert |
| 20 | * @copyright 2001-2019 WoltLab GmbH |
| 21 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> |
| 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 |
| 30 | */ |
| 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)) { |
| 67 | throw new ClassNotFoundException($this->className); |
| 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 | |
| 84 | public function __toString(): string |
| 85 | { |
| 86 | return WCF::getLanguage()->get('wcf.user.profile.menu.' . $this->menuItem); |
| 87 | } |
| 88 | } |