Catalog.php 1022 Bytes
<?php

namespace app\models;

class Catalog extends \yii\db\ActiveRecord
{
    public static function tableName()
    {
        return 'catalog';
    }
    
    static public function getCatalogs($parent_id = 0){
       return self::find()->where(['parent_id'=>$parent_id])->orderBy('sort ASC')->with('childs')->all(); 
    }
    
    public function getChilds()
    {
        return $this->hasMany(self::className(), ['parent_id' => 'id'])->orderBy('sort ASC');
    }
    
    public function getParent()
    {
        return $this->hasOne(self::className(), ['id' => 'parent_id']);
    }

    public function getCatFasovka(){
        return (!empty($this->fasovka_name)) ? $this->fasovka_name : 'Фасовка';
    }

    public function getCatType(){
        return (!empty($this->type_name)) ? $this->type_name : 'Тип';
    }

    public function getCatBrends(){
        return (!empty($this->brends_name)) ? $this->brends_name : 'Производители';
    }
    
}