/** * creates a correct field depending on the file type : * if the file is a picture, it will be displayed * if the file is anything else, a link to the resource will be displayed. * * @param $file string file to put in the row * @return string the file field */ public function fileField($file) { $filepath = $this->uploadConfig[(new \ReflectionClass($this->model))->getParentClass()->name]['file']['baseUrl'] . '/' . $this->model->file; $text = $file; if (in_array(strtolower(pathinfo($filepath)['extension']), ['jpg', 'png', 'gif', ''])) { $text = Html::img($filepath, ['alt' => isset($this->model->mediaI18ns[0]) ? $this->model->mediaI18ns[0]->title : $file, 'height' => '100px', 'class' => 'thumbnail center-block']); } return Html::a($text, $filepath, ['target' => '_blank']); }
/** * Generates a hyperlink that can be clicked to cause sorting. * @param Sort $sort the current Sort instance * @param string $attribute the attribute name * @param array $options additional HTML attributes for the hyperlink tag. * There is one special attribute `label` which will be used as the label of the hyperlink. * If this is not set, the label defined in [[attributes]] will be used. * If no label is defined, [[\yii\helpers\Inflector::camel2words()]] will be called to get a label. * Note that it will not be HTML-encoded. * @return string */ public static function sortLink(Sort $sort, $attribute, $options = []) { if (($direction = $sort->getAttributeOrder($attribute)) !== null) { $class = $direction === SORT_DESC ? 'current-sort desc' : 'current-sort asc'; $icon = $direction === SORT_DESC ? 'glyphicon-sort-by-alphabet-alt' : 'glyphicon-sort-by-alphabet'; if (isset($options['class'])) { $options['class'] .= ' ' . $class; } else { $options['class'] = $class; } } else { $icon = 'glyphicon-sort-by-alphabet'; if (isset($options['class'])) { $options['class'] .= ' asc'; } else { $options['class'] = 'asc'; } } $url = $sort->createUrl($attribute); $options['data-sort'] = $sort->createSortParam($attribute); if (isset($options['label'])) { $label = $options['label']; unset($options['label']); } else { if (isset($sort->attributes[$attribute]['label'])) { $label = $sort->attributes[$attribute]['label']; } else { $label = Inflector::camel2words($attribute); } } $label .= ' <span class="glyphicon ' . $icon . '"></span>'; return Html::a($label, $url, $options); }