示例#1
0
 public function has_access_to_subdef(RecordInterface $record, $subdef_name)
 {
     if ($subdef_name == 'thumbnail') {
         return true;
     }
     if ($record->isStory()) {
         return true;
     }
     $databox = $this->app->findDataboxById($record->getDataboxId());
     try {
         $subdef_class = $databox->get_subdef_structure()->get_subdef($record->getType(), $subdef_name)->get_class();
     } catch (\Exception $e) {
         return false;
     }
     $granted = false;
     if ($subdef_class == databox_subdef::CLASS_THUMBNAIL) {
         $granted = true;
     } elseif ($subdef_class == databox_subdef::CLASS_PREVIEW && $this->has_right_on_base($record->getBaseId(), 'candwnldpreview')) {
         $granted = true;
     } elseif ($subdef_class == databox_subdef::CLASS_PREVIEW && $this->has_preview_grant($record)) {
         $granted = true;
     } elseif ($subdef_class == databox_subdef::CLASS_DOCUMENT && $this->has_right_on_base($record->getBaseId(), 'candwnldhd')) {
         $granted = true;
     } elseif ($subdef_class == databox_subdef::CLASS_DOCUMENT && $this->has_hd_grant($record)) {
         $granted = true;
     }
     if (false === $granted && $this->app['repo.feed-items']->isRecordInPublicFeed($record->getDataboxId(), $record->getRecordId())) {
         $granted = true;
     }
     return $granted;
 }
 public function getSubdefUrl(RecordInterface $record, $subdefName)
 {
     if ($record instanceof ElasticsearchRecord) {
         $subdefs = $record->getSubdefs();
         if (isset($subdefs[$subdefName])) {
             $thumbnail = $subdefs[$subdefName];
             if (null !== ($path = $thumbnail['path'])) {
                 if (is_string($path) && '' !== $path) {
                     return $this->app['phraseanet.static-file']->getUrl($path);
                 }
             }
         }
     } elseif ($record instanceof \record_adapter) {
         if (null !== ($thumbnail = $record->get_subdef($subdefName))) {
             if ('' !== ($path = $thumbnail->get_pathfile())) {
                 return $this->app['phraseanet.static-file']->getUrl($path);
             }
         }
     }
     $path = sprintf('/assets/common/images/icons/substitution/%s.png', str_replace('/', '_', $record->getMimeType()));
     return $path;
 }