Coding with SPIP 3.0
SPIP3.0 Technical Documentation

> > > > objet_compte_enfants

objet_compte_enfants

This pipeline is used to augment or modify the count of children of an object.

It is called as show below in the ecrire/inc/rubriques.php file:

  1. // We pass the table of counts in a pipeline so that the plugins can add (or remove) children
  2. $compte = pipeline('objet_compte_enfants',
  3. 'args' => array(
  4. 'objet' => 'rubrique',
  5. 'id_objet' => $id_rubrique,
  6. 'statut' => 'publie',
  7. 'date' => $date
  8. ),
  9. 'data' => $compte
  10. )
  11. );

Download

It accepts an argument which is the object for which you wish to count children using the objet and id_objet parameters. It can also be passed the status of the children that you want to be used to filter the count.

In the call above, we requested a count of the "published" children in a specific section.

The data contents of the pipeline is an associative array, with the key being the type of object in the plural (e.g. "articles"), and the value being an integer which matches the number of children of that type.

Example

The "Polyhiérarchie" plugin adds into sections that counts of their indirect children:

  1. function polyhier_objet_compte_enfants($flux) {
  2.  
  3. if ($flux['args']['objet']=='rubrique'){
  4. $statut = (isset($flux['args']['statut'])?" AND A.statut=".sql_quote($flux['args']['statut']):"");
  5. $postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
  6. " AND A.date <= ".sql_quote(date('Y-m-d H:i:s')) : '';
  7.  
  8. $flux['data']['articles_indirects']+= sql_countsel(
  9. "spip_rubriques_liens as RL join spip_articles as A ON (RL.objet='article' AND RL.id_objet=A.id_article)",
  10. 'RL.id_parent='.$flux['args']['id_objet'].$statut.$postdates);
  11.  
  12. $statut = (isset($flux['args']['statut'])?" AND R.statut=".sql_quote($flux['args']['statut']):"");
  13. $flux['data']['rubriques_indirectes']+= sql_countsel(
  14. "spip_rubriques_liens as RL join spip_rubriques as R ON (RL.objet='rubrique' AND RL.id_objet=R.id_rubrique)",
  15. 'RL.id_parent='.$flux['args']['id_objet'].$statut);
  16. }
  17. return $flux;
  18. }

Download