예제 #1
0
 /**
  * @return string the attribute name
  */
 public function getMediaUploads()
 {
     if (!$this->owner->isNewRecord) {
         return MediaUpload::getAll($this->ownerClassName, $this->owner->primaryKey);
     }
     return [];
 }
예제 #2
0
 public function actionLoad()
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     if (Yii::$app->user->isGuest) {
         $response['files'][] = ['error' => 'Please, authorise to upload files.'];
         return $response;
     }
     $bundle = MediaAsset::register($this->view);
     $ownerClass = urldecode(Yii::$app->getRequest()->post('owner_class'));
     $ownerId = Yii::$app->getRequest()->post('owner_id');
     $uploads = MediaUpload::getAll($ownerClass, $ownerId);
     foreach ($uploads as $upload) {
         $model = $upload->media;
         $response['files'][] = ['url' => $model->url, 'thumbnailUrl' => $model->getDefaultThumbUrl($bundle->baseUrl), 'id' => $model->primaryKey, 'name' => $model->filename, 'type' => $model->type, 'size' => $model->size, 'deleteUrl' => Url::to(['delete', 'id' => $model->id]), 'deleteType' => 'POST'];
     }
     return $response;
 }