Merge branch '5.2' into 5.3
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / data / user / profile / menu / item / UserProfileMenuItem.class.php
CommitLineData
320f4a6d
MW
1<?php
2namespace wcf\data\user\profile\menu\item;
7b9ff46b
MS
3use wcf\system\exception\ImplementationException;
4use wcf\system\exception\ParentClassException;
592454d4 5use wcf\system\menu\user\profile\content\IUserProfileMenuContent;
320f4a6d 6use wcf\data\DatabaseObject;
c1b907f3
MS
7use wcf\data\TDatabaseObjectOptions;
8use wcf\data\TDatabaseObjectPermissions;
320f4a6d 9use wcf\system\exception\SystemException;
592454d4 10use wcf\system\SingletonFactory;
5929567d 11use wcf\system\WCF;
320f4a6d
MW
12
13/**
db8a92cc 14 * Represents a user profile menu item.
320f4a6d
MW
15 *
16 * @author Alexander Ebert
7b7b9764 17 * @copyright 2001-2019 WoltLab GmbH
320f4a6d 18 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
e71525e4 19 * @package WoltLabSuite\Core\Data\User\Profile\Menu\Item
e9335ed9 20 *
ed6a4e42
MS
21 * @property-read integer $menuItemID unique id of the user profile menu item
22 * @property-read integer $packageID id of the package which delivers the user profile menu item
23 * @property-read string $menuItem textual identifier of the user profile menu item
24 * @property-read integer $showOrder position of the user profile menu item in relation to its siblings
25 * @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
26 * @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
1615fc2e 27 * @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
MW
28 */
29class UserProfileMenuItem extends DatabaseObject {
c1b907f3
MS
30 use TDatabaseObjectOptions;
31 use TDatabaseObjectPermissions;
32
320f4a6d
MW
33 /**
34 * content manager
592454d4 35 * @var IUserProfileMenuContent
320f4a6d
MW
36 */
37 protected $contentManager = null;
38
320f4a6d 39 /**
592454d4 40 * @inheritDoc
320f4a6d
MW
41 */
42 protected static $databaseTableIndexName = 'menuItemID';
43
44 /**
45 * Returns the item identifier, dots are replaced by underscores.
46 *
47 * @return string
48 */
49 public function getIdentifier() {
50 return str_replace('.', '_', $this->menuItem);
51 }
52
53 /**
54 * Returns the content manager for this menu item.
55 *
592454d4 56 * @return IUserProfileMenuContent
2b770bdd 57 * @throws SystemException
320f4a6d
MW
58 */
59 public function getContentManager() {
60 if ($this->contentManager === null) {
61 if (!class_exists($this->className)) {
62 throw new SystemException("Unable to find class '".$this->className."'");
63 }
64
592454d4 65 if (!is_subclass_of($this->className, SingletonFactory::class)) {
7b9ff46b 66 throw new ParentClassException($this->className, SingletonFactory::class);
320f4a6d
MW
67 }
68
592454d4 69 if (!is_subclass_of($this->className, IUserProfileMenuContent::class)) {
7b9ff46b 70 throw new ImplementationException($this->className, IUserProfileMenuContent::class);
320f4a6d
MW
71 }
72
058cbd6a 73 $this->contentManager = call_user_func([$this->className, 'getInstance']);
320f4a6d
MW
74 }
75
76 return $this->contentManager;
77 }
5929567d
AE
78
79 /**
80 * @return string
81 */
82 public function __toString() {
83 return WCF::getLanguage()->get('wcf.user.profile.menu.' . $this->menuItem);
84 }
320f4a6d 85}