Skip to content

Commit e2dac81

Browse files
committed
Merge pull request 'Release/v1.5.0' from develop into master
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/onlyoffice-chamilo/pulls/11
2 parents 019e8fa + 15984d5 commit e2dac81

File tree

4 files changed

+80
-3
lines changed

4 files changed

+80
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
This plugin is developed and maintained at https://github.com/ONLYOFFICE/onlyoffice-chamilo.
44

5+
## 1.5.0
6+
## Added
7+
- support learning path
8+
59
## 1.4.1
610
## Changed
711
- minor fixes

editor.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,18 @@
6969
$config = json_decode(json_encode($config), true);
7070
$isMobileAgent = $configService->isMobileAgent($_SERVER['HTTP_USER_AGENT']);
7171

72+
$showHeaders = true;
73+
$headerHeight = 'calc(100% - 140px)';
74+
if (!empty($_GET['nh'])) {
75+
$showHeaders = false;
76+
$headerHeight = '100%';
77+
}
78+
7279
?>
7380
<title>ONLYOFFICE</title>
7481
<style>
7582
#app > iframe {
76-
height: calc(100% - 140px);
83+
height: <?php echo $headerHeight; ?>;
7784
}
7885
body {
7986
height: 100%;
@@ -172,4 +179,10 @@
172179
}
173180

174181
</script>
175-
<?php echo Display::display_header(); ?>
182+
<?php
183+
if ($showHeaders) {
184+
echo Display::display_header();
185+
} else {
186+
echo Display::display_reduced_header();
187+
}
188+
?>

lib/onlyofficePlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class OnlyofficePlugin extends Plugin implements HookPluginInterface
3333
protected function __construct()
3434
{
3535
parent::__construct(
36-
'1.4.1',
36+
'1.5.0',
3737
'Asensio System SIA',
3838
[
3939
'enable_onlyoffice_plugin' => 'boolean',

lib/onlyofficeTools.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,64 @@ public static function getButtonCreateNew(): string
149149
$urlToCreate
150150
);
151151
}
152+
153+
/**
154+
* Return path to OnlyOffice viewer for a given file.
155+
* @param int $documentId The ID from c_document.iid
156+
* @param bool $showHeaders Whether to show Chamilo headers on top of the OnlyOffice frame or not
157+
*
158+
* @return string A link to open the OnlyOffice viewer
159+
*/
160+
public static function getPathToView(int $documentId, bool $showHeaders = true): string
161+
{
162+
$plugin = OnlyofficePlugin::create();
163+
$appSettings = new OnlyofficeAppsettings($plugin);
164+
$documentManager = new OnlyofficeDocumentManager($appSettings, []);
165+
166+
$isEnable = 'true' === $plugin->get('enable_onlyoffice_plugin');
167+
if (!$isEnable) {
168+
return '';
169+
}
170+
171+
$urlToEdit = api_get_path(WEB_PLUGIN_PATH).'onlyoffice/editor.php';
172+
173+
$sessionId = api_get_session_id();
174+
$courseInfo = api_get_course_info();
175+
$userId = api_get_user_id();
176+
177+
$docInfo = DocumentManager::get_document_data_by_id($documentId, $courseInfo['code'], false, $sessionId);
178+
179+
$extension = strtolower(pathinfo($docInfo['path'], PATHINFO_EXTENSION));
180+
$canView = null !== $documentManager->getFormatInfo($extension) ? $documentManager->getFormatInfo($extension)->isViewable() : false;
181+
182+
$isGroupAccess = false;
183+
$groupId = api_get_group_id();
184+
if (!empty($groupId)) {
185+
$groupProperties = GroupManager::get_group_properties($groupId);
186+
$docInfoGroup = api_get_item_property_info(api_get_course_int_id(), 'document', $documentId, $sessionId);
187+
$isGroupAccess = GroupManager::allowUploadEditDocument($userId, $courseInfo['code'], $groupProperties, $docInfoGroup);
188+
189+
$urlToEdit = $urlToEdit.'?groupId='.$groupId.'&';
190+
} else {
191+
$urlToEdit = $urlToEdit.'?';
192+
}
193+
error_log(__LINE__.' '.$urlToEdit);
194+
195+
$isMyDir = DocumentManager::is_my_shared_folder($userId, $docInfo['absolute_parent_path'], $sessionId);
196+
197+
$accessRights = $isMyDir || $isGroupAccess;
198+
199+
$urlToEdit = $urlToEdit.'docId='.$documentId;
200+
if (false === $showHeaders) {
201+
$urlToEdit .= '&nh=1';
202+
}
203+
204+
if ($canView && !$accessRights) {
205+
error_log(__LINE__.' '.$urlToEdit);
206+
207+
return $urlToEdit;
208+
}
209+
210+
return '';
211+
}
152212
}

0 commit comments

Comments
 (0)