guild/common/models/DocumentTemplate.php

78 lines
1.7 KiB
PHP
Raw Normal View History

2022-11-08 18:01:42 +03:00
<?php
namespace common\models;
use Yii;
2022-11-10 16:00:43 +03:00
use yii\behaviors\TimestampBehavior;
use yii\db\Expression;
2022-11-08 18:01:42 +03:00
/**
* This is the model class for table "document_template".
*
* @property int $id
* @property string $title
* @property string $template_body
2022-11-10 16:00:43 +03:00
* @property int $status
* @property string $created_at
* @property string $updated_at
2022-11-08 18:01:42 +03:00
*/
class DocumentTemplate extends \yii\db\ActiveRecord
{
private $fieldPattern = '/\${(№?\s*\w*|(\w*\s?)*)}/';
2022-11-08 18:01:42 +03:00
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'document_template';
}
2022-11-10 16:00:43 +03:00
public function behaviors()
{
return [
[
'class' => TimestampBehavior::class,
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at',
'value' => new Expression('NOW()'),
],
];
}
2022-11-08 18:01:42 +03:00
/**
* {@inheritdoc}
*/
public function rules()
{
return [
2022-11-10 16:00:43 +03:00
[['status', 'title', 'template_body'], 'required'],
2022-11-08 18:01:42 +03:00
[['template_body'], 'string'],
2022-11-10 16:00:43 +03:00
[['status'], 'integer'],
[['created_at', 'updated_at'], 'safe'],
2022-11-08 18:01:42 +03:00
[['title'], 'string', 'max' => 255],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
2022-11-10 16:00:43 +03:00
'title' => 'Название',
'template_body' => 'Тело шаблона',
'status' => 'Статус',
'created_at' => 'Created At',
'updated_at' => 'Updated At',
2022-11-08 18:01:42 +03:00
];
}
public function getFields()
{
preg_match_all($this->fieldPattern, $this->template_body,$out);
return $out[0];
}
2022-11-08 18:01:42 +03:00
}