*/
protected $definitions = array();
+ /**
+ * object type definition ids grouped by category name
+ * @var array<integer>
+ */
+ protected $definitionsByCategory = array();
+
/**
* object type definitions sorted by name
* @var array<wcf\data\object\type\definition\ObjectTypeDefinition>
protected function init() {
// get definition cache
CacheHandler::getInstance()->addResource('objectType-'.PACKAGE_ID, WCF_DIR.'cache/cache.objectType-'.PACKAGE_ID.'.php', 'wcf\system\cache\builder\ObjectTypeCacheBuilder');
+ $this->definitionsByCategory = CacheHandler::getInstance()->get('objectType-'.PACKAGE_ID, 'categories');
$this->definitions = CacheHandler::getInstance()->get('objectType-'.PACKAGE_ID, 'definitions');
foreach ($this->definitions as $definition) {
$this->definitionsByName[$definition->definitionName] = $definition;
return null;
}
+ /**
+ * Returns a list of definitions by category name or 'null' if category name is invalid.
+ *
+ * @param string $categoryName
+ * @return array<wcf\data\object\type\definition\ObjectTypeDefinition>
+ */
+ public function getDefinitionsByCategory($categoryName) {
+ if (isset($this->definitionsByCategory[$categoryName])) {
+ $definitions = array();
+ foreach ($this->definitionsByCategory[$categoryName] as $definitionID) {
+ $definitions[$definitionID] = $this->getDefinition($definitionID);
+ }
+
+ return $definitions;
+ }
+
+ return null;
+ }
+
/**
* Gets an object type by id
*
public function getData(array $cacheResource) {
list($cache, $packageID) = explode('-', $cacheResource['cache']);
$data = array(
+ 'categories' => array(),
'definitions' => array(),
'objectTypes' => array()
);
$statement->execute(array($packageID));
while ($row = $statement->fetchArray()) {
$data['definitions'][$row['definitionID']] = new ObjectTypeDefinition(null, $row);
+
+ if ($row['categoryName']) {
+ if (!isset($data['categories'][$row['categoryName']])) {
+ $data['categories'][$row['categoryName']] = array();
+ }
+
+ $data['categories'][$row['categoryName']][] = $row['definitionID'];
+ }
}
// get object types
protected function prepareImport(array $data) {
return array(
'interfaceName' => (isset($data['elements']['interfacename']) ? $data['elements']['interfacename'] : ''),
- 'definitionName' => $data['elements']['name']
+ 'definitionName' => $data['elements']['name'],
+ 'categoryName' => (isset($data['elements']['categoryname']) ? $data['elements']['categoryname'] : '')
);
}
definitionName VARCHAR(255) NOT NULL,
packageID INT(10) NOT NULL,
interfaceName VARCHAR(255) NOT NULL DEFAULT '',
+ categoryName VARCHAR(80) NOT NULL DEFAULT '',
UNIQUE KEY definitionName (definitionName, packageID)
);