Vox Populi(x) forum
21 Maggio 2012, 03:16:52 *
   Indice   Aiuto Ricerca Accedi Registrati  
Pagine: [1]
  Stampa  
Autore Discussione: Recursive total of books in category view  (Letto 262 volte)
lsu
Coccinella
*

Karma: +0/-0
Scollegato Scollegato

Messaggi: 2


Mostra profilo
« inserita:: 11 Agosto 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
Codice: [Select]
(<?php echo $row->numero?>)
and adding this
Codice: [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
Vox Populi(x) forum
« inserita:: 11 Agosto 2011, 14:59:37 »

 
federica
Amministratore
Volpe
*****

Karma: +0/-0
Scollegato Scollegato

Messaggi: 299



Mostra profilo WWW
« Risposta #1 inserita:: 22 Agosto 2011, 12:25:54 »

Hi Stefan,
thanks for your contribution.
I will add your code in the next version of abook.
Vox Populi(x) forum
« Risposta #1 inserita:: 22 Agosto 2011, 12:25:54 »

 
Pagine: [1]
  Stampa  
 
 

A cura di Neomediatech