예제 #1
0
 /**
  * Count number of nodes for a term and its children.
  * 
  * @param int $tid
  *   Id of the tadonomy term to count nodes in.
  * @return int
  *   Returns the count of the nodes in the given term.
  */
 public static function taxonomyTermCountNodes($tid)
 {
     static $count;
     if (!isset($count) || !isset($count[$tid])) {
         $query = db_select('node', 'n')->fields('n', array('nid'))->addTag('node_access');
         $query->join('taxonomy_index', 'ti', 'n.nid = ti.nid');
         $query->join('node_field_data', 'd', 'd.nid = n.nid');
         $query->condition('n.type', 'faq')->condition('d.status', 1)->condition('ti.tid', $tid);
         $count[$tid] = $query->countQuery()->execute()->fetchField();
     }
     $children_count = 0;
     foreach (FaqHelper::taxonomyTermChildren($tid) as $child_term) {
         $children_count += FaqHelper::taxonomyTermCountNodes($child_term);
     }
     return $count[$tid] + $children_count;
 }