transfer_to_new_table

This commit is contained in:
SoHardKI
2019-06-27 15:41:58 +03:00
parent 0955e40eac
commit 0a9600cb00
11 changed files with 45 additions and 28 deletions

View File

@ -6,6 +6,7 @@ use common\classes\Debug;
use common\models\AdditionalFields;
use common\models\CardSkill;
use common\models\FieldsValue;
use common\models\FieldsValueNew;
use common\models\Status;
use Yii;
use backend\modules\card\models\UserCard;
@ -62,7 +63,9 @@ class UserCardController extends Controller
public function actionView($id)
{
$dataProvider = new ActiveDataProvider([
'query' => FieldsValue::find()->where(['card_id' => $id])->orderBy('order'),
'query' => FieldsValueNew::find()
->where(['item_id' => $id, 'item_type' => FieldsValueNew::TYPE_PROFILE])
->orderBy('order'),
'pagination' => [
'pageSize' => 200,
],
@ -105,7 +108,7 @@ class UserCardController extends Controller
public function actionUpdate($id)
{
$model = $this->findModel($id);
// Debug::dd($model);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}

View File

@ -5,6 +5,7 @@ namespace backend\modules\card\models;
use backend\modules\settings\models\Skill;
use common\models\CardSkill;
use common\models\FieldsValue;
use common\models\FieldsValueNew;
use yii\helpers\ArrayHelper;
class UserCard extends \common\models\UserCard
@ -16,17 +17,20 @@ class UserCard extends \common\models\UserCard
{
parent::init();
$fieldValue = FieldsValue::find()->where(
$fieldValue = FieldsValueNew::find()->where(
[
'card_id' => \Yii::$app->request->get('id'),
'project_id' => null,
'company_id' => null,
'item_id' => \Yii::$app->request->get('id'),
'item_type' => FieldsValueNew::TYPE_PROFILE,
])
->all();
$array = [];
if(!empty($fieldValue)){
foreach ($fieldValue as $item){
array_push($array, ['field_id' => $item->field_id, 'value' => $item->value, 'order' => $item->order]);
array_push($array,
['field_id' => $item->field_id,
'value' => $item->value,
'order' => $item->order,
'field_name' => $item->field->name]);
}
$this->fields = $array;
}
@ -36,6 +40,7 @@ class UserCard extends \common\models\UserCard
'field_id' => null,
'value' => null,
'order' => null,
'field_name' => null,
],
];
}
@ -54,17 +59,16 @@ class UserCard extends \common\models\UserCard
{
$post = \Yii::$app->request->post('UserCard');
if($post['fields']){
FieldsValue::deleteAll(['card_id' => $this->id]);
FieldsValueNew::deleteAll(['item_id' => $this->id, 'item_type' => FieldsValueNew::TYPE_PROFILE]);
foreach ( $post['fields'] as $item) {
$fildsValue = new FieldsValue();
$fildsValue = new FieldsValueNew();
$fildsValue->field_id = $item['field_id'];
$fildsValue->value = $item['value'];
$fildsValue->order = $item['order'];
$fildsValue->card_id = $this->id;
$fildsValue->item_id = $this->id;
$fildsValue->item_type = FieldsValueNew::TYPE_PROFILE;
$fildsValue->save();
}