Example #1
0
 /**
  * Setup query
  * 
  * @param  Model $model
  * @return Model
  */
 protected function setupQuery($model)
 {
     $userId = $this->auth->user()->id;
     if ($this->authis->check('media.admin.libraries.view.all')) {
         return $model;
     } else {
         return $model->where(function ($query) use($userId) {
             $query->where('user_id', $userId)->orWhere(function ($query) use($userId) {
                 $query->whereHas('users', function ($query) use($userId) {
                     $query->where('user_id', $userId);
                 });
             })->orWhere('visibility', 'public');
         });
     }
 }
Example #2
0
 /**
  * Generate returned data
  * 
  * @param  array $library
  * @return array
  */
 protected function generateReturnedData($library)
 {
     if ($library['description']['is_moved']) {
         $filesystem = $this->filesystemFactory->disk($library['description']['storage']);
     } else {
         $filesystem = $this->filesystemFactory->disk('local');
     }
     $library['description']['mime'] = $filesystem->exists($library['description']['path']) ? $filesystem->mimeType($library['description']['path']) : 'NaN';
     $library['description']['size'] = $filesystem->exists($library['description']['path']) ? $filesystem->size($library['description']['path']) : 'NaN';
     if (is_image($library['description']['mime'])) {
         $library['description']['thumbnail'] = $library['description']['path'] . '/medium';
     } else {
         $library['description']['thumbnail'] = '';
     }
     $resourceChecker = $this->authis->forResource(MediaLibrary::find($library['id']));
     $library['description']['shareable'] = $resourceChecker->check('media.admin.libraries.share.get');
     $library['description']['updateable'] = $resourceChecker->check('media.admin.libraries.update.get');
     $library['description']['publishable'] = $resourceChecker->check('media.admin.libraries.manage-publishment.get');
     $library['description']['deletable'] = $resourceChecker->check('media.admin.libraries.delete.get');
     return $library;
 }
Example #3
0
 /**
  * Remove library
  * 
  * @param  Library $entity
  * @return void
  */
 public function remove(MediaDomainModels\Library $entity)
 {
     $library = $this->model->find($entity->id()->value());
     $library->users()->detach();
     $library->delete();
 }