1 <?php
2
3 /**
4 * Object Oriented Framework: Bildet eine Kategorie der Struktur ab.
5 *
6 * @package redaxo\structure
7 */
8 class rex_category extends rex_structure_element
9 {
10 /**
11 * Return the current category.
12 *
13 * @param int $clang
14 *
15 * @return null|self
16 */
17 public static function getCurrent($clang = null)
18 {
19 $article = rex_article::getCurrent($clang);
20
21 return $article ? $article->getCategory() : null;
22 }
23
24 /**
25 * Return a list of top level categories, ie.
26 * categories that have no parent.
27 * Returns an array of rex_category objects sorted by $priority.
28 *
29 * If $ignore_offlines is set to TRUE,
30 * all categories with status 0 will be
31 * excempt from this list!
32 *
33 * @param bool $ignoreOfflines
34 * @param int $clang
35 *
36 * @return self[]
37 */
38 public static function getRootCategories($ignoreOfflines = false, $clang = null)
39 {
40 return self::getChildElements(0, 'clist', $ignoreOfflines, $clang);
41 }
42
43 /**
44 * {@inheritdoc}
45 */
46 public function getPriority()
47 {
48 return $this->catpriority;
49 }
50
51 /**
52 * Return a list of all subcategories.
53 * Returns an array of rex_category objects sorted by $priority.
54 *
55 * If $ignore_offlines is set to TRUE,
56 * all categories with status 0 will be
57 * excempt from this list!
58 *
59 * @param bool $ignoreOfflines
60 *
61 * @return self[]
62 */
63 public function getChildren($ignoreOfflines = false)
64 {
65 return self::getChildElements($this->id, 'clist', $ignoreOfflines, $this->clang_id);
66 }
67
68 /**
69 * Returns the parent category.
70 *
71 * @return self
72 */
73 public function getParent()
74 {
75 return self::get($this->parent_id, $this->clang_id);
76 }
77
78 /**
79 * Returns TRUE if this category is the direct
80 * parent of the other category.
81 *
82 * @param self $otherCat
83 *
84 * @return bool
85 */
86 public function isParent(self $otherCat)
87 {
88 return $this->getId() == $otherCat->getParentId() &&
89 $this->getClang() == $otherCat->getClang();
90 }
91
92 /**
93 * Return a list of articles in this category
94 * Returns an array of rex_article objects sorted by $priority.
95 *
96 * If $ignore_offlines is set to TRUE,
97 * all articles with status 0 will be
98 * excempt from this list!
99 *
100 * @param bool $ignoreOfflines
101 *
102 * @return rex_article[]
103 */
104 public function getArticles($ignoreOfflines = false)
105 {
106 return rex_article::getChildElements($this->id, 'alist', $ignoreOfflines, $this->clang_id);
107 }
108
109 /**
110 * Return the start article for this category.
111 *
112 * @return rex_article
113 */
114 public function getStartArticle()
115 {
116 return rex_article::get($this->id, $this->clang_id);
117 }
118
119 /**
120 * Returns the name of the category.
121 *
122 * @return string
123 */
124 public function getName()
125 {
126 return $this->catname;
127 }
128
129 /**
130 * Returns the path of the category.
131 *
132 * @return string
133 */
134 public function getPath()
135 {
136 return $this->path;
137 }
138
139 /**
140 * @param string $value
141 *
142 * @return bool
143 */
144 public static function hasValue($value)
145 {
146 return parent::_hasValue($value, ['cat_']);
147 }
148
149 /**
150 * {@inheritdoc}
151 */
152 public function isPermitted()
153 {
154 return (bool) rex_extension::registerPoint(new rex_extension_point('CAT_IS_PERMITTED', true, ['element' => $this]));
155 }
156 }
157