userId) { $this->userId = \Yii::$app->user->id; } } /** * @inheritdoc */ public function run() { Yii::$app->response->format = Response::FORMAT_JSON; $attachments = Attachment::findAll(["user_id" => $this->userId]); $list = []; foreach ($attachments as $attachment) { $mediaItem = MediaItem::createFromAttachment($attachment); if ($mediaItem->getFileType() === MediaItem::FILE_TYPE_IMAGE) { $list[] = [ 'title' => $attachment->title, 'thumb' => $attachment->getUrl() , 'image' => $attachment->getUrl() , ]; } elseif ($mediaItem->getFileType() === MediaItem::FILE_TYPE_DOCUMENT) { $list[] = [ 'title' => $attachment->title, 'name' => $attachment->title, 'link' =>$attachment->getUrl(), 'size' => $attachment->size ]; } else { $list[] = $url; } } return $list; } }