Example #1
0
 public static function getMedia($media)
 {
     $media = Media::find()->where('id=:id', [':id' => $media])->asArray()->one();
     if (!$media) {
         return false;
     }
     $media['data'] = unserialize($media['data']);
     $media['url'] = self::getFolderUrl($media['file'], $media['folder']);
     if (Media::isImage($media['mime_type'])) {
         $media['isImage'] = true;
         if (isset($media['data']['sizes']) && is_array($media['data']['sizes']) && count($media['data']['sizes'])) {
             foreach ($media['data']['sizes'] as $key => $thumb) {
                 $media['data']['sizes'][$key]['url'] = self::getFolderUrl($thumb['file'], $media['folder']);
             }
         }
     } else {
         $media['isImage'] = false;
     }
     return $media;
 }
 public function actionWysiwygWindow()
 {
     $dataProvider = new ActiveDataProvider(['query' => Media::find()->orderBy('created_at DESC'), 'pagination' => ['pageSize' => 24]]);
     Yii::$app->response->format = Response::FORMAT_JSON;
     return ['body' => $this->renderAjax('media-library', ['dataProvider' => $dataProvider])];
 }