public function actionDeleteLogoFile($id)
    {
        $id = (int)$id;
        // check that you have access to this note
        $file = CategoryArticle::model()->findByPk($id);
        if(!empty($file)){
           // Delete file
            $filename = $file->logotip;
            $imagePath = $file->getFileFolder() . $filename;
            if(file_exists($imagePath)) {
                unlink($imagePath); //delete file
            }
            $file->logotip = '';
            $file->logotip_realname = '';
            $file->saveNode(array('logotip','logotip_realname'));
                echo "[]";
                Yii::app()->end();
        }

        
        echo 'error';
        Yii::app()->end();
    }
示例#2
0
	public function applyCategoriesWithSub($categories, $select = 't.*')
	{
		$cat = array();
		
		if($categories instanceof CategoryArticle){

        	$cat[] = $categories->id;
        	$category = CategoryArticle::model()->findByPk($categories->id);
			$descendants = $category->descendants()->findAll();
			if(!empty($descendants)){
			foreach($descendants as $c){
                        if(is_object($c)){
                            $cat[] = $c->id;
                        } else {
                            $cat[] = $c;
                        }
                    }
            }
             $categories = $cat;

        } 
 
		$criteria = new CDbCriteria;

		if($select)
			$criteria->select = $select;
                
		$criteria->join = 'LEFT JOIN "article_category" "categorization" ON ("categorization"."article"="t"."id")';

		$criteria->addInCondition('categorization.category', $categories);
		
                $this->getDbCriteria()->mergeWith($criteria);

		return $this;
	}
示例#3
0
    public function checkIfAvailable($attr)
    {
        $labels = $this->attributeLabels();
        $check = CategoryArticle::model()->countByAttributes(array(
            $attr=>$this->$attr,
        ), 't.id != :id', array(':id'=>(int)$this->id));

        if($check>0)
            $this->addError($attr, $labels[$attr].' '.Yii::t('site', 'is occupied'));
    }
 public function _loadModel($url)
 {
     // Find category
     $model = CategoryArticle::model()
                       ->withUrl($url)
                       ->find();
     if (!$model) throw new CHttpException(404, 'Категория не найдена.');
             
     return $model;
 }