2021-12-27 16:50:17 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace common\models;
|
|
|
|
|
2022-01-07 15:04:11 +03:00
|
|
|
use common\helpers\TransliteratorHelper;
|
2021-12-27 16:50:17 +03:00
|
|
|
use Yii;
|
|
|
|
use yii\helpers\ArrayHelper;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the model class for table "document_field".
|
|
|
|
*
|
|
|
|
* @property int $id
|
|
|
|
* @property string $title
|
2022-01-07 15:04:11 +03:00
|
|
|
* @property string $field_template
|
2021-12-27 16:50:17 +03:00
|
|
|
*
|
|
|
|
* @property DocumentFieldValue[] $documentFieldValues
|
|
|
|
* @property TemplateDocumentField[] $templateDocumentFields
|
|
|
|
*/
|
|
|
|
class DocumentField extends \yii\db\ActiveRecord
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public static function tableName()
|
|
|
|
{
|
|
|
|
return 'document_field';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
|
|
|
return [
|
2022-01-07 15:04:11 +03:00
|
|
|
[['title', 'field_template'], 'string', 'max' => 255],
|
2021-12-27 16:50:17 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-01-07 15:04:11 +03:00
|
|
|
public function beforeSave($insert)
|
|
|
|
{
|
|
|
|
$this->field_template = TransliteratorHelper::transliterate($this->title);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-12-27 16:50:17 +03:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function attributeLabels()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'id' => 'ID',
|
|
|
|
'title' => 'Название',
|
2022-01-07 15:04:11 +03:00
|
|
|
'field_template' => 'Шаблон поля',
|
2021-12-27 16:50:17 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \yii\db\ActiveQuery
|
|
|
|
*/
|
|
|
|
public function getDocumentFieldValues()
|
|
|
|
{
|
|
|
|
return $this->hasMany(DocumentFieldValue::className(), ['field_id' => 'id']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return \yii\db\ActiveQuery
|
|
|
|
*/
|
|
|
|
public function getTemplateDocumentFields()
|
|
|
|
{
|
|
|
|
return $this->hasMany(TemplateDocumentField::className(), ['field_id' => 'id']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getIdFieldsTitleList($template_id): array
|
|
|
|
{
|
|
|
|
return
|
|
|
|
self::find()->joinWith('templateDocumentFields')
|
|
|
|
->where(['template_document_field.template_id' => $template_id])
|
|
|
|
->asArray()->all();
|
|
|
|
}
|
|
|
|
}
|