示例#1
0
 /**
  * Return the controller to be used to display an asset.
  *
  * @param Asset $asset
  *
  * @return string
  */
 public static function controller(AssetModel $asset)
 {
     $namespace = 'BoomCMS\\Http\\Controllers\\ViewAsset\\';
     if (!$asset->getExtension()) {
         return;
     }
     $byExtension = $namespace . ucfirst($asset->getExtension());
     if (class_exists($byExtension)) {
         return $byExtension;
     }
     $byType = $namespace . ucfirst($asset->getType());
     if (class_exists($byType)) {
         return $byType;
     }
     return $namespace . 'BaseController';
 }
 public function boot()
 {
     parent::boot();
     Models\Asset::observe(CreationLogObserver::class);
     Models\AssetVersion::observe(CreationLogObserver::class);
     Models\Page::observe(CreationLogObserver::class);
     Models\PageVersion::observe(CreationLogObserver::class);
     Models\Asset::observe(SetSiteObserver::class);
     Models\Group::observe(SetSiteObserver::class);
     Models\Page::observe(SetSiteObserver::class);
     Models\Tag::observe(SetSiteObserver::class);
     Models\URL::observe(SetSiteObserver::class);
     Models\Page::observe(DeletionLogObserver::class);
 }
示例#3
0
 /**
  * @param AssetModel $model
  *
  * @return AssetModel
  */
 public function save(AssetModel $model)
 {
     $model->save();
     return $model;
 }
示例#4
0
 public function testSetVersion()
 {
     $asset = new Asset();
     $version = new AssetVersion();
     $asset->setVersion($version);
     $this->assertEquals($version, $asset->getLatestVersion());
 }
示例#5
0
 /**
  * @param Request $request
  * @param Asset   $asset
  */
 public function update(Request $request, Asset $asset, Site $site)
 {
     $this->authorize('manageAssets', $site);
     $asset->setTitle($request->input(Asset::ATTR_TITLE))->setDescription($request->input(Asset::ATTR_DESCRIPTION))->setCredits($request->input(Asset::ATTR_CREDITS))->setThumbnailAssetId($request->input(Asset::ATTR_THUMBNAIL_ID));
     AssetFacade::save($asset);
     return $this->show($asset);
 }
示例#6
0
 public function upload()
 {
     $assetIds = [];
     list($validFiles, $errors) = $this->validateFileUpload();
     foreach ($validFiles as $file) {
         $asset = new Asset();
         $asset->setUploadedTime(new DateTime('now'))->setUploadedBy(Auth::getPerson())->setTitle($file->getClientOriginalName())->setType(AssetHelper::typeFromMimetype($file->getMimeType()));
         $assetIds[] = AssetFacade::save($asset)->getId();
         AssetFacade::createVersionFromFile($asset, $file);
     }
     return count($errors) ? new JsonResponse($errors, 500) : $assetIds;
 }
 public function destroy(Request $request, Asset $asset = null)
 {
     $assetIds = $asset->getId() ? [$asset->getId()] : $request->input('assets');
     AssetFacade::delete($assetIds);
 }