Vox Populi(x) forum

Alexandria Book Library => Richieste (Requests) => Topic started by: lsu on 11 August 2011, 14:59:37

Title: Recursive total of books in category view
Post by: lsu on 11 August 2011, 14:59:37
Hello,

In category view we wanted to see the total of books in each category including its subcategories. Therefor I extended the default.php template files of the category and categories by removing this
Code: [Select]
(<?php echo $row->numero?>)
and adding this
Code: [Select]
(<?php 

$numero $row->numero;
$depth 0;
$parents[$depth] = $row->id;
/* Count the total number of books, including subcategories */
/* This method only works because the tree is sorted        */
foreach($rows as $rownum) {
$couldbeachild true;
while ($couldbeachild) {
/* Is it a children? */
if ($rownum->parent_id == $parents[$depth]) {
/* Yes, its a child, add the number of books*/
$numero += $rownum->numero;

/* Assume there is are child item(s) inside, increase depth... */
$depth++;
$parents[$depth] = $rownum->id;
break;
}
elseif ($depth == 0)
$couldbeachild false;
else
$depth--;
}
}
echo $numero;

 ?>
)

Would be cool if this code could be included into the upstream version. Also it may be necessary to add a option for this feature (should be easy, just put an if around the whole for loop)

Bye
Stefan
Title: Re: Recursive total of books in category view
Post by: federica on 22 August 2011, 12:25:54
Hi Stefan,
thanks for your contribution.
I will add your code in the next version of abook.