add_additional_fields
This commit is contained in:
@ -18,6 +18,51 @@ class Balance extends \yii\db\ActiveRecord
|
||||
const TYPE_ACTIVE = 1;
|
||||
const TYPE_PASSIVE = 0;
|
||||
|
||||
public $fields;
|
||||
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
$fieldValue = FieldsValueNew::find()
|
||||
->where(
|
||||
[
|
||||
//'balance_id' => \Yii::$app->request->get('id'),
|
||||
'item_id' => $this->id,
|
||||
'item_type' => FieldsValueNew::TYPE_BALANCE,
|
||||
])
|
||||
->with('field')
|
||||
->all();
|
||||
// Debug::dd($fieldValue[0]->field->name);
|
||||
|
||||
$array = [];
|
||||
if (!empty($fieldValue)) {
|
||||
foreach ($fieldValue as $item) {
|
||||
array_push($array,
|
||||
['field_id' => $item->field_id,
|
||||
'value' => $item->value,
|
||||
'order' => $item->order,
|
||||
'field_name' => $item->field->name]);
|
||||
}
|
||||
$this->fields = $array;
|
||||
} else {
|
||||
$this->fields = [
|
||||
[
|
||||
'field_id' => null,
|
||||
'value' => null,
|
||||
'order' => null,
|
||||
'field_name' => null,
|
||||
],
|
||||
];
|
||||
}
|
||||
// $user = ArrayHelper::getColumn(ProjectUser::find()->where(['project_id' => \Yii::$app->request->get('id')])->all(),
|
||||
// 'card_id');
|
||||
//
|
||||
// if (!empty($user)) {
|
||||
// $this->user = $user;
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
public static function getTypeName($id)
|
||||
{
|
||||
return self::getTypeList()[$id];
|
||||
@ -64,7 +109,7 @@ class Balance extends \yii\db\ActiveRecord
|
||||
*/
|
||||
public function getFieldsValues()
|
||||
{
|
||||
return $this->hasMany(FieldsValueNew::class, ['item_id' => 'id', 'item_type' => FieldsValueNew::TYPE_BALANCE]);
|
||||
return $this->hasMany(FieldsValueNew::class, ['item_id' => 'id'])->where(['item_type' => FieldsValueNew::TYPE_BALANCE])->with('field');
|
||||
}
|
||||
|
||||
public function afterSave($insert, $changedAttributes)
|
||||
|
@ -62,4 +62,9 @@ class FieldsValueNew extends \yii\db\ActiveRecord
|
||||
{
|
||||
return $this->hasOne(AdditionalFields::class, ['id' => 'field_id']);
|
||||
}
|
||||
|
||||
// public function getadditional_fields()
|
||||
// {
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
Reference in New Issue
Block a user