diff --git a/Classes/Domain/Model/Category.php b/Classes/Domain/Model/Category.php new file mode 100644 index 0000000..eee4ad6 --- /dev/null +++ b/Classes/Domain/Model/Category.php @@ -0,0 +1,109 @@ + + * @lazy + */ + protected $children = null; + + /** + * @var \Mia3\Mia3Categories\Domain\Model\Category|NULL + * @lazy + */ + protected $parent = null; + + public function __toString() + { + return $this->title; + } + + /** + * Returns the sorting + * + * @return integer $sorting + */ + public function getSorting() + { + return $this->sorting; + } + + /** + * Sets the sorting + * + * @param integer $sorting + * @return void + */ + public function setSorting($sorting) + { + $this->sorting = $sorting; + } + + /** + * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Mia3\Mia3Categories\Domain\Model\Category> $children + */ + public function setChildren($children) + { + $this->children = $children; + } + + /** + * @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Mia3\Mia3Categories\Domain\Model\Category> + */ + public function getChildren() + { + return ObjectStorageSorter::sort($this->children, 'sorting'); + } + + public function getChildrenRecursive($children = array()) + { + foreach ($this->children as $child) { + $children[] = $child; + $children = $child->getChildrenRecursive($children); + } + + return $children; + } + + public function getHasPages() + { + $children = $this->getChildrenRecursive(); + $uids = array($this->getUid()); + foreach($children as $child) { + $uids[] = $child->getUid(); + } + $where = ' tablenames = "pages" + AND fieldname = "categories" + AND uid_local IN (' . implode(',', $uids) . ')'; + $result = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('uid_local', 'sys_category_record_mm', $where); + return $result > 0; + } +} \ No newline at end of file diff --git a/Classes/Domain/Repository/CategoryRepository.php b/Classes/Domain/Repository/CategoryRepository.php new file mode 100644 index 0000000..adbf7a7 --- /dev/null +++ b/Classes/Domain/Repository/CategoryRepository.php @@ -0,0 +1,46 @@ +objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings::class); + $querySettings->setRespectStoragePage(FALSE); + $querySettings->setRespectSysLanguage(FALSE); + $this->setDefaultQuerySettings($querySettings); + } + + public function findByUids($uids) { + if (is_string($uids)) { + $uids = explode(',', $uids); + } + $query = $this->createQuery(); + $query->matching($query->in('uid', $uids)); + return $query->execute(); + } +} diff --git a/Configuration/TCA/Overrides/sys_category.php b/Configuration/TCA/Overrides/sys_category.php new file mode 100644 index 0000000..8fa258a --- /dev/null +++ b/Configuration/TCA/Overrides/sys_category.php @@ -0,0 +1,29 @@ + array( + 'exclude' => 1, + 'label' => 'Sortierung', + 'config' => array( + 'type' => 'passthrough' + ), + ), + 'children' => array( + 'exclude' => 1, + 'label' => 'Unterkategorien', + 'config' => array( + 'type' => 'select', + 'renderType' => 'selectMultipleSideBySide', + 'foreign_table' => 'sys_category', + 'foreign_field' => 'parent', + 'foreign_table_where' => ' AND (sys_category.sys_language_uid = 0 OR sys_category.l10n_parent = 0) ORDER BY sys_category.sorting', + 'size' => 10, + 'autoSizeMax' => 20, + 'minitems' => 0, + 'maxitems' => 20 + ), + ) +); + +\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('sys_category', $temporaryColumns); +\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes('sorting,children'); diff --git a/ext_tables.sql b/ext_tables.sql new file mode 100644 index 0000000..08b8fba --- /dev/null +++ b/ext_tables.sql @@ -0,0 +1,6 @@ +# +# Table structure for table 'sys_category' +# +CREATE TABLE sys_category ( + children int(11) unsigned DEFAULT '0' NOT NULL +); \ No newline at end of file diff --git a/ext_typoscript_setup.txt b/ext_typoscript_setup.txt new file mode 100644 index 0000000..d2ef512 --- /dev/null +++ b/ext_typoscript_setup.txt @@ -0,0 +1,19 @@ +config.tx_extbase{ + persistence{ + classes{ + + TYPO3\CMS\Extbase\Domain\Model\Category { + subclasses { + Tx_Mia3Categories_Category = Mia3\Mia3Categories\Domain\Model\Category + + } + } + Mia3\Mia3Categories\Domain\Model\Category { + mapping { + tableName = sys_category + } + } + + } + } +} \ No newline at end of file