fix links to not exists files

This commit is contained in:
Leorne 2019-12-05 17:20:25 +03:00
parent 5ebdc16a8a
commit 5cff041241

View File

@ -71,18 +71,19 @@ class UserCard extends \common\models\UserCard
if ($post['fields']) { if ($post['fields']) {
FieldsValueNew::deleteAll(['item_id' => $this->id, 'item_type' => FieldsValueNew::TYPE_PROFILE]); FieldsValueNew::deleteAll(['item_id' => $this->id, 'item_type' => FieldsValueNew::TYPE_PROFILE]);
foreach ($post['fields'] as $item) { foreach ($post['fields'] as $item) {
$fildsValue = new FieldsValueNew(); $fieldsValue = new FieldsValueNew();
$fildsValue->field_id = $item['field_id']; $fieldsValue->field_id = $item['field_id'];
$fildsValue->value = $item['value']; $fieldsValue->value = $item['value'];
$fildsValue->type_file = 'text'; $fieldsValue->order = $item['order'];
if (substr($item['value'], 0, 1) == '/') { $fieldsValue->item_id = $this->id;
$fildsValue->type_file = 'file'; $fieldsValue->item_type = FieldsValueNew::TYPE_PROFILE;
if(is_file(Yii::getAlias('@frontend') . '/web/' . $item['value'])){
$fieldsValue->type_file = 'file';
}else{
$fieldsValue->type_file = 'text';
} }
$fildsValue->order = $item['order'];
$fildsValue->item_id = $this->id;
$fildsValue->item_type = FieldsValueNew::TYPE_PROFILE;
$fildsValue->save(); $fieldsValue->save();
} }
} }