public static function getDocument($documentId)
 {
     $documentId = (int) $documentId;
     if ($documentId <= 0) {
         throw new CBPArgumentNullException("documentId");
     }
     $file = File::loadById($documentId);
     if (!$file) {
         return null;
     }
     $ufFields = Driver::getInstance()->getUserFieldManager()->getFieldsForObject($file);
     $ufFileRow = array();
     if (!empty($ufFields)) {
         foreach ($ufFields as $fieldKey => $fieldData) {
             $ufFileRow[$fieldKey] = $fieldData['VALUE'];
             $ufFileRow[$fieldData['XML_ID']] = $fieldData['VALUE'];
         }
     }
     $fileRow = File::getList(array('with' => array('CREATE_USER', 'UPDATE_USER', 'DELETE_USER'), 'filter' => array('ID' => $documentId)))->fetch();
     if (!$fileRow) {
         return null;
     }
     if (empty($fileRow["CODE"])) {
         $fileRow["CODE"] = Loc::getMessage("DISK_BZ_D_NAME_NOT_CODE");
     }
     return array_merge(array("ID" => $fileRow["ID"], "CREATE_TIME" => $fileRow["CREATE_TIME"], "CREATED_BY" => $fileRow["CREATED_BY"], "CREATED_BY_PRINTABLE" => $fileRow['CREATE_USERREF_NAME'] . ' ' . $fileRow['CREATE_USERREF_LAST_NAME'], "UPDATE_TIME" => $fileRow["UPDATE_TIME"], "UPDATED_BY" => $fileRow["UPDATED_BY"], "UPDATED_BY_PRINTABLE" => $fileRow['UPDATE_USERREF_NAME'] . ' ' . $fileRow['UPDATE_USERREF_LAST_NAME'], "DELETE_TIME" => $fileRow["DELETE_TIME"], "DELETED_BY" => $fileRow["DELETED_BY"], "DELETED_BY_PRINTABLE" => $fileRow['DELETE_USERREF_NAME'] . ' ' . $fileRow['DELETE_USERREF_LAST_NAME'], "STORAGE_ID" => $fileRow["STORAGE_ID"], "NAME" => $fileRow["NAME"], "SIZE" => $fileRow["SIZE"], "CODE" => $fileRow["CODE"], "TIMESTAMP_X" => $fileRow["UPDATE_TIME"], "MODIFIED_BY" => $fileRow["CREATED_BY"], "MODIFIED_BY_PRINTABLE" => $fileRow['UPDATE_USERREF_NAME'] . ' ' . $fileRow['UPDATE_USERREF_LAST_NAME'], "DATE_CREATE" => $fileRow["CREATE_TIME"], "FILE_SIZE" => $fileRow["SIZE"]), $ufFileRow);
 }
Ejemplo n.º 2
0
 /**
  * @return File|null
  */
 public function getObject()
 {
     if (!$this->objectId) {
         return null;
     }
     if (isset($this->object) && $this->objectId == $this->object->getId()) {
         return $this->object;
     }
     $this->object = File::loadById($this->objectId);
     return $this->object;
 }
Ejemplo n.º 3
0
 /**
  * Returns true if current user has read access to the file.
  * @param array $params Allowed keys: fileId.
  * @param int $userId Current user's id.
  * @return bool
  */
 public static function checkUserReadAccess(array $params, $userId)
 {
     $result = false;
     $fileId = $params['fileId'];
     if ($file = \Bitrix\Disk\File::loadById($fileId)) {
         $securityContext = $file->getStorage()->getSecurityContext($userId);
         if ($file->canRead($securityContext)) {
             $result = true;
         }
     }
     return $result;
 }
Ejemplo n.º 4
0
 protected function processBeforeAction($actionName)
 {
     $this->file = File::loadById($this->fileId, array('STORAGE'));
     if (!$this->file) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOWNLOAD_CONTROLLER_ERROR_COULD_NOT_FIND_FILE'), self::ERROR_COULD_NOT_FIND_FILE)));
         $this->sendJsonErrorResponse();
     }
     if ($this->file instanceof FileLink && !$this->file->getRealObject()) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOWNLOAD_CONTROLLER_ERROR_COULD_NOT_FIND_FILE'), self::ERROR_COULD_NOT_FIND_REAL_FILE)));
         $this->sendJsonErrorResponse();
     }
     $this->checkPermissions();
     return true;
 }
Ejemplo n.º 5
0
 protected function processActionOpenFileDetail()
 {
     if (!$this->checkRequiredGetParams(array('fileId'))) {
         $this->sendJsonErrorResponse();
     }
     /** @var File $file */
     $file = File::loadById((int) $this->request->getQuery('fileId'), array('STORAGE'));
     if (!$file) {
         $this->errorCollection->addOne(new Error('Could not find file', self::ERROR_COULD_NOT_FIND_FILE));
         $this->sendJsonErrorResponse();
     }
     if (!$file->canRead($file->getStorage()->getCurrentUserSecurityContext())) {
         $this->errorCollection->addOne(new Error('Could not find file', self::ERROR_COULD_NOT_READ_FILE));
         $this->sendJsonErrorResponse();
     }
     $urlManager = Driver::getInstance()->getUrlManager();
     LocalRedirect($urlManager->encodeUrn($urlManager->getPathFileDetail($file)));
 }
Ejemplo n.º 6
0
 private function getFileAndExternalLink()
 {
     if (!$this->checkRequiredPostParams(array('externalId', 'objectId'))) {
         $this->sendJsonErrorResponse();
     }
     /** @var File $file */
     $file = File::loadById((int) $this->request->getPost('objectId'), array('STORAGE'));
     if (!$file) {
         $this->errorCollection->addOne(new Error(Loc::getMessage('DISK_BREADCRUMBS_ERROR_COULD_NOT_FIND_OBJECT'), self::ERROR_COULD_NOT_FIND_OBJECT));
         $this->sendJsonErrorResponse();
     }
     $securityContext = $file->getStorage()->getCurrentUserSecurityContext();
     if (!$file->canRead($securityContext)) {
         $this->sendJsonAccessDeniedResponse();
     }
     $extLinks = $file->getExternalLinks(array('filter' => array('ID' => (int) $this->request->getPost('externalId'), 'OBJECT_ID' => $file->getId(), 'CREATED_BY' => $this->getUser()->getId(), 'TYPE' => \Bitrix\Disk\Internals\ExternalLinkTable::TYPE_MANUAL, 'IS_EXPIRED' => false), 'limit' => 1));
     return array($file, array_pop($extLinks));
 }
Ejemplo n.º 7
0
 /**
  * Called before record transformed for log writing.
  *
  * @param array &$record Database record.
  *
  * @return void
  */
 public function beforeLogFormat(array &$record)
 {
     global $USER;
     if ($record["PARAM_NAME"] !== "FILE_ID" || $record["PARAM_VALUE"] <= 0) {
         return;
     }
     if (!\Bitrix\Main\Loader::includeModule('disk')) {
         AddMessage2Log('MessageParamHandler::beforeLogFormat: failed to load disk module.');
         return;
     }
     if (!is_object($USER) || $USER->GetID() < 0) {
         AddMessage2Log('MessageParamHandler::beforeLogFormat: no user provided.');
         return;
     }
     /** @var \Bitrix\Disk\File $file */
     $fileId = $record["PARAM_VALUE"];
     $userId = $USER->GetID();
     $file = \Bitrix\Disk\File::loadById($fileId);
     if (!$file) {
         AddMessage2Log('MessageParamHandler::beforeLogFormat: file (' . $fileId . ') not found for user (' . $userId . ').');
         return;
     }
     $externalLink = $file->addExternalLink(array('CREATED_BY' => $userId, 'TYPE' => \Bitrix\Disk\Internals\ExternalLinkTable::TYPE_MANUAL));
     if (!$externalLink) {
         AddMessage2Log('MessageParamHandler::beforeLogFormat: failed to get external link for file (' . $fileId . ').');
         AddMessage2Log($file->getErrors());
         return;
     }
     $url = \Bitrix\Disk\Driver::getInstance()->getUrlManager()->getUrlExternalLink(array('hash' => $externalLink->getHash(), 'action' => 'default'), true);
     $fileName = $file->getName();
     $fileSize = $file->getSize();
     $attach = new \CIMMessageParamAttach(null, \CIMMessageParamAttach::CHAT);
     $attach->AddFiles(array(array("NAME" => $fileName, "LINK" => $url, "SIZE" => $fileSize)));
     $record["PARAM_NAME"] = 'ATTACH';
     $record["PARAM_VALUE"] = 1;
     $record["PARAM_JSON"] = $attach->GetJSON();
 }
Ejemplo n.º 8
0
 protected function initializeFile($fileId)
 {
     $this->file = File::loadById($fileId, array('STORAGE'));
     if (!$this->file) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_FILE'), self::ERROR_COULD_NOT_FIND_FILE)));
         $this->sendJsonErrorResponse();
     }
 }
Ejemplo n.º 9
0
 /**
  * Event listener which return url for resource by fields.
  * @param array $fields Fields from search module.
  * @return string
  */
 public static function onSearchGetUrl($fields)
 {
     if (!is_array($fields)) {
         return '';
     }
     if ($fields["MODULE_ID"] !== "disk" || substr($fields["URL"], 0, 1) !== "=") {
         return $fields["URL"];
     }
     parse_str(ltrim($fields["URL"], "="), $data);
     if (empty($data['ID'])) {
         return '';
     }
     $file = File::loadById($data['ID']);
     if (!$file) {
         return '';
     }
     $pathFileDetail = Driver::getInstance()->getUrlManager()->getPathFileDetail($file);
     \CSearch::update($fields['ID'], array('URL' => $pathFileDetail));
     return $pathFileDetail;
 }
Ejemplo n.º 10
0
 private function loadFilesData()
 {
     if (empty($this->arParams['PARAMS']['arUserField'])) {
         return array();
     }
     $userId = $this->getUser()->getId();
     $values = $this->arParams['PARAMS']['arUserField']['VALUE'];
     if (!is_array($this->arParams['PARAMS']['arUserField']['VALUE'])) {
         $values = array($values);
     }
     $files = array();
     $driver = \Bitrix\Disk\Driver::getInstance();
     $urlManager = $driver->getUrlManager();
     $userFieldManager = $driver->getUserFieldManager();
     $userFieldManager->loadBatchAttachedObject($values);
     foreach ($values as $id) {
         $attachedModel = null;
         list($type, $realValue) = FileUserType::detectType($id);
         if ($realValue <= 0) {
             continue;
         } elseif ($type == FileUserType::TYPE_NEW_OBJECT) {
             /** @var File $fileModel */
             $fileModel = File::loadById($realValue);
             if (!$fileModel || !$fileModel->canRead($fileModel->getStorage()->getCurrentUserSecurityContext())) {
                 continue;
             }
         } else {
             /** @var \Bitrix\Disk\AttachedObject $attachedModel */
             $attachedModel = $userFieldManager->getAttachedObjectById($realValue);
             if (!$attachedModel) {
                 continue;
             }
             if (!$this->editMode) {
                 $attachedModel->setOperableEntity(array('ENTITY_ID' => $this->arParams['PARAMS']['arUserField']['ENTITY_ID'], 'ENTITY_VALUE_ID' => $this->arParams['PARAMS']['arUserField']['ENTITY_VALUE_ID']));
             }
             /** @var File $fileModel */
             $fileModel = $attachedModel->getFile();
         }
         $name = $fileModel->getName();
         $data = array('ID' => $id, 'NAME' => $name, 'CONVERT_EXTENSION' => DocumentHandler::isNeedConvertExtension($fileModel->getExtension()), 'EDITABLE' => DocumentHandler::isEditable($fileModel->getExtension()), 'CAN_UPDATE' => $attachedModel ? $attachedModel->canUpdate($userId) : $fileModel->canUpdate($fileModel->getStorage()->getCurrentUserSecurityContext()), 'FROM_EXTERNAL_SYSTEM' => $fileModel->getContentProvider() && $fileModel->getCreatedBy() == $userId, 'EXTENSION' => $fileModel->getExtension(), 'SIZE' => \CFile::formatSize($fileModel->getSize()), 'XML_ID' => $fileModel->getXmlId(), 'FILE_ID' => $fileModel->getId(), 'VIEW_URL' => $urlManager->getUrlToShowAttachedFileByService($id, 'gvdrive'), 'EDIT_URL' => $urlManager->getUrlToStartEditUfFileByService($id, 'gdrive'), 'DOWNLOAD_URL' => $urlManager->getUrlUfController('download', array('attachedId' => $id)), 'COPY_TO_ME_URL' => $urlManager->getUrlUfController('copyToMe', array('attachedId' => $id)), 'DELETE_URL' => "");
         if (\Bitrix\Disk\TypeFile::isImage($fileModel)) {
             $this->arParams['PARAMS']['THUMB_SIZE'] = $this->arParams['PARAMS']['THUMB_SIZE'] > 0 ? $this->arParams['PARAMS']['THUMB_SIZE'] : 100;
             $data["PREVIEW_URL"] = $attachedModel === null ? $urlManager->getUrlForShowFile($fileModel) : $urlManager->getUrlUfController('show', array('attachedId' => $id));
             $data["IMAGE"] = $fileModel->getFile();
         }
         if ($this->editMode) {
             $data['STORAGE'] = $fileModel->getStorage()->getProxyType()->getTitleForCurrentUser() . ' / ' . $fileModel->getParent()->getName();
         } else {
             $data['ATTRIBUTES_FOR_VIEWER'] = Ui\Viewer::getAttributesByAttachedObject($attachedModel, array('canUpdate' => $data['CAN_UPDATE'], 'canFakeUpdate' => true, 'showStorage' => false, 'externalId' => false, 'relativePath' => false));
         }
         $files[] = $data;
     }
     unset($id);
     return $files;
 }
Ejemplo n.º 11
0
 protected function processActionUpdateFile($hash, &$fileData, &$package, &$upload, &$error)
 {
     $this->checkRequiredInputParams($_POST, array('targetFileId'));
     $file = false;
     if (!$this->errorCollection->hasErrors()) {
         /** @var File $file */
         $file = File::loadById((int) $_POST['targetFileId'], array('STORAGE'));
         if ($file && isset($_POST['checkBp'])) {
             $workflowParameters = array();
             $search = 'bizproc';
             foreach ($_POST as $idParameter => $valueParameter) {
                 $res = strpos($idParameter, $search);
                 if ($res === 0) {
                     $workflowParameters[$idParameter] = $valueParameter;
                 }
             }
             $autoExecute = intval($_POST['autoExecute']);
             \Bitrix\Disk\BizProcDocument::startAutoBizProc($file->getStorageId(), $file->getId(), $autoExecute, $workflowParameters);
         }
         if (!$file) {
             $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_FILE_UPLOAD_ERROR_COULD_NOT_FIND_FILE'), self::ERROR_COULD_NOT_FIND_FILE)));
         } else {
             if (!$file->canUpdate($file->getStorage()->getCurrentUserSecurityContext())) {
                 $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_FILE_UPLOAD_ERROR_BAD_RIGHTS2'), self::ERROR_BAD_RIGHTS)));
             } else {
                 if (!$file->uploadVersion($fileData["files"]["default"], $this->getUser()->getId())) {
                     $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_FILE_UPLOAD_ERROR_COULD_UPLOAD_VERSION'), self::ERROR_COULD_UPLOAD_VERSION)));
                 }
             }
         }
     }
     $error = implode(" ", (is_object($file) ? $file->getErrors() : array()) + $this->errorCollection->toArray());
     return empty($error);
 }
Ejemplo n.º 12
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);
 }
Ejemplo n.º 13
0
 /**
  * @param $id
  * @return File|null
  */
 protected static function getFileById($id)
 {
     if (!isset(self::$loadedFiles[$id])) {
         self::$loadedFiles[$id] = File::loadById($id, array('STORAGE'));
     }
     return self::$loadedFiles[$id];
 }
Ejemplo n.º 14
0
use Bitrix\Disk\File;
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
    die;
}
if (intval($USER->GetID()) <= 0) {
    return;
}
if (!CModule::IncludeModule('disk')) {
    return;
}
if (empty($_REQUEST['objectId'])) {
    return;
}
/** @var File $file */
$file = File::loadById((int) $_REQUEST['objectId'], array('STORAGE'));
if (!$file) {
    return;
}
$securityContext = $file->getStorage()->getCurrentUserSecurityContext();
if (!$file->canRead($securityContext)) {
    return;
}
if (!empty($_GET['download'])) {
    $fileData = $file->getFile();
    \CFile::viewByUser($fileData, array("force_download" => false, 'attachment_name' => $file->getName()));
}
if (CFile::isImage($file->getName())) {
    $icon = 'img.png';
} else {
    $icons = array('pdf' => 'pdf.png', 'doc' => 'doc.png', 'docx' => 'doc.png', 'ppt' => 'ppt.png', 'pptx' => 'ppt.png', 'rar' => 'rar.png', 'xls' => 'xls.png', 'xlsx' => 'xls.png', 'zip' => 'zip.png');
Ejemplo n.º 15
0
 public static function writeFileToResponse($fileID)
 {
     if (!Loader::includeModule('disk')) {
         return;
     }
     $file = File::loadById($fileID);
     if (!$file) {
         return;
     }
     $fileData = $file->getFile();
     if (!$fileData) {
         return;
     }
     \CFile::viewByUser($fileData, array('force_download' => true, 'cache_time' => 0, 'attachment_name' => $file->getName()));
 }
Ejemplo n.º 16
0
 protected function findFile()
 {
     $this->file = \Bitrix\Disk\File::loadById($this->arParams['FILE_ID'], array('REAL_OBJECT', 'CREATE_USER'));
     if (!$this->file) {
         throw new \Bitrix\Main\SystemException("Invalid file.");
     }
     return $this;
 }
Ejemplo n.º 17
0
 /**
  * @param $iblockId
  * @param string $fileId disk file with the prefix 'n'
  * @return int|null
  */
 public static function attachFilesWorkflow($iblockId, $fileId)
 {
     if (!(int) $iblockId) {
         return null;
     }
     $userFieldManager = Driver::getInstance()->getUserFieldManager();
     list($connectorClass, $moduleId) = $userFieldManager->getConnectorDataByEntityType("iblock_workflow");
     list($type, $realId) = FileUserType::detectType($fileId);
     if ($type != FileUserType::TYPE_NEW_OBJECT) {
         return null;
     }
     $errorCollection = new ErrorCollection();
     $fileModel = File::loadById($realId, array('STORAGE'));
     if (!$fileModel) {
         return null;
     }
     $attachedModel = AttachedObject::load(array('OBJECT_ID' => $fileModel->getId(), '=ENTITY_TYPE' => $connectorClass, '=ENTITY_ID' => $iblockId, '=MODULE_ID' => $moduleId));
     if ($attachedModel) {
         return $fileModel->getId();
     }
     global $USER;
     if ($USER instanceof \CUser && $USER->getId()) {
         $userId = $USER->getId();
     } else {
         $userId = SystemUser::SYSTEM_USER_ID;
     }
     $securityContext = $fileModel->getStorage()->getSecurityContext($userId);
     if (!$fileModel->canRead($securityContext)) {
         return null;
     }
     $canUpdate = $fileModel->canUpdate($securityContext);
     $attachedModel = AttachedObject::add(array('MODULE_ID' => $moduleId, 'OBJECT_ID' => $fileModel->getId(), 'ENTITY_ID' => $iblockId, 'ENTITY_TYPE' => $connectorClass, 'IS_EDITABLE' => (int) $canUpdate, 'ALLOW_EDIT' => (int) ($canUpdate && (int) Application::getInstance()->getContext()->getRequest()->getPost('DISK_FILE_' . $iblockId . '_DISK_ATTACHED_OBJECT_ALLOW_EDIT')), 'CREATED_BY' => $userId), $errorCollection);
     if (!$attachedModel || $errorCollection->hasErrors()) {
         return null;
     }
     return $fileModel->getId();
 }
Ejemplo n.º 18
0
 /**
  * Returns file model.
  * @return null|Object|File
  */
 public function getFile()
 {
     if (!$this->objectId) {
         return null;
     }
     if (isset($this->file) && $this->objectId == $this->file->getId()) {
         return $this->file;
     }
     //todo Here we can load anything (Folder or File). But now - only File model
     $this->file = File::loadById($this->objectId);
     return $this->file;
 }
Ejemplo n.º 19
0
 public function processActionStopBizProc()
 {
     $this->checkRequiredPostParams(array('fileId', 'idBizProc'));
     if (!Loader::includeModule("bizproc")) {
         $this->errorCollection->addOne(new Error(Loc::getMessage('DISK_FILE_VIEW_BIZPROC_LOAD')));
     }
     if ($this->errorCollection->hasErrors()) {
         $this->sendJsonErrorResponse();
     }
     $fileId = (int) $this->request->getPost('fileId');
     /** @var File $file */
     $file = File::loadById($fileId);
     if (!$file) {
         $this->errorCollection->addOne(new Error(Loc::getMessage('DISK_FILE_VIEW_ERROR_COULD_NOT_FIND_OBJECT'), self::ERROR_COULD_NOT_FIND_OBJECT));
         $this->sendJsonErrorResponse();
     }
     $documentData = array('DISK' => array('DOCUMENT_ID' => \Bitrix\Disk\BizProcDocument::getDocumentComplexId($fileId)), 'WEBDAV' => array('DOCUMENT_ID' => \Bitrix\Disk\BizProcDocumentCompatible::getDocumentComplexId($fileId)));
     $webdavFileId = $file->getXmlId();
     if (!empty($webdavFileId)) {
         $documentData['OLD_FILE_COMMON'] = array('DOCUMENT_ID' => array('webdav', 'CIBlockDocumentWebdav', $webdavFileId));
         $documentData['OLD_FILE_GROUP'] = array('DOCUMENT_ID' => array('webdav', 'CIBlockDocumentWebdavSocnet', $webdavFileId));
     }
     $workflowId = $this->request->getPost('idBizProc');
     $error = array();
     foreach ($documentData as $nameModule => $data) {
         $availabilityProcess = CBPDocument::GetDocumentState($data['DOCUMENT_ID'], $workflowId);
         if (!empty($availabilityProcess)) {
             if (CBPDocument::CanUserOperateDocument(CBPCanUserOperateOperation::StartWorkflow, $this->getUser()->getId(), $data['DOCUMENT_ID'])) {
                 CBPDocument::TerminateWorkflow($workflowId, $data['DOCUMENT_ID'], $error);
             }
         }
     }
     if ($error) {
         $this->errorCollection->addOne(new Error(array_shift($error)));
         $this->sendJsonErrorResponse();
     }
     $this->sendJsonSuccessResponse();
 }
Ejemplo n.º 20
0
 public static function makeFileArray($fileID)
 {
     if (!Loader::includeModule('disk')) {
         return null;
     }
     /** @var File $file */
     $file = File::loadById($fileID);
     if (!$file) {
         return null;
     }
     $originalFileID = $file->getFileId();
     if ($originalFileID <= 0) {
         return null;
     }
     $fileData = \CFile::MakeFileArray($originalFileID);
     $fileData['ORIGINAL_NAME'] = $file->getName();
     return $fileData;
 }
Ejemplo n.º 21
0
 public static function getUsersFromUserGroup($group, $documentId)
 {
     if (substr($documentId, 0, 8) == "STORAGE_") {
         $storageId = self::getStorageIdByType($documentId);
     } else {
         if (is_array($documentId)) {
             $documentId = intval($documentId[2]);
         }
         /** @var File $file */
         $file = File::loadById($documentId);
         if (!$file) {
             return array();
         }
         $storageId = $file->getStorageId();
     }
     if (strtolower($group) == "author") {
         $documentId = intval($documentId);
         if ($documentId <= 0) {
             return array();
         }
         /** @var File $file */
         $file = File::loadById($documentId);
         if (!$file) {
             return array();
         }
         return array($file->getCreatedBy());
     }
     if ($storageId) {
         $storage = Storage::loadById($storageId, array('ROOT_OBJECT'));
         if ($storage->getProxyType() instanceof ProxyType\Group) {
             $entityId = $storage->getEntityId();
             $group = strtoupper($group);
             if (Loader::includeModule("socialnetwork")) {
                 $listUserGroup = array();
                 if ($group == SONET_ROLES_OWNER) {
                     $listGroup = \CSocNetGroup::getByID($entityId);
                     if ($listGroup) {
                         $listUserGroup[] = $listGroup["OWNER_ID"];
                     }
                 } elseif ($group == SONET_ROLES_MODERATOR) {
                     $dbRes = \CSocNetUserToGroup::getList(array(), array("GROUP_ID" => $entityId, "<=ROLE" => SONET_ROLES_MODERATOR, "USER_ACTIVE" => "Y"), false, false, array("USER_ID"));
                     while ($res = $dbRes->fetch()) {
                         $listUserGroup[] = $res["USER_ID"];
                     }
                 } elseif ($group == SONET_ROLES_USER) {
                     $dbRes = \CSocNetUserToGroup::getList(array(), array("GROUP_ID" => $entityId, "<=ROLE" => SONET_ROLES_USER, "USER_ACTIVE" => "Y"), false, false, array("USER_ID"));
                     while ($res = $dbRes->fetch()) {
                         $listUserGroup[] = $res["USER_ID"];
                     }
                 }
                 return $listUserGroup;
             }
         }
     }
     $group = intval($group);
     if ($group <= 0) {
         return array();
     }
     $userIds = array();
     $filter = array("ACTIVE" => "Y");
     if ($group != 2) {
         $filter["GROUPS_ID"] = $group;
     }
     $query = \CUser::getList($b = "ID", $o = "ASC", $filter);
     while ($user = $query->fetch()) {
         $userIds[] = $user["ID"];
     }
     return $userIds;
 }
Ejemplo n.º 22
0
 protected function processActionRenameFile()
 {
     $this->checkRequiredPostParams(array('newName', 'attachedId'));
     if ($this->errorCollection->hasErrors()) {
         $this->sendJsonErrorResponse();
     }
     list($type, $realValue) = FileUserType::detectType($this->request->getPost('attachedId'));
     if ($type == FileUserType::TYPE_NEW_OBJECT) {
         /** @var File $model */
         $model = File::loadById((int) $realValue, array('STORAGE'));
         if (!$model) {
             $this->errorCollection->add(array(new Error("Could not find file")));
             $this->sendJsonErrorResponse();
         }
         if (!$model->canRename($model->getStorage()->getCurrentUserSecurityContext())) {
             $this->errorCollection->add(array(new Error("Bad permission. Could not read this file")));
             $this->sendJsonErrorResponse();
         }
         $newName = Text::correctFilename($this->request->getPost('newName'));
         if (!$model->renameInternal($newName, true)) {
             $this->errorCollection->add($model->getErrors());
             $this->sendJsonErrorResponse();
         }
         Driver::getInstance()->getIndexManager()->indexFile($model);
         $this->sendJsonSuccessResponse(array('id' => $this->request->getPost('attachedId'), 'name' => $model->getName()));
     } else {
         $this->sendJsonErrorResponse();
     }
 }
Ejemplo n.º 23
0
 public static function extractValue(FieldType $fieldType, array $field, array $request)
 {
     if (!Loader::includeModule('disk')) {
         return null;
     }
     $value = parent::extractValue($fieldType, $field, $request);
     if (is_array($value) && isset($value['VALUE'])) {
         $value = $value['VALUE'];
     }
     if (!$value) {
         return null;
     }
     // Attach file disk
     $userFieldManager = \Bitrix\Disk\Driver::getInstance()->getUserFieldManager();
     list($connectorClass, $moduleId) = $userFieldManager->getConnectorDataByEntityType('lists_workflow');
     list($type, $realId) = \Bitrix\Disk\Uf\FileUserType::detectType($value);
     if ($type != \Bitrix\Disk\Uf\FileUserType::TYPE_NEW_OBJECT) {
         return null;
     }
     $errorCollection = new \Bitrix\Disk\Internals\Error\ErrorCollection();
     $fileModel = \Bitrix\Disk\File::loadById($realId, array('STORAGE'));
     if (!$fileModel) {
         return null;
     }
     $documentType = $fieldType->getDocumentType();
     $iblockId = intval(substr($documentType[2], strlen("iblock_")));
     $attachedModel = \Bitrix\Disk\AttachedObject::load(array('OBJECT_ID' => $fileModel->getId(), '=ENTITY_TYPE' => $connectorClass, '=ENTITY_ID' => $iblockId, '=MODULE_ID' => $moduleId));
     if ($attachedModel) {
         return $fileModel->getId();
     }
     $securityContext = $fileModel->getStorage()->getCurrentUserSecurityContext();
     if (!$fileModel->canRead($securityContext)) {
         return null;
     }
     $canUpdate = $fileModel->canUpdate($securityContext);
     global $USER;
     $attachedModel = \Bitrix\Disk\AttachedObject::add(array('MODULE_ID' => $moduleId, 'OBJECT_ID' => $fileModel->getId(), 'ENTITY_ID' => $iblockId, 'ENTITY_TYPE' => $connectorClass, 'IS_EDITABLE' => (int) $canUpdate, 'ALLOW_EDIT' => (int) ($canUpdate && (int) \Bitrix\Main\Application::getInstance()->getContext()->getRequest()->getPost('DISK_FILE_' . $iblockId . '_DISK_ATTACHED_OBJECT_ALLOW_EDIT')), 'CREATED_BY' => $USER->getId()), $errorCollection);
     if (!$attachedModel || $errorCollection->hasErrors()) {
         return null;
     }
     return $fileModel->getId();
 }