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

pull/5867/head
Yannick Warnier 11 months ago
parent 3ea92aa1a7
commit 0f32994d39
  1. 45
      main/lp/learnpath.class.php

@ -3710,18 +3710,55 @@ class learnpath
'zip',
'ppt',
'pptx',
'ods',
'xlsx',
'odp',
'xls',
'xlsx',
'ods',
'csv',
'doc',
'docx',
'odt',
'pdf',
'dot',
];
$officeExtensions = [
'ppt',
'pptx',
'odp',
'xls',
'xlsx',
'ods',
'csv',
'doc',
'docx',
'odt',
'pdf',
];
if (in_array($extension, $extensionsToDownload)) {
$file = api_get_path(WEB_CODE_PATH).
'lp/embed.php?type=download&source=file&lp_item_id='.$item_id.'&'.api_get_cidreq();
$found = false;
if (in_array($extension, $officeExtensions)) {
$onlyOffice = OnlyofficePlugin::create();
if ($onlyOffice->isEnabled()) {
$lpItem = $this->getItem($item_id);
if ($lpItem->get_type() == 'document') {
$docId = $lpItem->get_path();
if (method_exists('OnlyofficeTools', 'getPathToView')) {
$pathToView = OnlyofficeTools::getPathToView($docId, false);
// getPathView returns empty on error, so if this is the case,
// fallback to normal viewer/downloader
if (!empty($pathToView)) {
$file = $pathToView;
$found = true;
}
}
}
}
}
if (false === $found) {
$file = api_get_path(WEB_CODE_PATH).
'lp/embed.php?type=download&source=file&lp_item_id='.$item_id.'&'.api_get_cidreq();
}
}
}
}

Loading…
Cancel
Save