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:

// We pass the table of counts in a pipeline so that the plugins can add (or remove) children
$compte = pipeline('objet_compte_enfants',
	array(
		'args' => array(
			'objet' => 'rubrique',
			'id_objet' => $id_rubrique,
			'statut' => 'publie',
			'date' => $date
		),
		'data' => $compte
	)
);

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:

function polyhier_objet_compte_enfants($flux) {

	if ($flux['args']['objet']=='rubrique'){
		$statut = (isset($flux['args']['statut'])?" AND A.statut=".sql_quote($flux['args']['statut']):"");
		$postdates = ($GLOBALS['meta']["post_dates"] == "non") ?
			" AND A.date <= ".sql_quote(date('Y-m-d H:i:s')) : '';

		$flux['data']['articles_indirects']+= sql_countsel(
						"spip_rubriques_liens as RL join spip_articles as A ON (RL.objet='article' AND RL.id_objet=A.id_article)",
						'RL.id_parent='.$flux['args']['id_objet'].$statut.$postdates);

		$statut = (isset($flux['args']['statut'])?" AND R.statut=".sql_quote($flux['args']['statut']):"");
		$flux['data']['rubriques_indirectes']+= sql_countsel(
						"spip_rubriques_liens as RL join spip_rubriques as R ON (RL.objet='rubrique' AND RL.id_objet=R.id_rubrique)",
						'RL.id_parent='.$flux['args']['id_objet'].$statut);
	}
	return $flux;
}

Author Mark Baber Published : Updated : 12/03/23

Translations : English, français