addition fields images
This commit is contained in:
parent
5cff041241
commit
9db4ea8abd
@ -78,10 +78,7 @@ $this->params['breadcrumbs'][] = $this->title;
|
|||||||
'attribute' => 'value',
|
'attribute' => 'value',
|
||||||
'format' => 'raw',
|
'format' => 'raw',
|
||||||
'value' => function ($model) {
|
'value' => function ($model) {
|
||||||
if ($model->type_file == 'file') {
|
return $model->getValue();
|
||||||
return $model->value . ' (' . Html::a('Скачать', $model->value, ['target' => '_blank', 'download' => 'download']) . ')';
|
|
||||||
}
|
|
||||||
return $model->value;
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
@ -46,10 +46,7 @@ $this->params['breadcrumbs'][] = $this->title;
|
|||||||
'attribute' => 'value',
|
'attribute' => 'value',
|
||||||
'format' => 'raw',
|
'format' => 'raw',
|
||||||
'value' => function ($model) {
|
'value' => function ($model) {
|
||||||
if ($model->type_file == 'file') {
|
return $model->getValue();
|
||||||
return $model->value . ' (' . Html::a('Скачать', $model->value, ['target' => '_blank', 'download' => 'download']) . ')';
|
|
||||||
}
|
|
||||||
return $model->value;
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
namespace common\models;
|
namespace common\models;
|
||||||
|
|
||||||
use Yii;
|
use Yii;
|
||||||
|
use yii\base\ErrorException;
|
||||||
|
use yii\base\Exception;
|
||||||
|
use yii\helpers\Html;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the model class for table "fields_value_new".
|
* This is the model class for table "fields_value_new".
|
||||||
@ -23,6 +26,7 @@ class FieldsValueNew extends \yii\db\ActiveRecord
|
|||||||
const TYPE_COMPANY = 2;
|
const TYPE_COMPANY = 2;
|
||||||
const TYPE_BALANCE = 3;
|
const TYPE_BALANCE = 3;
|
||||||
const TYPE_NOTE = 4;
|
const TYPE_NOTE = 4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
@ -67,4 +71,61 @@ class FieldsValueNew extends \yii\db\ActiveRecord
|
|||||||
return $this->hasOne(AdditionalFields::class, ['id' => 'field_id']);
|
return $this->hasOne(AdditionalFields::class, ['id' => 'field_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function isImage()
|
||||||
|
{
|
||||||
|
if ($this->type_file === 'text') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try{
|
||||||
|
$mime = mime_content_type(Yii::getAlias('@frontend/web' . $this->value));
|
||||||
|
}catch (ErrorException $e){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$extension = explode('/', $mime)['0'];
|
||||||
|
if (($extension === 'image') || $extension === 'application') {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getValue()
|
||||||
|
{
|
||||||
|
$test = $this->type_file === 'file' ? $this->getFileValue() : $this->getTextValue();
|
||||||
|
return $test;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFileValue()
|
||||||
|
{
|
||||||
|
$filename = $this->getFileName();
|
||||||
|
$filePath = Yii::getAlias('@frontend/web' . $this->value);
|
||||||
|
if($this->isImage()){
|
||||||
|
$imageHTML = Html::img($this->value, ['width' => '200px', 'alt' => $filename]);
|
||||||
|
$downloadLinkHTML = ' (' . Html::a('Скачать', $this->value, ['target' => '_blank', 'download' => $filename]) . ')';
|
||||||
|
$result = $imageHTML . $downloadLinkHTML;
|
||||||
|
}else{
|
||||||
|
$result = $filename . ' (' . Html::a('Скачать', $this->value, ['target' => '_blank', 'download' => $filename]) . ')';
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTextValue()
|
||||||
|
{
|
||||||
|
return $this->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFileName(){
|
||||||
|
if($this->type_file === 'file'){
|
||||||
|
$explode = explode('/', $this->value);
|
||||||
|
$filename = array_pop($explode);
|
||||||
|
return $filename;
|
||||||
|
}
|
||||||
|
return $this->value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user