Monday, December 7, 2009

Check Category Level in depth return One if category is exist in given level and Zero when category have great level then given level

####Created By Rahul Dev Xarma [RDX]
function _IsCatLevel($catId,$Levels = NULL)
{
$pid = $catId;
$flage = 1;
if((!empty($Levels) || $Levels !=NULL) && $catId!=0)
{

$parents = $this->Category->find('all',array('conditions' => array('Category.id' => $pid)));
$curLevel = 0 ;

while($pid!=NULL || $pid!=0)
{
$parents = $this->Category->find('all',array('conditions' => array('Category.id' => $pid)));
//pr($parents);
$pid = $parents[0]['Category']['parent_id'];
$curLevel++;

if($curLevel == $Levels)
{
$flage = 0;
break;
}
}
}
if($flage == 0)
return 0;
else
return 1;


}
#### End Created By RDX