diff --git a/Classes/Domain/Model/Category.php b/Classes/Domain/Model/Category.php index eee4ad6..6de9a7f 100644 --- a/Classes/Domain/Model/Category.php +++ b/Classes/Domain/Model/Category.php @@ -100,10 +100,12 @@ public function getHasPages() 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); + $where = ' sys_category_record_mm.tablenames = "pages" + AND sys_category_record_mm.fieldname = "categories" + AND sys_category_record_mm.uid_foreign = pages.uid + AND sys_category_record_mm.uid_local IN (' . implode(',', $uids) . ') + ' . $GLOBALS["TSFE"]->sys_page->enableFields('pages'); + $result = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('uid_local', 'sys_category_record_mm, pages', $where); return $result > 0; } } \ No newline at end of file diff --git a/Classes/ViewHelpers/CategoryHasItemsViewHelper.php b/Classes/ViewHelpers/CategoryHasItemsViewHelper.php new file mode 100644 index 0000000..6809637 --- /dev/null +++ b/Classes/ViewHelpers/CategoryHasItemsViewHelper.php @@ -0,0 +1,61 @@ + $category) { + if ($category instanceof Category) { + $groupCategories = array($category->getUid()); + foreach ($category->getChildrenRecursive() as $childCategory) { + $groupCategories[] = $childCategory->getUid(); + } + $categoryUids[] = $groupCategories; + } else { + $categoryUids[] = explode(',', $category); + } + } + + $from = array($tableName); + $where = array(); + foreach($categoryUids as $key => $categoryGroup) { + $mmTableName = 'mm' . $key; + $foreignTableName = $tableName; + $where[] = $mmTableName . '.tablenames = "' . $tableName . '" + AND ' . $mmTableName . '.fieldname = "' . $fieldName . '" + AND ' . $mmTableName . '.uid_local IN (' . implode(',', $categoryGroup) . ') + AND ' . $mmTableName . '.uid_foreign = ' . $foreignTableName . '.uid + '; + $from[] = 'sys_category_record_mm as ' . $mmTableName; + } +// $GLOBALS['TYPO3_DB']->store_lastBuiltQuery = 1; + $result = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', implode(', ', $from), implode(' AND ', $where) . $GLOBALS["TSFE"]->sys_page->enableFields('pages')); +// echo $GLOBALS['TYPO3_DB']->debug_lastBuiltQuery; +// exit(); + return $result > 0; + } + +}