3 namespace wcf\data\smiley\category
;
5 use wcf\data\category\AbstractDecoratedCategory
;
6 use wcf\data\ITraversableObject
;
7 use wcf\data\smiley\Smiley
;
8 use wcf\data\smiley\SmileyCache
;
9 use wcf\system\exception\SystemException
;
13 * Represents a smiley category.
15 * @author Tim Duesterhus, Alexander Ebert
16 * @copyright 2001-2019 WoltLab GmbH
17 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
18 * @package WoltLabSuite\Core\Data\Smiley\Category
20 * @method SmileyCategory[] getChildCategories()
21 * @method SmileyCategory[] getAllChildCategories()
22 * @method SmileyCategory getParentCategory()
23 * @method SmileyCategory[] getParentCategories()
24 * @method static SmileyCategory|null getCategory($categoryID)
26 class SmileyCategory
extends AbstractDecoratedCategory
implements \Countable
, ITraversableObject
29 * current iterator index
35 * list of index to object relation
38 protected $indexToObject;
41 * list of assigned smilies
47 * Loads associated smilies from cache.
49 public function loadSmilies()
51 if ($this->smilies
=== null) {
52 $this->smilies
= SmileyCache
::getInstance()->getCategorySmilies($this->categoryID ?
: null);
53 $this->indexToObject
= \array_keys
($this->smilies
);
60 public function count()
62 return \
count($this->smilies
);
69 public function current()
71 $objectID = $this->indexToObject
[$this->index
];
73 return $this->smilies
[$objectID];
77 * CAUTION: This methods does not return the current iterator index,
78 * rather than the object key which maps to that index.
80 * @see \Iterator::key()
84 return $this->indexToObject
[$this->index
];
90 public function next()
98 public function rewind()
106 public function valid()
108 return isset($this->indexToObject
[$this->index
]);
114 public function seek($index)
116 $this->index
= $index;
118 if (!$this->valid()) {
119 throw new \
OutOfBoundsException();
126 public function seekTo($objectID)
128 $this->index
= \array_search
($objectID, $this->indexToObject
);
130 if ($this->index
=== false) {
131 throw new SystemException("object id '" . $objectID . "' is invalid");
137 * @return Smiley|null
139 public function search($objectID)
142 $this->seekTo($objectID);
144 return $this->current();
145 } catch (SystemException
$e) {
151 * Returns the category's name.
155 public function __toString()
157 return WCF
::getLanguage()->get($this->title
);