示例#1
0
 public function getPublicLink(array $file)
 {
     /** @var File $file */
     $file = File::loadById($file['extra']['id']);
     if (!$file) {
         $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . " by id {$file['extra']['id']}", 111606)));
         return '';
     }
     if (!$file->canRead($this->storage->getCurrentUserSecurityContext())) {
         throw new CWebDavAccessDeniedException();
     }
     $extLinks = $file->getExternalLinks(array('filter' => array('OBJECT_ID' => $file->getId(), 'CREATED_BY' => $this->getUser()->getId(), 'TYPE' => \Bitrix\Disk\Internals\ExternalLinkTable::TYPE_MANUAL, 'IS_EXPIRED' => false), 'limit' => 1));
     $extModel = array_pop($extLinks);
     if (!$extModel) {
         $extModel = $file->addExternalLink(array('CREATED_BY' => $this->getUser()->getId(), 'TYPE' => ExternalLinkTable::TYPE_MANUAL));
     }
     if (!$extModel) {
         $this->errorCollection->add(array(new Error("Could not " . __METHOD__ . ", addExternalLink", 121606)));
         $this->errorCollection->add($file->getErrors());
         return '';
     }
     return \Bitrix\Disk\Driver::getInstance()->getUrlManager()->getShortUrlExternalLink(array('hash' => $extModel->getHash(), 'action' => 'default'), true);
 }