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. 41
      main/lp/learnpath.class.php

@ -3710,21 +3710,58 @@ class learnpath
'zip', 'zip',
'ppt', 'ppt',
'pptx', 'pptx',
'ods', 'odp',
'xlsx',
'xls', 'xls',
'xlsx',
'ods',
'csv', 'csv',
'doc', 'doc',
'docx', 'docx',
'odt',
'pdf',
'dot', 'dot',
]; ];
$officeExtensions = [
'ppt',
'pptx',
'odp',
'xls',
'xlsx',
'ods',
'csv',
'doc',
'docx',
'odt',
'pdf',
];
if (in_array($extension, $extensionsToDownload)) { if (in_array($extension, $extensionsToDownload)) {
$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). $file = api_get_path(WEB_CODE_PATH).
'lp/embed.php?type=download&source=file&lp_item_id='.$item_id.'&'.api_get_cidreq(); 'lp/embed.php?type=download&source=file&lp_item_id='.$item_id.'&'.api_get_cidreq();
} }
} }
} }
}
break; break;
case 'dir': case 'dir':
$file = 'lp_content.php?type=dir&'.api_get_cidreq(); $file = 'lp_content.php?type=dir&'.api_get_cidreq();

Loading…
Cancel
Save