kokjan/common/models/CmsMenuFrontend.php

104 lines
2.5 KiB
PHP

<?php
namespace common\models;
use Yii;
use yii\behaviors\TimestampBehavior;
/**
* This is the model class for table "cms_menu_frontend".
*
* @property int $id
* @property int|null $parent_id
* @property string $name
* @property string|null $link
* @property string $position navbar, left_menu
* @property int|null $sort_order
* @property int|null $status
* @property int|null $created_at
* @property int|null $updated_at
*
* @property CmsMenuFrontend $parent
* @property CmsMenuFrontend[] $cmsMenuFrontends
*/
class CmsMenuFrontend extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'cms_menu_frontend';
}
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
TimestampBehavior::class,
];
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['parent_id', 'sort_order', 'status', 'created_at', 'updated_at'], 'integer'],
[['name', 'position'], 'required'],
[['name', 'link'], 'string', 'max' => 255],
[['position'], 'string', 'max' => 50],
[['parent_id'], 'exist', 'skipOnError' => true, 'targetClass' => CmsMenuFrontend::class, 'targetAttribute' => ['parent_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'parent_id' => 'เมนูหลัก',
'name' => 'ชื่อเมนู',
'link' => 'ลิงก์',
'position' => 'ตำแหน่ง',
'sort_order' => 'ลำดับ',
'status' => 'สถานะ',
'created_at' => 'สร้างเมื่อ',
'updated_at' => 'แก้ไขเมื่อ',
];
}
/**
* Gets query for [[Parent]].
*
* @return \yii\db\ActiveQuery
*/
public function getParent()
{
return $this->hasOne(CmsMenuFrontend::class, ['id' => 'parent_id']);
}
/**
* Gets query for [[CmsMenuFrontends]].
*
* @return \yii\db\ActiveQuery
*/
public function getCmsMenuFrontends()
{
return $this->hasMany(CmsMenuFrontend::class, ['parent_id' => 'id']);
}
public static function getPositions()
{
return [
'navbar' => 'Navbar (แถบเมนูบน)',
'left_menu' => 'Left Menu (แถบเมนูข้าง)',
];
}
}