<?php
class DeleteAction extends BaseAction
{
    public function run()
    {
        $id = intval(Yii::app()->request->getQuery('id'));
        $cate = Smiles::model()->findByPk($id);
        if (!empty($cate))
        {
            $smiles = Smiles::model()->findAll(array('condition'=>'type='.$id));
            if (!empty($smiles))
            {
                foreach ($smiles as $smile)
                {
                    $imageFile = $smile->getSmilePath($cate->path.'/'.$smile->path);
                    if (is_file($imageFile))
                    {
                        @unlink($imageFile);
                    }
                    $smile->delete();
                }
            }
            $cate->delete();
        }
        
        $this->getController()->redirect(array('/admin/smiles/index'));
    }
}