Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
diskhelper.php
1
<?php
2
3
namespace
Bitrix\SocialServices\Integration\Zoom
;
4
5
use Bitrix\Disk\Storage;
6
use
Bitrix\Main\Error
;
7
use
Bitrix\Main\Loader
;
8
use
Bitrix\Main\Localization\Loc
;
9
use
Bitrix\Main\Result
;
10
use
Bitrix\Main\Type\DateTime
;
11
12
class
DiskHelper
13
{
14
const
ROOT_FOLDER_CODE
=
"ZOOM_RECORDS"
;
15
16
public
static
function
saveFile
(array $arFile,
int
$userId, $siteId = SITE_ID):
Result
17
{
18
$result =
new
Result
();
19
if
(!Loader::includeModule(
"disk"
))
20
{
21
return
$result->addError(
new
Error
(
"Disk module is not installed"
));
22
}
23
24
$subFolder =
self::getRecordsFolder
((
new
DateTime
())->format(
"Y-m"
), $siteId);
25
if
(!$subFolder)
26
{
27
return
$result->addError(
new
Error
(
"Could not create records folder"
));
28
}
29
30
$accessCodes = [];
31
$rightsManager = \Bitrix\Disk\Driver::getInstance()->getRightsManager();
32
$fullAccessTaskId = $rightsManager->getTaskIdByName($rightsManager::TASK_FULL);
33
34
$accessCodes[] = [
35
'ACCESS_CODE'
=>
'U'
. $userId,
36
'TASK_ID'
=> $fullAccessTaskId,
37
];
38
$accessCodes[] = [
39
'ACCESS_CODE'
=>
'G1'
,
40
'TASK_ID'
=> $fullAccessTaskId,
41
];
42
43
$fileModel = $subFolder->uploadFile(
44
$arFile,
45
[
'CREATED_BY'
=> $userId,],
46
$accessCodes,
47
true
48
);
49
50
if
(!$fileModel)
51
{
52
if
(count($subFolder->getErrors()) > 0)
53
{
54
return
$result->addErrors($subFolder->getErrors());
55
}
56
return
$result->addError(
new
Error
(
"Unknown error while saving file"
));
57
}
58
return
$result->setData([
59
'fileId'
=> $fileModel->getId()
60
]);
61
}
62
63
public
static
function
getRecordsFolder
($folderName, $siteId = SITE_ID)
64
{
65
if
(!\
Bitrix
\Main\Loader::includeModule(
'disk'
))
66
return
false
;
67
68
$rootFolder =
self::getRootFolder
($siteId);
69
if
(!$rootFolder)
70
{
71
return
false
;
72
}
73
74
$subFolder = \Bitrix\Disk\Folder::load(array(
75
'=NAME'
=> $folderName,
76
'PARENT_ID'
=> $rootFolder->getId(),
77
));
78
79
if
(!$subFolder)
80
{
81
$subFolder = $rootFolder->addSubFolder(array(
82
'NAME'
=> $folderName,
83
'CREATED_BY'
=> \
Bitrix
\Disk\SystemUser::SYSTEM_USER_ID
84
));
85
}
86
87
return
$subFolder;
88
}
89
90
public
static
function
getRootFolder
($siteId = SITE_ID)
91
{
92
$storageModel =
self::getStorageModel
($siteId);
93
if
(!$storageModel)
94
{
95
return
false
;
96
}
97
98
$folderModel = \Bitrix\Disk\Folder::load(array(
99
'STORAGE_ID'
=> $storageModel->getId(),
100
'PARENT_ID'
=> $storageModel->getRootObjectId(),
101
'TYPE'
=> \
Bitrix
\Disk\Internals\ObjectTable::TYPE_FOLDER,
102
'=CODE'
=> static::ROOT_FOLDER_CODE,
103
));
104
if
($folderModel)
105
{
106
return
$folderModel;
107
}
108
109
// Creating root folder
110
$folderModel = $storageModel->addFolder([
111
'NAME'
=> static::getRootFolderName($siteId),
112
'CODE'
=> static::ROOT_FOLDER_CODE,
113
'CREATED_BY'
=> \
Bitrix
\Disk\SystemUser::SYSTEM_USER_ID
114
], static::createRootFolderAccessCodes($storageModel));
115
116
return
$folderModel;
117
}
118
123
public
static
function
getStorageModel
($siteId = SITE_ID): ?Storage
124
{
125
if
($siteId ===
''
)
126
return
null
;
127
128
$storageModel = \Bitrix\Disk\Driver::getInstance()->getStorageByCommonId(
"shared_files_{$siteId}"
);
129
return
$storageModel ?:
null
;
130
}
131
132
public
static
function
getRootFolderName
($siteId): string
133
{
134
// Folder name
135
$dbSite = \CSite::GetByID($siteId);
136
$arSite = $dbSite->Fetch();
137
IncludeModuleLangFile(__FILE__, $arSite && isset($arSite[
'LANGUAGE_ID'
]) ? $arSite[
'LANGUAGE_ID'
] :
false
);
138
139
return
Loc::getMessage
(
"SOCSERV_ZOOM_RECORDS_ROOT_FOLDER"
);
140
}
141
142
public
static
function
createRootFolderAccessCodes
(Storage $storageModel)
143
{
144
// Access codes
145
$rightsManager = \Bitrix\Disk\Driver::getInstance()->getRightsManager();
146
$fullAccessTaskId = $rightsManager->getTaskIdByName($rightsManager::TASK_FULL);
147
$rights = $rightsManager->getAllListNormalizeRights($storageModel->getRootObject());
148
149
$accessCodes = array();
150
foreach
($rights as $right)
151
{
152
$accessCodes[] = Array(
153
'ACCESS_CODE'
=> $right[
'ACCESS_CODE'
],
154
'TASK_ID'
=> $right[
'TASK_ID'
],
155
'NEGATIVE'
=> 1
156
);
157
}
158
$accessCodes[] = Array(
159
'ACCESS_CODE'
=>
'G1'
,
160
'TASK_ID'
=> $fullAccessTaskId,
161
);
162
163
return
$accessCodes;
164
}
165
}
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\Loader
Definition
loader.php:12
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\ORM\Data\Result
Definition
result.php:16
Bitrix\Main\Result
Definition
result.php:14
Bitrix\Main\Type\DateTime
Definition
datetime.php:9
Bitrix\SocialServices\Integration\Zoom\DiskHelper
Definition
diskhelper.php:13
Bitrix\SocialServices\Integration\Zoom\DiskHelper\getStorageModel
static getStorageModel($siteId=SITE_ID)
Definition
diskhelper.php:123
Bitrix\SocialServices\Integration\Zoom\DiskHelper\getRootFolderName
static getRootFolderName($siteId)
Definition
diskhelper.php:132
Bitrix\SocialServices\Integration\Zoom\DiskHelper\getRootFolder
static getRootFolder($siteId=SITE_ID)
Definition
diskhelper.php:90
Bitrix\SocialServices\Integration\Zoom\DiskHelper\saveFile
static saveFile(array $arFile, int $userId, $siteId=SITE_ID)
Definition
diskhelper.php:16
Bitrix\SocialServices\Integration\Zoom\DiskHelper\ROOT_FOLDER_CODE
const ROOT_FOLDER_CODE
Definition
diskhelper.php:14
Bitrix\SocialServices\Integration\Zoom\DiskHelper\getRecordsFolder
static getRecordsFolder($folderName, $siteId=SITE_ID)
Definition
diskhelper.php:63
Bitrix\SocialServices\Integration\Zoom\DiskHelper\createRootFolderAccessCodes
static createRootFolderAccessCodes(Storage $storageModel)
Definition
diskhelper.php:142
Bitrix\SocialServices\Integration\Zoom
Definition
conference.php:4
Bitrix
modules
socialservices
lib
integration
zoom
diskhelper.php
Создано системой
1.10.0