Menu.php 2.48 KB
<?php

namespace common\models;

use Yii;
  

/**
 * This is the model class for table "menu".
 *
 * @property integer $menu_id
 * @property integer $menu_pid
 * @property integer $menu_lft
 * @property integer $menu_rgt
 * @property integer $termin_id
 * @property integer $show
 * @property integer $sortorder
 */
class Menu extends \yii\db\ActiveRecord
{ 
    public function getMenuList ($location_name)
    {  
        return yii::$app->db->createCommand('
            SELECT 
                `menu`.menu_id, `menu`.menu_pid, `menu`.level,
                `page_lang`.page_title, `page_lang`.page_alias,
                `template`.template_file
            FROM `menu`
                INNER JOIN `menu_location` ON `menu_location`.menu_location_id = `menu`.menu_location_id
                    AND `menu_location`.menu_location_name = "'.$location_name.'" 
                INNER JOIN `page` ON `page`.page_id = `menu`.page_id
                    AND `page`.show = 1
                INNER JOIN `page_lang` ON `page_lang`.page_id = `page`.page_id
                    AND `page_lang`.lang_id = '.yii::$app->lang_id.' 
                INNER JOIN `template` ON `template`.template_id = `page`.template_id
            WHERE `menu`.show = 1
            ORDER BY `menu`.level ASC, `menu`.sortorder ASC
        ')->queryAll();
/*
        return $this->find()
            ->selectOption('`termin_lang`.termin_title')
            ->from('menu')
            ->join(
                'INNER JOIN', 
                '`termin_lang`.termin_id = `menu`.termin_id', 
                ['lang_id' => yii::$app->lang_id])
            ->all();
*/
    }
 
    // ==== YII ====

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'menu';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['menu_pid', 'menu_lft', 'menu_rgt', 'termin_id', 'show', 'sortorder'], 'safe'],
            [['menu_pid', 'menu_lft', 'menu_rgt', 'termin_id', 'show', 'sortorder'], 'integer']
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'menu_id' => Yii::t('app', 'Menu ID'),
            'menu_pid' => Yii::t('app', 'Menu Pid'),
            'menu_lft' => Yii::t('app', 'Menu Lft'),
            'menu_rgt' => Yii::t('app', 'Menu Rgt'),
            'termin_id' => Yii::t('app', 'Termin ID'),
            'show' => Yii::t('app', 'Show'),
            'sortorder' => Yii::t('app', 'Sortorder'),
        ];
    }
 
}