Skip to content

Commit 0f32994

Browse files
committed
Learnpath: Add support for OnlyOffice viewer in learning paths for ppt(x), odp, xls(x), ods, csv, doc(x), odt and pdf formats - refs #5395
1 parent 3ea92aa commit 0f32994

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

main/lp/learnpath.class.php

+41-4
Original file line numberDiff line numberDiff line change
@@ -3710,18 +3710,55 @@ public function get_link($type = 'http', $item_id = 0, $provided_toc = false)
37103710
'zip',
37113711
'ppt',
37123712
'pptx',
3713-
'ods',
3714-
'xlsx',
3713+
'odp',
37153714
'xls',
3715+
'xlsx',
3716+
'ods',
37163717
'csv',
37173718
'doc',
37183719
'docx',
3720+
'odt',
3721+
'pdf',
37193722
'dot',
37203723
];
3724+
$officeExtensions = [
3725+
'ppt',
3726+
'pptx',
3727+
'odp',
3728+
'xls',
3729+
'xlsx',
3730+
'ods',
3731+
'csv',
3732+
'doc',
3733+
'docx',
3734+
'odt',
3735+
'pdf',
3736+
];
37213737

37223738
if (in_array($extension, $extensionsToDownload)) {
3723-
$file = api_get_path(WEB_CODE_PATH).
3724-
'lp/embed.php?type=download&source=file&lp_item_id='.$item_id.'&'.api_get_cidreq();
3739+
$found = false;
3740+
if (in_array($extension, $officeExtensions)) {
3741+
$onlyOffice = OnlyofficePlugin::create();
3742+
if ($onlyOffice->isEnabled()) {
3743+
$lpItem = $this->getItem($item_id);
3744+
if ($lpItem->get_type() == 'document') {
3745+
$docId = $lpItem->get_path();
3746+
if (method_exists('OnlyofficeTools', 'getPathToView')) {
3747+
$pathToView = OnlyofficeTools::getPathToView($docId, false);
3748+
// getPathView returns empty on error, so if this is the case,
3749+
// fallback to normal viewer/downloader
3750+
if (!empty($pathToView)) {
3751+
$file = $pathToView;
3752+
$found = true;
3753+
}
3754+
}
3755+
}
3756+
}
3757+
}
3758+
if (false === $found) {
3759+
$file = api_get_path(WEB_CODE_PATH).
3760+
'lp/embed.php?type=download&source=file&lp_item_id='.$item_id.'&'.api_get_cidreq();
3761+
}
37253762
}
37263763
}
37273764
}

0 commit comments

Comments
 (0)