chamilo /
chamilo-lms
| 1 | <?php |
||||
| 2 | /** |
||||
| 3 | * (c) Copyright Ascensio System SIA 2025. |
||||
| 4 | * |
||||
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||||
| 6 | * you may not use this file except in compliance with the License. |
||||
| 7 | * You may obtain a copy of the License at |
||||
| 8 | * |
||||
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
||||
| 10 | * |
||||
| 11 | * Unless required by applicable law or agreed to in writing, software |
||||
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
||||
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
| 14 | * See the License for the specific language governing permissions and |
||||
| 15 | * limitations under the License. |
||||
| 16 | */ |
||||
| 17 | use Onlyoffice\DocsIntegrationSdk\Models\Customization; |
||||
| 18 | use Onlyoffice\DocsIntegrationSdk\Models\EditorsMode; |
||||
| 19 | use Onlyoffice\DocsIntegrationSdk\Models\GoBack; |
||||
| 20 | use Onlyoffice\DocsIntegrationSdk\Models\Permissions; |
||||
| 21 | use Onlyoffice\DocsIntegrationSdk\Models\User; |
||||
| 22 | use Onlyoffice\DocsIntegrationSdk\Service\DocEditorConfig\DocEditorConfigService; |
||||
| 23 | |||||
| 24 | class OnlyofficeConfigService extends DocEditorConfigService |
||||
| 25 | { |
||||
| 26 | public function __construct($settingsManager, $jwtManager, $documentManager) |
||||
| 27 | { |
||||
| 28 | parent::__construct($settingsManager, $jwtManager, $documentManager); |
||||
| 29 | } |
||||
| 30 | |||||
| 31 | public function getEditorsMode() |
||||
| 32 | { |
||||
| 33 | if ($this->isEditable() && $this->getAccessRights() && !$this->isReadOnly()) { |
||||
| 34 | $editorsMode = new EditorsMode('edit'); |
||||
| 35 | } else { |
||||
| 36 | if ($this->canView()) { |
||||
| 37 | $editorsMode = new EditorsMode('view'); |
||||
| 38 | } else { |
||||
| 39 | api_not_allowed(true); |
||||
| 40 | } |
||||
| 41 | } |
||||
| 42 | |||||
| 43 | return $editorsMode; |
||||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||||
| 44 | } |
||||
| 45 | |||||
| 46 | public function isEditable() |
||||
| 47 | { |
||||
| 48 | return $this->documentManager->isDocumentEditable($this->documentManager->getDocInfo('title')); |
||||
|
0 ignored issues
–
show
The method
getDocInfo() does not exist on Onlyoffice\DocsIntegrati...ocument\DocumentManager. Since it exists in all sub-types, consider adding an abstract or default implementation to Onlyoffice\DocsIntegrati...ocument\DocumentManager.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 49 | } |
||||
| 50 | |||||
| 51 | public function canView() |
||||
| 52 | { |
||||
| 53 | return $this->documentManager->isDocumentViewable($this->documentManager->getDocInfo('title')); |
||||
| 54 | } |
||||
| 55 | |||||
| 56 | public function getAccessRights() |
||||
| 57 | { |
||||
| 58 | $isAllowToEdit = api_is_allowed_to_edit(true, true); |
||||
| 59 | $isMyDir = DocumentManager::is_my_shared_folder( |
||||
| 60 | api_get_user_id(), |
||||
| 61 | $this->documentManager->getDocInfo('absolute_parent_path'), |
||||
| 62 | api_get_session_id() |
||||
| 63 | ); |
||||
| 64 | $isGroupAccess = false; |
||||
| 65 | if (!empty($this->documentManager->getGroupId())) { |
||||
|
0 ignored issues
–
show
The method
getGroupId() does not exist on Onlyoffice\DocsIntegrati...ocument\DocumentManager. Since it exists in all sub-types, consider adding an abstract or default implementation to Onlyoffice\DocsIntegrati...ocument\DocumentManager.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 66 | $groupProperties = GroupManager::get_group_properties($this->documentManager->getGroupId()); |
||||
| 67 | $docInfoGroup = api_get_item_property_info( |
||||
| 68 | api_get_course_int_id(), |
||||
| 69 | 'document', |
||||
| 70 | $docId, |
||||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
| 71 | $sessionId |
||||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
| 72 | ); |
||||
| 73 | $isGroupAccess = GroupManager::allowUploadEditDocument( |
||||
| 74 | $userId, |
||||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
| 75 | $courseCode, |
||||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
| 76 | $groupProperties, |
||||
| 77 | $docInfoGroup |
||||
| 78 | ); |
||||
| 79 | $isMemberGroup = GroupManager::is_user_in_group($userId, $groupProperties); |
||||
| 80 | if (!$isGroupAccess) { |
||||
| 81 | if (!$groupProperties['status']) { |
||||
| 82 | api_not_allowed(true); |
||||
| 83 | } |
||||
| 84 | if (!$isMemberGroup && 1 != $groupProperties['doc_state']) { |
||||
| 85 | api_not_allowed(true); |
||||
| 86 | } |
||||
| 87 | } |
||||
| 88 | } |
||||
| 89 | |||||
| 90 | // Allow editing if the document is part of an exercise |
||||
| 91 | if (!empty($_GET['exerciseId']) || !empty($_GET['exeId'])) { |
||||
| 92 | return true; |
||||
| 93 | } |
||||
| 94 | |||||
| 95 | $accessRights = $isAllowToEdit || $isMyDir || $isGroupAccess; |
||||
| 96 | |||||
| 97 | return $accessRights; |
||||
| 98 | } |
||||
| 99 | |||||
| 100 | public function isReadOnly() |
||||
| 101 | { |
||||
| 102 | return $this->documentManager->getDocInfo('readonly'); |
||||
| 103 | } |
||||
| 104 | |||||
| 105 | public function getUser() |
||||
| 106 | { |
||||
| 107 | $user = new User(); |
||||
| 108 | $user->setId(api_get_user_id()); |
||||
| 109 | $userInfo = api_get_user_info($userId); |
||||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||||
| 110 | $user->setName($userInfo['username']); |
||||
| 111 | |||||
| 112 | return $user; |
||||
| 113 | } |
||||
| 114 | |||||
| 115 | public function getCustomization(string $fileId) |
||||
| 116 | { |
||||
| 117 | $goback = new GoBack(); |
||||
| 118 | |||||
| 119 | if (!empty($this->documentManager->getGobackUrl($fileId))) { |
||||
| 120 | $goback->setUrl($this->documentManager->getGobackUrl($fileId)); |
||||
| 121 | } |
||||
| 122 | $goback->setBlank(false); |
||||
| 123 | $customization = new Customization(); |
||||
| 124 | $customization->setGoback($goback); |
||||
| 125 | $customization->setCompactHeader(true); |
||||
| 126 | $customization->setToolbarNoTabs(true); |
||||
| 127 | |||||
| 128 | return $customization; |
||||
| 129 | } |
||||
| 130 | |||||
| 131 | public function getLang() |
||||
| 132 | { |
||||
| 133 | return $this->getLangInfo(); |
||||
| 134 | } |
||||
| 135 | |||||
| 136 | public function getRegion() |
||||
| 137 | { |
||||
| 138 | return $this->getLangInfo(); |
||||
| 139 | } |
||||
| 140 | |||||
| 141 | public function getLangInfo() |
||||
| 142 | { |
||||
| 143 | $langInfo = LangManager::getLangUser(); |
||||
| 144 | |||||
| 145 | return $langInfo['isocode']; |
||||
| 146 | } |
||||
| 147 | |||||
| 148 | public function getPermissions(string $fileId = '') |
||||
| 149 | { |
||||
| 150 | $permsEdit = $this->getAccessRights() && !$this->isReadOnly(); |
||||
| 151 | $isFillable = $this->documentManager->isDocumentFillable($this->documentManager->getDocInfo('title')); |
||||
| 152 | |||||
| 153 | $permissions = new Permissions(null, |
||||
| 154 | null, |
||||
| 155 | null, |
||||
| 156 | null, |
||||
| 157 | null, |
||||
| 158 | null, |
||||
| 159 | $permsEdit, |
||||
| 160 | null, |
||||
| 161 | $isFillable, |
||||
| 162 | null, |
||||
| 163 | null, |
||||
| 164 | null, |
||||
| 165 | null, |
||||
| 166 | null, |
||||
| 167 | null, |
||||
| 168 | null, |
||||
| 169 | null |
||||
| 170 | ); |
||||
| 171 | |||||
| 172 | return $permissions; |
||||
| 173 | } |
||||
| 174 | |||||
| 175 | public function getCoEditing(string $fileId = '', $mode = null, $type) |
||||
| 176 | { |
||||
| 177 | return null; |
||||
| 178 | } |
||||
| 179 | } |
||||
| 180 |