Example #1
0
 public static function treeRemove($nItemId)
 {
     $oItem = Item::model()->findByPk($nItemId);
     if (!$oItem) {
         Yii::log('Cannot find Item ID:' . $nItemId, CLogger::LEVEL_ERROR);
         return FALSE;
     }
     if (count(Item::getChildren($nItemId))) {
         Yii::log('Cannot delete Item having children ID:' . $nItemId, CLogger::LEVEL_WARNING);
         return FALSE;
     }
     $aSiblings = Item::getChildren($oItem->parentId);
     if ($oItem->position < count($aSiblings) - 1) {
         foreach ($aSiblings as $oSibling) {
             if ($oSibling->position > $oItem->position) {
                 $oSibling->position -= 1;
                 $oSibling->save();
             }
         }
     }
     if (!$oItem->delete()) {
         Yii::log('Cannot delete Item ID:' . $nItemId, CLogger::LEVEL_ERROR);
         return FALSE;
     }
     return TRUE;
 }