Skip to content
Permalink
Browse files

Fix listing categories and elements in nested categories (#14729)

  • Loading branch information...
Mark-H authored and opengeek committed Sep 10, 2019
1 parent 10f3a54 commit ab518e05c0843227ccf2b3456a35ca7b709d452b
Showing with 10 additions and 8 deletions.
  1. +10 −8 core/src/Revolution/Processors/Element/GetNodes.php
@@ -349,10 +349,10 @@ public function getInCategoryNodes(array $map)
/* first handle subcategories */
$c = $this->modx->newQuery(modCategory::class);
$c->select($this->modx->getSelectColumns(modCategory::class, 'modCategory'));
$c->select('COUNT(DISTINCT ' . $elementClassKey . '.id) AS elementCount');
$c->select('COUNT(DISTINCT ' . $elementType . '.id) AS elementCount');
$c->select('COUNT(DISTINCT ' . $this->modx->getSelectColumns(modCategory::class, 'Children', '',
['id']) . ') AS childrenCount');
$c->leftJoin($elementClassKey, $elementClassKey, $elementClassKey . '.category = modCategory.id');
$c->leftJoin($elementClassKey, $elementType, $elementType . '.category = modCategory.id');
$c->leftJoin(modCategory::class, 'Children');
$c->where([
'parent' => $categoryId,
@@ -577,12 +577,12 @@ public function getTypeNodes(array $map)
$c = $this->modx->newQuery(modCategory::class);
$c->select($this->modx->getSelectColumns(modCategory::class, 'modCategory'));
$c->select('
COUNT(DISTINCT ' . $this->modx->getSelectColumns($elementClassKey, $elementClassKey, '', ['id']) . ') AS elementCount,
COUNT(DISTINCT ' . $this->modx->getSelectColumns($elementClassKey, $elementType, '', ['id']) . ') AS elementCount,
COUNT(DISTINCT ' . $this->modx->getSelectColumns(modCategory::class, 'Children', '', ['id']) . ') AS childrenCount
');
$c->leftJoin($elementClassKey, $elementClassKey,
$this->modx->getSelectColumns($elementClassKey, $elementClassKey, '',
['category']) . ' = ' . $this->modx->getSelectColumns(modCategory::class, 'modCategory', '', ['id']));
$c->leftJoin($elementClassKey, $elementType,
$this->modx->getSelectColumns($elementClassKey, $elementType, '', ['category'])
. ' = ' . $this->modx->getSelectColumns(modCategory::class, 'modCategory', '', ['id']));
$c->leftJoin(modCategory::class, 'Children');
$c->where([
'modCategory.parent' => 0,
@@ -725,13 +725,15 @@ protected function subCategoriesHaveElements($categoryId, $elementClassKey)
'parent' => $categoryId,
]);
$elementType = array_search($elementClassKey, $this->typeMap, true);
foreach ($categories as $category) {
$c = $this->modx->newQuery(modCategory::class);
$c->select($this->modx->getSelectColumns(modCategory::class, 'modCategory'));
$c->select('COUNT(DISTINCT ' . $elementClassKey . '.id) AS elementCount');
$c->select('COUNT(DISTINCT ' . $elementType . '.id) AS elementCount');
$c->select('COUNT(DISTINCT ' . $this->modx->getSelectColumns(modCategory::class, 'Children', '',
['id']) . ') AS childrenCount');
$c->leftJoin($elementClassKey, $elementClassKey, $elementClassKey . '.category = modCategory.id');
$c->leftJoin($elementClassKey, $elementType, $elementType . '.category = modCategory.id');
$c->leftJoin(modCategory::class, 'Children');
$c->where([
'id' => $category->get('id'),

0 comments on commit ab518e0

Please sign in to comment.
You can’t perform that action at this time.