S
S
Sergey Miller2019-02-02 17:56:48
MODX
Sergey Miller, 2019-02-02 17:56:48

MODX Revo displaying the total number of additional resources?

I continue to study modx and pdoTools.
I have:

-Отец
--Сын 1
---Внук 1
---Внук 2
---Внук 3
---Внук 4
--Сын 2
---Внук 1
---Внук 2
---Внук 3
---Внук 4
--Сын 3
---Внук 1
---Внук 2
---Внук 3
---Внук 4

The number of sons and grandchildren will grow naturally over time.
How to count and display the number of only grandchildren using pdoTools or another plugin, if it does not conflict with pdoTools ( I just xs if this is possible ) or system methods?
Now I've put it like this for clarity:

Finally got:
<div class="countChildren">12</div>
<div class="countChildren">4</div>
<div class="countChildren">1</div>

Everything works correctly, but how to sum them up? To end up like this:
<div class="countChildren">17</div>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Lunegov, 2019-02-02
@blackseabreathe

I did this for one project. Hold.
Create a snippet. Name it, for example countGrandsons .

<?php
$id=$modx->getOption('id',$scriptProperties,0);
$c = $modx->newQuery('modResource');
$c->where(array(
  'published' => true,
  'deleted' => false,
  'isfolder' => false
));
$children = $modx->getChildIds($id);
if (count($children) > 0) {
    $c->where(array(
        'id:IN' => $children,
    ));
} else {
    $c = 0;
};
$resources = $modx->getCollection('modResource',$c);
return count($resources);

In chunks, call something like this: .
In the &id parameter , you need to specify the ID of the resource whose grandchildren you want to count.

A
Anton Tarasov, 2019-02-02
@an-tar

Try like this:


where $where is a json encoded array with the conditions you want to specify for the fetch.. say template id, published or not, etc.
And see the result in the placeholder

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question