drop unnecessary tables and module

This commit is contained in:
iIronside
2022-11-08 17:22:54 +03:00
parent 4efa463b18
commit 8648f5458e
66 changed files with 99 additions and 3516 deletions

View File

@ -1,65 +0,0 @@
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "accompanying_document".
*
* @property int $id
* @property int $document_id
* @property string $title
*
* @property Document $document
*/
class AccompanyingDocument extends \yii\db\ActiveRecord
{
public $accompanying_document;
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'accompanying_document';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['document_id'], 'integer'],
[['title'], 'required'],
[['title'], 'string', 'max' => 255],
[['template_file_name', 'title'], 'required'],
[['accompanying_document'], 'required', 'message'=>'Укажите путь к файлу'],
[['accompanying_document'], 'file', 'maxSize' => '100000'],
[['accompanying_document'], 'file', 'skipOnEmpty' => true, 'extensions' => 'docx'],
[['document_id'], 'exist', 'skipOnError' => true, 'targetClass' => Document::className(), 'targetAttribute' => ['document_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'document_id' => 'Документ',
'title' => 'Название',
'accompanying_document' => 'Сопроводительный документ'
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getDocument()
{
return $this->hasOne(Document::className(), ['id' => 'document_id']);
}
}

View File

@ -1,113 +0,0 @@
<?php
namespace common\models;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveQuery;
use yii\db\Expression;
use yii\db\StaleObjectException;
/**
* This is the model class for table "document".
*
* @property int $id
* @property string $title
* @property string $created_at
* @property string $updated_at
* @property int $template_id
* @property int $manager_id
*
* @property Manager $manager
* @property Template $template
* @property DocumentFieldValue[] $documentFieldValues
*/
class Document extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'document';
}
public function behaviors()
{
return [
[
'class' => TimestampBehavior::class,
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at',
'value' => new Expression('NOW()'),
],
];
}
/**
* @throws \Throwable
* @throws StaleObjectException
*/
public function beforeDelete()
{
foreach ($this->documentFieldValues as $documentFieldValue){
$documentFieldValue->delete();
}
return parent::beforeDelete();
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['created_at', 'updated_at'], 'safe'],
[['template_id', 'manager_id'], 'required'],
[['template_id', 'manager_id'], 'integer'],
['title', 'unique', 'targetAttribute' => ['title', 'template_id'], 'message'=>'Документ уже создан'],
[['title'], 'string', 'max' => 255],
[['manager_id'], 'exist', 'skipOnError' => true, 'targetClass' => Manager::className(), 'targetAttribute' => ['manager_id' => 'id']],
[['template_id'], 'exist', 'skipOnError' => true, 'targetClass' => Template::className(), 'targetAttribute' => ['template_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'title' => 'Название',
'created_at' => 'Дата создания',
'updated_at' => 'Дата обновления',
'template_id' => 'Шаблон',
'manager_id' => 'Менеджер',
];
}
/**
* @return ActiveQuery
*/
public function getManager()
{
return $this->hasOne(Manager::className(), ['id' => 'manager_id']);
}
/**
* @return ActiveQuery
*/
public function getTemplate()
{
return $this->hasOne(Template::className(), ['id' => 'template_id']);
}
/**
* @return ActiveQuery
*/
public function getDocumentFieldValues(): ActiveQuery
{
return $this->hasMany(DocumentFieldValue::className(), ['document_id' => 'id']);
}
}

View File

@ -1,80 +0,0 @@
<?php
namespace common\models;
use common\helpers\TransliteratorHelper;
use Yii;
use yii\helpers\ArrayHelper;
/**
* This is the model class for table "document_field".
*
* @property int $id
* @property string $title
* @property string $field_template
*
* @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 [
[['title', 'field_template'], 'string', 'max' => 255],
];
}
public function beforeSave($insert)
{
$this->field_template = TransliteratorHelper::transliterate($this->title);
return true;
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'title' => 'Название',
'field_template' => 'Шаблон поля',
];
}
/**
* @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();
}
}

View File

@ -1,72 +0,0 @@
<?php
namespace common\models;
use Yii;
use yii\db\ActiveQuery;
/**
* This is the model class for table "document_field_value".
*
* @property int $id
* @property int $field_id
* @property int $document_id
* @property string $value
*
* @property Document $document
* @property DocumentField $field
*/
class DocumentFieldValue extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'document_field_value';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['field_id', 'document_id', 'value'], 'required'],
[['field_id', 'document_id'], 'integer'],
[['value'], 'string', 'max' => 255],
['field_id', 'unique', 'targetAttribute' => ['field_id', 'document_id'], 'message'=>'Поле уже используется'],
[['document_id'], 'exist', 'skipOnError' => true, 'targetClass' => Document::className(), 'targetAttribute' => ['document_id' => 'id']],
[['field_id'], 'exist', 'skipOnError' => true, 'targetClass' => DocumentField::className(), 'targetAttribute' => ['field_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'field_id' => 'Поле',
'document_id' => 'Документ',
'value' => 'Значение',
];
}
/**
* @return ActiveQuery
*/
public function getDocument()
{
return $this->hasOne(Document::className(), ['id' => 'document_id']);
}
/**
* @return ActiveQuery
*/
public function getField(): ActiveQuery
{
return $this->hasOne(DocumentField::className(), ['id' => 'field_id']);
}
}

View File

@ -1,132 +0,0 @@
<?php
namespace common\models;
use Yii;
use yii\base\InvalidConfigException;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveQuery;
use yii\db\Expression;
/**
* This is the model class for table "template".
*
* @property int $id
* @property string $title
* @property string $created_at
* @property string $updated_at
* @property string $template_file_name
* @property int $document_type
*
* @property Document[] $documents
* @property TemplateDocumentField[] $templateDocumentFields
*/
class Template extends \yii\db\ActiveRecord
{
const SCENARIO_UPDATE_TITLE = 'update';
const SCENARIO_UPDATE_FILE = 'update';
public $template;
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'template';
}
public function behaviors()
{
return [
[
'class' => TimestampBehavior::class,
'createdAtAttribute' => 'created_at',
'updatedAtAttribute' => 'updated_at',
'value' => new Expression('NOW()'),
],
];
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['created_at', 'updated_at'], 'safe'],
[['title'], 'unique'],
[['document_type'], 'integer'],
[['template_file_name', 'title', 'document_type'], 'required'],
[['template'], 'required', 'message'=>'Укажите путь к файлу'],
[['template'], 'file', 'maxSize' => '100000'],
[['template'], 'file', 'skipOnEmpty' => true, 'extensions' => 'docx'],
[['title', 'template_file_name'], 'string', 'max' => 255],
];
}
public function scenarios()
{
$scenarios = parent::scenarios();
$scenarios[static::SCENARIO_UPDATE_TITLE] = ['created_at', 'updated_at', 'title', 'template_file_name'];
$scenarios[static::SCENARIO_UPDATE_FILE] = ['template'];
return $scenarios;
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'title' => 'Название',
'created_at' => 'Дата создания',
'updated_at' => 'Дата изменения',
'template_file_name' => 'Файл шаблона',
'document_type' => 'Тип документа',
];
}
public function beforeDelete()
{
foreach ($this->templateDocumentFields as $templateDocumentField){
$templateDocumentField->delete();
}
if (!empty($this->template_file_name)) {
$template_path = Yii::getAlias('@templates') . '/' . $this->template_file_name;
if(file_exists($template_path)) {
unlink($template_path);
}
}
return parent::beforeDelete();
}
/**
* @return ActiveQuery
*/
public function getDocuments()
{
return $this->hasMany(Document::className(), ['template_id' => 'id']);
}
/**
* @return ActiveQuery
*/
public function getTemplateDocumentFields()
{
return $this->hasMany(TemplateDocumentField::className(), ['template_id' => 'id']);
}
public function getTitle()
{
return $this->title;
}
public function getFields()
{
return $this->hasMany(DocumentField::className(), ['id' => 'field_id'])
->via('templateDocumentFields');
}
}

View File

@ -1,69 +0,0 @@
<?php
namespace common\models;
use Yii;
use yii\helpers\ArrayHelper;
/**
* This is the model class for table "template_document_field".
*
* @property int $id
* @property int $template_id
* @property int $field_id
*
* @property DocumentField $field
* @property Template $template
*/
class TemplateDocumentField extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'template_document_field';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['template_id', 'field_id'], 'required'],
[['template_id', 'field_id'], 'integer'],
['field_id', 'unique', 'targetAttribute' => ['template_id', 'field_id'], 'message'=>'Поле уже назначено'],
[['field_id'], 'exist', 'skipOnError' => true, 'targetClass' => DocumentField::className(), 'targetAttribute' => ['field_id' => 'id']],
[['template_id'], 'exist', 'skipOnError' => true, 'targetClass' => Template::className(), 'targetAttribute' => ['template_id' => 'id']],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'template_id' => 'Шаблон',
'field_id' => 'Поле',
];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getField()
{
return $this->hasOne(DocumentField::className(), ['id' => 'field_id'])->asArray();
}
/**
* @return \yii\db\ActiveQuery
*/
public function getTemplate()
{
return $this->hasOne(Template::className(), ['id' => 'template_id']);
}
}