/** * Get the number of child nodes * * If the direct parameter is set to true, only the direct children are counted (based upon the parent_id field) * If false is passed for the id parameter, all top level nodes are counted, or all nodes are counted. * * Scoped behavior: * * If the model is scoped and the id parameter is given it will automatically set the scope. To count the top * level nodes you have to pass the scopeField as the id parameter. * * Example: array('scope' => 5) or array('id' => false, 'scope' => 5) * * @param AppModel $Model Model instance * @param mixed $id The ID of the record to read or false to read all top level nodes * @param boolean $direct whether to count direct, or all, children * @return integer number of child nodes * @access public * @link http://book.cakephp.org/view/1347/Counting-children */ public function childcount($Model, $id = null, $direct = false) { if ($this->scoped($Model)) { if (empty($id)) { return false; } $id = $this->__setScopeFromId($Model, $id); } return parent::childcount($Model, $id, $direct); }