Merge branch '5.3'
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / data / user / option / category / UserOptionCategory.class.php
1 <?php
2
3 namespace wcf\data\user\option\category;
4
5 use wcf\data\DatabaseObject;
6 use wcf\data\ITitledObject;
7 use wcf\system\WCF;
8
9 /**
10 * Represents a user option category.
11 *
12 * @author Marcel Werk
13 * @copyright 2001-2019 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package WoltLabSuite\Core\Data\User\Option\Category
16 *
17 * @property-read int $categoryID unique id of the user option category
18 * @property-read int $packageID id of the package which delivers the user option category
19 * @property-read string $categoryName name and textual identifier of the user option category
20 * @property-read string $parentCategoryName name of the user option category's parent category or empty if it has no parent category
21 * @property-read int $showOrder position of the user option category in relation to its siblings
22 * @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 option category
23 * @property-read string $options comma separated list of options of which at least one needs to be enabled for the user option category to be shown
24 */
25 class UserOptionCategory extends DatabaseObject implements ITitledObject
26 {
27 /**
28 * Returns the title of this category.
29 *
30 * @return string
31 */
32 public function __toString()
33 {
34 return $this->categoryName;
35 }
36
37 /**
38 * @inheritDoc
39 */
40 public function getTitle()
41 {
42 return WCF::getLanguage()->get('wcf.user.option.category.' . $this->categoryName);
43 }
44
45 /**
46 * Returns an instance of UserOptionCategory by name.
47 *
48 * @param string $categoryName
49 * @return UserOptionCategory
50 */
51 public static function getCategoryByName($categoryName)
52 {
53 $sql = "SELECT *
54 FROM wcf" . WCF_N . "_user_option_category
55 WHERE categoryName = ?";
56 $statement = WCF::getDB()->prepareStatement($sql);
57 $statement->execute([$categoryName]);
58 $row = $statement->fetchArray();
59 if ($row === false) {
60 return;
61 }
62
63 return new self(null, $row);
64 }
65 }