|
|
|
<?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
|
|
|
|
{
|
|
|
|
$page = new static();
|
|
|
|
$page->title = $title;
|
|
|
|
$page->slug = $slug;
|
|
|
|
$page->content = $content;
|
|
|
|
$page->meta = $meta;
|
|
|
|
return $page;
|
|
|
|
}
|
|
|
|
|
|
|
|
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'),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|