/** * @param FileData $fileData * @return null|EditSession * @throws \Bitrix\Main\NotImplementedException */ protected function addFileEditSessionByCurrentUser(FileData $fileData) { $data = array('OBJECT_ID' => $this->file->getId(), 'USER_ID' => $this->getUser()->getId(), 'OWNER_ID' => $this->getUser()->getId(), 'SERVICE' => $this->documentHandler->getCode(), 'SERVICE_FILE_ID' => $fileData->getId(), 'SERVICE_FILE_LINK' => $fileData->getLinkInService()); if ($this->isSpecificVersion()) { $data['VERSION_ID'] = $this->version->getId(); $data['IS_EXCLUSIVE'] = 1; } return EditSession::add($data, $this->errorCollection); }
/** * Returns version model. * @see isSpecificVersion() * @return Version|null */ public function getVersion() { if (!$this->versionId) { return null; } if (isset($this->version) && $this->versionId == $this->version->getId()) { return $this->version; } $this->version = Version::loadById($this->versionId); return $this->version; }
public function linkVersion(Version $version) { $update = $this->update(array('OBJECT_ID' => $version->getObjectId(), 'VERSION_ID' => $version->getId())); if ($update) { $this->setAttributes(array('VERSION' => $version, 'OBJECT' => $version->getObject())); } return $update; }
/** * Gets data attributes by version to viewer. * @param Version $version Target version. * @param array $additionalParams Additional parameters 'canUpdate', 'showStorage'. * @return string */ public static function getAttributesByVersion(Version $version, array $additionalParams = array()) { $object = $version->getObject(); $objectId = $object->getId(); $urlManager = Driver::getInstance()->getUrlManager(); if (DocumentHandler::isEditable($version->getExtension())) { $dataAttributesForViewer = 'data-bx-viewer="iframe" ' . 'data-bx-title="' . htmlspecialcharsbx($version->getName()) . '" ' . 'data-bx-src="' . $urlManager->getUrlToShowVersionByService($objectId, $version->getId(), 'gvdrive') . '" ' . 'data-bx-isFromUserLib="" ' . 'data-bx-askConvert="' . (DocumentHandler::isNeedConvertExtension($version->getExtension()) ? '1' : '') . '" ' . 'data-bx-download="' . $urlManager->getUrlForDownloadVersion($version) . '" ' . 'data-bx-size="' . htmlspecialcharsbx(CFile::formatSize($version->getSize())) . '" '; } elseif (Viewer::isViewable($object->getExtension())) { $dataAttributesForViewer = 'data-bx-viewer="iframe" ' . 'data-bx-title="' . htmlspecialcharsbx($version->getName()) . '" ' . 'data-bx-src="' . $urlManager->getUrlToShowVersionByService($objectId, $version->getId(), 'gvdrive') . '" ' . 'data-bx-isFromUserLib="" ' . 'data-bx-askConvert="0" ' . 'data-bx-download="' . $urlManager->getUrlForDownloadVersion($version) . '" ' . 'data-bx-size="' . htmlspecialcharsbx(CFile::formatSize($version->getSize())) . '" ' . 'data-bx-dateModify="' . htmlspecialcharsbx($version->getCreateTime()) . '" '; } elseif (TypeFile::isImage($object)) { $dataAttributesForViewer = 'data-bx-viewer="image" ' . 'data-bx-title="' . htmlspecialcharsbx($object->getName()) . '" ' . 'data-bx-src="' . $urlManager->getUrlForDownloadVersion($version) . '" ' . 'data-bx-isFromUserLib="" ' . 'data-bx-download="' . $urlManager->getUrlForDownloadVersion($version) . '" '; } else { $dataAttributesForViewer = 'data-bx-viewer="unknown" ' . 'data-bx-src="' . $urlManager->getUrlForDownloadVersion($version) . '" ' . 'data-bx-isFromUserLib="" ' . 'data-bx-download="' . $urlManager->getUrlForDownloadVersion($version) . '" ' . 'data-bx-title="' . htmlspecialcharsbx($object->getName()) . '" ' . 'data-bx-owner="' . htmlspecialcharsbx($version->getCreateUser() ? $version->getCreateUser()->getFormattedName() : '') . '" ' . 'data-bx-dateModify="' . htmlspecialcharsbx($version->getCreateTime()) . '" ' . 'data-bx-size="' . htmlspecialcharsbx(CFile::formatSize($version->getSize())) . '" '; } $dataAttributesForViewer .= " data-bx-version=\"\"" . " data-bx-history=\"\"" . " data-bx-historyPage=\"\""; if (!empty($additionalParams['canUpdate'])) { $dataAttributesForViewer .= ' data-bx-edit="' . $urlManager->getUrlForStartEditVersion($objectId, $version->getId(), 'gdrive') . '" '; } if (!empty($additionalParams['showStorage'])) { $dataAttributesForViewer .= ' data-bx-storage="' . htmlspecialcharsbx($object->getParent()->getName()) . '" '; } return $dataAttributesForViewer; }
/** * Gets url to download version of file. * @param Version $version Version of file. * @return string */ public function getUrlForDownloadVersion(Version $version) { return $this->getUrlDownloadController('downloadVersion', array('fileId' => $version->getObjectId(), 'versionId' => $version->getId())); }