getByFileable() public static method

Get the files for fileable
public static getByFileable ( string $fileableId ) : Illuminate\Database\Eloquent\Collection | static[]
$fileableId string fileable identifier
return Illuminate\Database\Eloquent\Collection | static[]
 public function getKeyFile()
 {
     if (!$this->file && $this->get('uuid')) {
         $files = File::getByFileable($this->get('uuid'));
         $this->file = $files->first();
     }
     return $this->file;
 }
Example #2
0
 /**
  * destroyItem
  * 메뉴 아이템 삭제 처리 메소드
  *
  * @param MenuHandler     $handler menu handler
  * @param string          $menuId  menu id
  * @param string          $itemId  item id
  *
  * @return RedirectResponse
  * @throws Exception
  */
 public function destroyItem(MenuHandler $handler, $menuId, $itemId)
 {
     $item = $handler->getItem($itemId);
     $menu = $item->menu;
     if ($menu->getKey() !== $menuId) {
         throw new InvalidArgumentHttpException(400);
     }
     XeDB::beginTransaction();
     try {
         $handler->removeItem($item);
         foreach (File::getByFileable($item->getKey()) as $file) {
             XeStorage::unBind($item->getKey(), $file);
         }
         $handler->deleteMenuItemTheme($item);
         $this->permissionUnregister($handler->permKeyString($item));
     } catch (Exception $e) {
         XeDB::rollback();
         return Redirect::back()->with('alert', ['type' => 'danger', 'message' => $e->getMessage()]);
     }
     XeDB::commit();
     return Redirect::route('settings.menu.index')->with('alert', ['type' => 'success', 'message' => 'MenuItem deleted']);
 }
 protected static function bindGalleryThumb($item)
 {
     /** @var \Xpressengine\Media\MediaManager $mediaManager */
     $mediaManager = \App::make('xe.media');
     // board gallery thumbnails 에 항목이 없는 경우
     if ($item->boardThumbnailFileId === null && $item->boardThumbnailPath === null) {
         // find file by document id
         $files = File::getByFileable($item->id);
         $fileId = '';
         $externalPath = '';
         $thumbnailPath = '';
         if (count($files) == 0) {
             // find file by contents link or path
             $externalPath = static::getImagePathFromContent($item->content);
             // make thumbnail
             $thumbnailPath = $externalPath;
         } else {
             foreach ($files as $file) {
                 if ($mediaManager->is($file) !== true) {
                     continue;
                 }
                 // 어떤 크기의 썸네일을 사용할 것인지 스킨 설정을 통해 결정(두배 이미지가 좋다함)
                 $dimension = 'L';
                 $media = Image::getThumbnail($mediaManager->make($file), BoardModule::THUMBNAIL_TYPE, $dimension);
                 if ($media === null) {
                     continue;
                 }
                 $fileId = $file->id;
                 $thumbnailPath = $media->url();
                 break;
             }
         }
         $item->boardThumbnailFileId = $fileId;
         $item->boardThumbnailExternalPath = $externalPath;
         $item->boardThumbnailPath = $thumbnailPath;
         $model = new BoardGalleryThumb();
         $model->fill(['targetId' => $item->id, 'boardThumbnailFileId' => $fileId, 'boardThumbnailExternalPath' => $externalPath, 'boardThumbnailPath' => $thumbnailPath]);
         $model->save();
     }
     // 없을 경우 출력될 디폴트 이미지 (스킨의 설정으로 뺄 수 있을것 같음)
     if ($item->boardThumbnailPath == '') {
         $item->boardThumbnailPath = 'http://placehold.it/300x200';
     }
 }
Example #4
0
 /**
  * Returns image url list
  *
  * @return array
  */
 public function getImages()
 {
     $files = File::getByFileable($this->getKey());
     /** @var MediaManager $mediaManager */
     $mediaManager = app('xe.media');
     $imageHandler = $mediaManager->getHandler(Media::TYPE_IMAGE);
     $images = [];
     foreach ($files as $file) {
         if ($mediaManager->getFileType($file) === Media::TYPE_IMAGE) {
             $images[] = $imageHandler->make($file);
         }
     }
     return $images;
 }
Example #5
0
 /**
  * save data
  *
  * @param Board $board board model
  * @param array $args  arguments
  * @return void
  */
 protected function saveData(Board $board, array $args)
 {
     $allowComment = 1;
     if (empty($args['allowComment']) || $args['allowComment'] !== '1') {
         $allowComment = 0;
     }
     $useAlarm = 1;
     if (empty($args['useAlarm']) || $args['useAlarm'] !== '1') {
         $useAlarm = 0;
     }
     $fileCount = FileModel::getByFileable($board->id)->count();
     $data = $board->boardData;
     if ($data === null) {
         $data = new BoardData(['allowComment' => $allowComment, 'useAlarm' => $useAlarm, 'fileCount' => $fileCount]);
     } else {
         $data->allowComment = $allowComment;
         $data->useAlarm = $useAlarm;
         $data->fileCount = $fileCount;
     }
     $board->boardData()->save($data);
 }