Beispiel #1
0
 public static function getMediaUrl($media, $size = null)
 {
     if ($size === null) {
         $size = self::ThumbnailSize;
     }
     if (is_numeric($media)) {
         $media = self::getMedia($media);
         if (!$media || $media === null) {
             return false;
         }
         if ($media['isImage'] && isset($media['data']['sizes'][$size])) {
             return $media['data']['sizes'][$size]['url'];
         } else {
             return $media['url'];
         }
     } elseif (is_object($media)) {
         if (Media::isImage($media->mime_type) && isset($media->data['sizes'][$size])) {
             return self::getFolderUrl($media->data['sizes'][$size]['file'], $media->folder);
         } else {
             return self::getFolderUrl($media->file, $media->folder);
         }
     }
     return false;
 }
Beispiel #2
0
 public function getMedia()
 {
     return $this->hasOne(Media::className(), ['id' => 'value']);
 }
 protected function findModel($id)
 {
     if (($model = Media::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #4
0
?>
</div>
            <div class="form-group"><?php 
echo Html::button(Html::tag('i', "", ['class' => 'fa fa-trash']) . ' Удалить выбранные', ['class' => 'btn btn-sm btn-danger btn-delete hide', 'disabled' => true]);
?>
</div>
            <div class="form-group"><?php 
echo Html::button(Html::tag('i', "", ['class' => 'fa fa-refresh']) . ' Пересоздать миниатюры', ['class' => 'btn btn-sm btn-success btn-refresh' . (!$dataProvider->getTotalCount() ? " hide" : "")]);
?>
</div>
        </div>

        <?php 
echo \yii\widgets\ListView::widget(['layout' => "<div class='clearfix'>{items}</div>\n{pager}", 'dataProvider' => $dataProvider, 'itemOptions' => ['class' => 'media-item col-lg-1 col-md-2 col-sm-2 col-xs-4', 'data-url' => \yii\helpers\Url::toRoute(['window'])], 'itemView' => function ($model, $key, $index, $widget) {
    $image = false;
    if (\lenarx\media\models\Media::isImage($model->mime_type)) {
        $image = true;
    }
    $model->data = $model->data ? unserialize($model->data) : [];
    $filesize = lenarx\media\helpers\MediaLib::filesize_formatted($model->data['size']);
    return $this->render('media-item', ['model' => $model, 'image' => $image]);
}]);
?>
        <?php 
\yii\widgets\Pjax::end();
?>
    </div>

</div>

<div class="full-media-window">