コード例 #1
0
 /**
  * Action to get the original value of an asset
  * @param \ride\library\orm\OrmManager $orm
  * @param string $asset
  * @return null
  */
 public function assetValueAction(OrmManager $orm, FileBrowser $fileBrowser, AssetService $assetService, $asset)
 {
     $assetModel = $orm->getAssetModel();
     if (is_numeric($asset)) {
         $asset = $assetModel->getById($asset);
     } else {
         $locales = $orm->getLocales();
         foreach ($locales as $locale) {
             $asset = $assetModel->getBy(array('filter' => array('slug' => $asset)), $locale);
             if ($asset) {
                 break;
             }
         }
     }
     if (!$asset) {
         $this->response->setNotFound();
         return;
     }
     $url = $assetService->getAssetUrl($asset, $this->request->getQueryParameter('style'));
     if ($url) {
         $this->response->setRedirect($url);
         return;
     }
     $file = $fileBrowser->getFile($asset->getValue());
     if (!$file) {
         $this->response->setNotFound();
         return;
     }
     $this->setFileView($file);
 }