You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
85 lines
1.8 KiB
85 lines
1.8 KiB
<?php |
|
|
|
namespace core\entities; |
|
|
|
use paulzi\nestedsets\NestedSetsBehavior; |
|
use core\behaviors\MetaBehavior; |
|
use yii\db\ActiveRecord; |
|
use core\entities\Meta; |
|
use Yii; |
|
|
|
/** |
|
* @property integer $id |
|
* @property string $title |
|
* @property string $slug |
|
* @property string $content |
|
* @property string meta_json |
|
* @property integer $lft |
|
* @property integer $rgt |
|
* @property integer $depth |
|
* @property Meta $meta |
|
* |
|
* @property Page $parent |
|
* @property Page[] $parents |
|
* @property Page[] $children |
|
* @property Page $prev |
|
* @property Page $next |
|
* @mixin NestedSetsBehavior |
|
*/ |
|
class Page extends ActiveRecord |
|
{ |
|
public $meta; |
|
|
|
public static function create($title, $slug, $content, Meta $meta): self |
|
{ |
|
$category = new static(); |
|
$category->title = $title; |
|
$category->slug = $slug; |
|
$category->title = $title; |
|
$category->content = $content; |
|
$category->meta = $meta; |
|
return $category; |
|
} |
|
|
|
public function edit($title, $slug, $content, Meta $meta): void |
|
{ |
|
$this->title = $title; |
|
$this->slug = $slug; |
|
$this->content = $content; |
|
$this->meta = $meta; |
|
} |
|
|
|
public function getSeoTitle(): string |
|
{ |
|
return $this->meta->title ?: $this->title; |
|
} |
|
|
|
public static function tableName(): string |
|
{ |
|
return '{{%pages}}'; |
|
} |
|
|
|
public function behaviors(): array |
|
{ |
|
return [ |
|
MetaBehavior::className(), |
|
NestedSetsBehavior::className(), |
|
]; |
|
} |
|
|
|
public function transactions(): array |
|
{ |
|
return [ |
|
self::SCENARIO_DEFAULT => self::OP_ALL, |
|
]; |
|
} |
|
|
|
public function attributeLabels() { |
|
return [ |
|
'title' => Yii::t('page', 'Title'), |
|
'slug' => Yii::t('page', 'Slug'), |
|
'id' => Yii::t('page', 'ID'), |
|
'content' => Yii::t('page', 'Content'), |
|
]; |
|
} |
|
} |