intermediate commit
This commit is contained in:
@ -4,6 +4,7 @@ namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use yii\db\ActiveQuery;
|
||||
use yii\db\Expression;
|
||||
use yii\db\StaleObjectException;
|
||||
|
||||
@ -87,7 +88,7 @@ class Document extends \yii\db\ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getManager()
|
||||
{
|
||||
@ -95,7 +96,7 @@ class Document extends \yii\db\ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getTemplate()
|
||||
{
|
||||
@ -103,9 +104,9 @@ class Document extends \yii\db\ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getDocumentFieldValues()
|
||||
public function getDocumentFieldValues(): ActiveQuery
|
||||
{
|
||||
return $this->hasMany(DocumentFieldValue::className(), ['document_id' => 'id']);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use common\helpers\TransliteratorHelper;
|
||||
use Yii;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
@ -10,6 +11,7 @@ use yii\helpers\ArrayHelper;
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $title
|
||||
* @property string $field_template
|
||||
*
|
||||
* @property DocumentFieldValue[] $documentFieldValues
|
||||
* @property TemplateDocumentField[] $templateDocumentFields
|
||||
@ -30,10 +32,16 @@ class DocumentField extends \yii\db\ActiveRecord
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['title'], 'string', 'max' => 255],
|
||||
[['title', 'field_template'], 'string', 'max' => 255],
|
||||
];
|
||||
}
|
||||
|
||||
public function beforeSave($insert)
|
||||
{
|
||||
$this->field_template = TransliteratorHelper::transliterate($this->title);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -42,6 +50,7 @@ class DocumentField extends \yii\db\ActiveRecord
|
||||
return [
|
||||
'id' => 'ID',
|
||||
'title' => 'Название',
|
||||
'field_template' => 'Шаблон поля',
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\db\ActiveQuery;
|
||||
|
||||
/**
|
||||
* This is the model class for table "document_field_value".
|
||||
@ -54,7 +55,7 @@ class DocumentFieldValue extends \yii\db\ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getDocument()
|
||||
{
|
||||
@ -62,10 +63,17 @@ class DocumentFieldValue extends \yii\db\ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getField()
|
||||
public function getField(): ActiveQuery
|
||||
{
|
||||
return $this->hasOne(DocumentField::className(), ['id' => 'field_id']);
|
||||
}
|
||||
|
||||
public function getFieldsArray()
|
||||
{
|
||||
return '44';
|
||||
// self::find()->select(['value', 'document_field.title', 'document_field.template'])
|
||||
// ->joinWith('field')->asArray()->all();
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,9 @@
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\InvalidConfigException;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use yii\db\ActiveQuery;
|
||||
use yii\db\Expression;
|
||||
|
||||
/**
|
||||
@ -20,7 +22,7 @@ use yii\db\Expression;
|
||||
*/
|
||||
class Template extends \yii\db\ActiveRecord
|
||||
{
|
||||
public $template;
|
||||
// public $template;
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
@ -50,9 +52,9 @@ class Template extends \yii\db\ActiveRecord
|
||||
[['created_at', 'updated_at'], 'safe'],
|
||||
[['title'], 'unique'],
|
||||
[['template_file_name', 'title'], 'required'],
|
||||
[['template'], 'required', 'message'=>'Укажите путь к файлу'],
|
||||
[['template'], 'file', 'maxSize' => '10000'],
|
||||
[['template'], 'file', 'skipOnEmpty' => false, 'extensions' => 'doc, docx, txt'],
|
||||
// [['template'], 'required', 'message'=>'Укажите путь к файлу'],
|
||||
// [['template'], 'file', 'maxSize' => '10000'],
|
||||
// [['template'], 'file', 'skipOnEmpty' => false, 'extensions' => 'doc, docx, txt'],
|
||||
[['title', 'template_file_name'], 'string', 'max' => 255],
|
||||
];
|
||||
}
|
||||
@ -78,7 +80,7 @@ class Template extends \yii\db\ActiveRecord
|
||||
}
|
||||
|
||||
if (!empty($this->template_file_name)) {
|
||||
$template_path = Yii::getAlias('@templates') . '/' . $this->template_file_name;
|
||||
$template_path = Yii::getAlias('@templates') . $this->template_file_name;
|
||||
|
||||
if(file_exists($template_path)) {
|
||||
unlink($template_path);
|
||||
@ -88,7 +90,7 @@ class Template extends \yii\db\ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getDocuments()
|
||||
{
|
||||
@ -96,10 +98,27 @@ class Template extends \yii\db\ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getTemplateDocumentFields()
|
||||
{
|
||||
return $this->hasMany(TemplateDocumentField::className(), ['template_id' => 'id']);
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
//TODO no need, delete
|
||||
public function getDocumentFields()
|
||||
{
|
||||
$fieldsArray = [];
|
||||
|
||||
foreach ($this->templateDocumentFields as $templateDocField) {
|
||||
$fieldsArray[] = $templateDocField->field;
|
||||
}
|
||||
|
||||
return $fieldsArray;
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class TemplateDocumentField extends \yii\db\ActiveRecord
|
||||
*/
|
||||
public function getField()
|
||||
{
|
||||
return $this->hasOne(DocumentField::className(), ['id' => 'field_id']);
|
||||
return $this->hasOne(DocumentField::className(), ['id' => 'field_id'])->asArray();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user