2018-10-11 11:15:09 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace backend\modules\project\models;
|
|
|
|
|
|
|
|
use common\classes\Debug;
|
|
|
|
use common\models\FieldsValue;
|
|
|
|
use common\models\ProjectUser;
|
|
|
|
use yii\helpers\ArrayHelper;
|
|
|
|
|
|
|
|
class Project extends \common\models\Project
|
|
|
|
{
|
|
|
|
public $fields;
|
|
|
|
public $user;
|
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
parent::init();
|
|
|
|
|
|
|
|
$fieldValue = FieldsValue::find()
|
|
|
|
->where(
|
|
|
|
[
|
|
|
|
'project_id' => \Yii::$app->request->get('id'),
|
|
|
|
'card_id' => null,
|
2018-10-11 17:45:35 +03:00
|
|
|
'company_id' => null,
|
2018-10-11 11:15:09 +03:00
|
|
|
])
|
|
|
|
->all();
|
|
|
|
$array = [];
|
|
|
|
if (!empty($fieldValue)) {
|
|
|
|
foreach ($fieldValue as $item) {
|
|
|
|
array_push($array, ['field_id' => $item->field_id, 'value' => $item->value, 'order' => $item->order]);
|
|
|
|
}
|
|
|
|
$this->fields = $array;
|
|
|
|
} else {
|
|
|
|
$this->fields = [
|
|
|
|
[
|
|
|
|
'field_id' => null,
|
|
|
|
'value' => null,
|
|
|
|
'order' => null,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
$user = ArrayHelper::getColumn(ProjectUser::find()->where(['project_id' => \Yii::$app->request->get('id')])->all(),
|
|
|
|
'card_id');
|
|
|
|
|
|
|
|
if (!empty($user)) {
|
|
|
|
$this->user = $user;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function afterSave($insert, $changedAttributes)
|
|
|
|
{
|
|
|
|
$post = \Yii::$app->request->post('Project');
|
|
|
|
|
|
|
|
FieldsValue::deleteAll(['project_id' => $this->id]);
|
|
|
|
|
|
|
|
foreach ($post['fields'] as $item) {
|
|
|
|
$fildsValue = new FieldsValue();
|
|
|
|
$fildsValue->field_id = $item['field_id'];
|
|
|
|
$fildsValue->value = $item['value'];
|
|
|
|
$fildsValue->order = $item['order'];
|
|
|
|
$fildsValue->project_id = $this->id;
|
|
|
|
|
|
|
|
$fildsValue->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
ProjectUser::deleteAll(['project_id' => $this->id]);
|
|
|
|
|
2018-11-23 16:20:49 +03:00
|
|
|
if($post['user']){
|
|
|
|
foreach ($post['user'] as $item) {
|
|
|
|
$prUser = new ProjectUser();
|
|
|
|
$prUser->project_id = $this->id;
|
|
|
|
$prUser->card_id = $item;
|
2018-10-11 11:15:09 +03:00
|
|
|
|
2018-11-23 16:20:49 +03:00
|
|
|
$prUser->save();
|
|
|
|
}
|
2018-10-11 11:15:09 +03:00
|
|
|
}
|
|
|
|
|
2018-11-23 16:20:49 +03:00
|
|
|
|
2018-10-11 11:15:09 +03:00
|
|
|
parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub
|
|
|
|
}
|
|
|
|
}
|