| Current Path : /var/www/html/chatbot/backend/models/ |
| Current File : /var/www/html/chatbot/backend/models/Category.php |
<?php
namespace backend\models;
use Yii;
use common\models\Dermaga;
/**
* This is the model class for table "ost_bul_cat".
*
* @property string $id
* @property string $title
* @property integer $parent_id
* @property integer $level
* @property string $status
* @property string $access
* @property integer $sort
* @property string $created_by
* @property string $created_at
* @property string $updated_by
* @property string $updated_at
* @property string $deleted_at
*
* @property OstBulCatLang[] $ostBulCatLangs
*/
class Category extends Dermaga
{
/**
* @inheritdoc
*/
public $titlebm;
public static function tableName()
{
return 'dmg_bul_cat';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['title','titlebm'],'required'],
[['parent_id', 'level', 'sort'], 'integer'],
[['created_at', 'updated_at', 'deleted_at'], 'safe'],
[['title','titlebm'], 'string', 'max' => 255],
[['status', 'access'], 'string', 'max' => 5],
[['created_by', 'updated_by'], 'string', 'max' => 50],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'title' => Yii::t('app','Title (English Version)'),
'titlebm'=> Yii::t('app','Title(Malay Version)'),
'parent_id' => Yii::t('app','Parent'),
'level' => Yii::t('app','Level'),
'status' => Yii::t('app','Status'),
'access' => Yii::t('app','Access'),
'sort' => Yii::t('app','Sort'),
'created_by' => Yii::t('app','Created By'),
'created_at' => Yii::t('app','Created At'),
'updated_by' => Yii::t('app','Updated By'),
'updated_at' => Yii::t('app','Updated Date'),
'deleted_at' => Yii::t('app','Deleted At'),
];
}
public static function getParentList() {
$arr = array();
$rows = Category::getCatList();
foreach ($rows as $row) {
$arr[$row->id] = Category::marker($row->level) . ' ' . $row->title;
}
return $arr;
}
public static function getCatList($level = 1) {
$arr = array();
$rows = self::find()->where(['level' => $level])->all();
foreach ($rows as $row) {
array_push($arr, $row);
Category::getCat($row->id, $arr);
}
return $arr;
}
public static function getCat($parent_id, &$arr) {
$rows = self::find()->where(['parent_id' => $parent_id])->all();
foreach ($rows as $row) {
array_push($arr, $row);
$rows2 = Category::getCat($row->id, $arr);
}
}
public static function marker($level) {
$str = '|';
for ($i = 1; $i < $level; $i++) {
$str .= '__+';
}
return $str;
}
public static function getNameParent($id) {
$ref = self::find()->where("id = '$id'")->one();
if ($ref != '') {
return $ref->title;
} else {
return '';
}
}
/**
* @return \yii\db\ActiveQuery
*/
public function getOstBulCatLangs()
{
return $this->hasMany(Category::className(), ['cat_id' => 'id']);
}
public function getHrinfo() {
return $this->hasOne(Staff::className(), ['id' => 'updated_by']);
}
}