diff --git a/assets/js/lp.js b/assets/js/lp.js new file mode 100644 index 0000000000..a117bc425e --- /dev/null +++ b/assets/js/lp.js @@ -0,0 +1,15 @@ + +/* For licensing terms, see /license.txt */ + +import $ from 'jquery'; + +window.jQuery = $; +window.$ = $; +global.jQuery = $; + +import('webpack-jquery-ui'); +import('webpack-jquery-ui/css'); + + +var hljs = require('highlight.js'); +global.hljs = hljs; diff --git a/public/main/inc/ajax/document.ajax.php b/public/main/inc/ajax/document.ajax.php index cf27514937..8208c46dfc 100644 --- a/public/main/inc/ajax/document.ajax.php +++ b/public/main/inc/ajax/document.ajax.php @@ -1,4 +1,5 @@ true, + ]); + break; + $lpId = isset($_GET['lp']) ? intval($_GET['lp']) : 0; $lpItemId = isset($_GET['lp_item']) ? intval($_GET['lp_item']) : 0; $sessionId = api_get_session_id(); @@ -205,8 +211,9 @@ switch ($action) { ]); break; } - - $forum = $learningPath->getForum($sessionId); + // @todo fix get forum + //$forum = $learningPath->getForum($sessionId); + $forum = false;; if (empty($forum)) { require_once '../../forum/forumfunction.inc.php'; diff --git a/public/main/inc/lib/display.lib.php b/public/main/inc/lib/display.lib.php index 5bcaa1ba7e..c74a282bf8 100644 --- a/public/main/inc/lib/display.lib.php +++ b/public/main/inc/lib/display.lib.php @@ -2829,6 +2829,9 @@ HTML; $translateHtml = '{type:"script", src:"'.api_get_path(WEB_AJAX_PATH).'lang.ajax.php?a=translate_html&'.api_get_cidreq().'"},'; } + $lpJs = api_get_path(WEB_PUBLIC_PATH).'build/lp.js'; + //{type:"script", src:"'.api_get_jquery_ui_js_web_path().'"}, + //{type:"script", src: "'.$webPublicPath.'build/libs/mediaelement/plugins/markersrolls/markersrolls.js"}, $videoFeatures = implode("','", $videoFeatures); $frameReady = ' $.frameReady(function() { @@ -2845,22 +2848,20 @@ HTML; }, "'.$frameName.'", [ - {type:"script", src:"'.api_get_jquery_web_path().'", deps: [ - {type:"script", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.highlight.js"}, + {type:"script", src:"'.$lpJs.'", deps: [ + {type:"script", src:"'.api_get_path(WEB_CODE_PATH).'glossary/glossary.js.php?'.api_get_cidreq().'"}, - {type:"script", src:"'.api_get_jquery_ui_js_web_path().'"}, + {type:"script", src: "'.$webPublicPath.'build/libs/mediaelement/mediaelement-and-player.min.js", deps: [ {type:"script", src: "'.$webPublicPath.'build/libs/mediaelement/plugins/vrview/vrview.js"}, - {type:"script", src: "'.$webPublicPath.'build/libs/mediaelement/plugins/markersrolls/markersrolls.js"}, '.$videoPluginFiles.' ]}, '.$translateHtml.' ]}, '.$videoPluginCssFiles.' {type:"script", src:"'.$webPublicPath.'build/libs/mathjax/MathJax.js?config=AM_HTMLorMML"}, - {type:"stylesheet", src:"'.$webPublicPath.'assets/jquery-ui/themes/smoothness/jquery-ui.min.css"}, - {type:"stylesheet", src:"'.$webPublicPath.'assets/jquery-ui/themes/smoothness/theme.css"}, + ]);'; return $frameReady; diff --git a/public/main/inc/lib/document.lib.php b/public/main/inc/lib/document.lib.php index 4f757ce41b..f505712209 100644 --- a/public/main/inc/lib/document.lib.php +++ b/public/main/inc/lib/document.lib.php @@ -2625,9 +2625,6 @@ class DocumentManager ) { $course_info = api_get_course_info(); $sessionId = api_get_session_id(); - $course_dir = $course_info['path'].'/document'; - $sys_course_path = api_get_path(SYS_COURSE_PATH); - $base_work_dir = $sys_course_path.$course_dir; if (isset($files[$fileKey])) { $uploadOk = process_uploaded_file($files[$fileKey], $show_output); @@ -2636,7 +2633,7 @@ class DocumentManager $document = handle_uploaded_document( $course_info, $files[$fileKey], - $base_work_dir, + null, $path, api_get_user_id(), api_get_group_id(), @@ -2935,7 +2932,7 @@ class DocumentManager } $link .= ''; - $link .= $folder.' '.$node['slug']; + $link .= $folder.' '.addslashes($node['title']); $link .= ''; $link .= ''; @@ -4430,13 +4427,13 @@ class DocumentManager // Check if pathname already exists inside document table $table = Database::get_course_table(TABLE_DOCUMENT); - $sql = "SELECT id, path FROM $table + $sql = "SELECT iid, title FROM $table WHERE filetype = 'file' AND c_id = $courseId AND ( - path = '".$fileNameEscape."' OR - path = '$fileNameWithSuffix' + title = '".$fileNameEscape."' OR + title = '$fileNameWithSuffix' ) AND (session_id = 0 OR session_id = $sessionId) "; @@ -4494,6 +4491,11 @@ class DocumentManager $counter = 1; $filePath = $path.$name; $uniqueName = $name; + $baseName = pathinfo($name, PATHINFO_FILENAME); + $extension = pathinfo($name, PATHINFO_EXTENSION); + + return uniqid($baseName.'-', true).'.'.$extension; + while ($documentExists = self::documentExists( $filePath, $courseInfo, diff --git a/public/main/inc/lib/fileUpload.lib.php b/public/main/inc/lib/fileUpload.lib.php index d1d9d9e4b2..205eae71fb 100644 --- a/public/main/inc/lib/fileUpload.lib.php +++ b/public/main/inc/lib/fileUpload.lib.php @@ -275,7 +275,9 @@ function handle_uploaded_document( // Check if there is enough space to save the file if (!DocumentManager::enough_space($uploadedFile['size'], $maxSpace)) { if ($output) { - Display::addFlash(Display::return_message(get_lang('There is not enough space to upload this file.'), 'error')); + Display::addFlash( + Display::return_message(get_lang('There is not enough space to upload this file.'), 'error') + ); } return false; @@ -332,7 +334,7 @@ function handle_uploaded_document( return false; } else { // If the upload path differs from / (= root) it will need a slash at the end - if ('/' != $uploadPath) { + if ('/' !== $uploadPath) { $uploadPath = $uploadPath.'/'; } @@ -340,26 +342,30 @@ function handle_uploaded_document( $whereToSave = $documentDir.$uploadPath; // Just upload the file "as is" - if ($onlyUploadFile) { + /*if ($onlyUploadFile) { $errorResult = moveUploadedFile($uploadedFile, $whereToSave.$cleanName); if ($errorResult) { return $whereToSave.$cleanName; } return $errorResult; - } + }*/ /* Based in the clean name we generate a new filesystem name Using the session_id and group_id if values are not empty */ - $fileSystemName = DocumentManager::fixDocumentName( + + // @todo fix clean name use hash instead of custom document name + /*$fileSystemName = DocumentManager::fixDocumentName( $cleanName, 'file', $courseInfo, $sessionId, $groupId - ); + );*/ + + $fileSystemName = $cleanName; // Name of the document without the extension (for the title) $documentTitle = get_document_title($uploadedFile['name']); @@ -368,16 +374,39 @@ function handle_uploaded_document( $fileSize = $uploadedFile['size']; // Example: /folder/picture.jpg - $filePath = $uploadPath.$fileSystemName; - + /*$filePath = $uploadPath.$fileSystemName; $docId = DocumentManager::get_document_id( $courseInfo, $filePath, $sessionId - ); + );*/ + + $courseEntity = api_get_course_entity($courseInfo['real_id']); + if (empty($courseEntity)) { + return false; + } + $sessionId = empty($sessionId) ? api_get_session_id() : $sessionId; + $session = api_get_session_entity($sessionId); + $group = api_get_group_entity($groupId); $documentRepo = Container::getDocumentRepository(); - $document = $documentRepo->find($docId); + + /** @var \Chamilo\CoreBundle\Entity\AbstractResource $parentResource */ + $parentResource = $courseEntity; + if (!empty($parentId)) { + $parent = $documentRepo->find($parentId); + if ($parent) { + $parentResource = $parent; + } + } + + $document = $documentRepo->findResourceByTitle( + $documentTitle, + $parentResource->getResourceNode(), + $courseEntity, + $session, + $group + ); if (!($content instanceof UploadedFile)) { $request = Container::getRequest(); @@ -393,15 +422,15 @@ function handle_uploaded_document( case 'overwrite': if ($document) { // Update file size - update_existing_document( + /*update_existing_document( $courseInfo, $document->getIid(), $uploadedFile['size'] - ); + );*/ $document = DocumentManager::addFileToDocument( $document, - $filePath, + null, $content, $defaultVisibility, null, @@ -425,7 +454,7 @@ function handle_uploaded_document( // Put the document data in the database $document = DocumentManager::addDocument( $courseInfo, - $filePath, + null, 'file', $fileSize, $documentTitle, diff --git a/public/main/inc/lib/tracking.lib.php b/public/main/inc/lib/tracking.lib.php index a6d0003e57..8c27853d00 100644 --- a/public/main/inc/lib/tracking.lib.php +++ b/public/main/inc/lib/tracking.lib.php @@ -363,7 +363,7 @@ class Tracking iv.max_score as myviewmaxscore, i.item_type as item_type, iv.view_count as iv_view_count, - iv.id as iv_id, + iv.iid as iv_id, path FROM $TBL_LP_ITEM as i INNER JOIN $TBL_LP_ITEM_VIEW as iv diff --git a/public/main/lp/learnpath.class.php b/public/main/lp/learnpath.class.php index e6f85261ef..58278ce73a 100644 --- a/public/main/lp/learnpath.class.php +++ b/public/main/lp/learnpath.class.php @@ -7884,13 +7884,6 @@ class learnpath true ); - $headers = [ - get_lang('Files'), - get_lang('CreateTheDocument'), - get_lang('CreateReadOutText'), - get_lang('Upload'), - ]; - $form = new FormValidator( 'form_upload', 'POST', @@ -7959,9 +7952,9 @@ class learnpath $url = api_get_path(WEB_AJAX_PATH).'document.ajax.php?'.api_get_cidreq().'&a=upload_file&curdirpath='; $form->addMultipleUpload($url); - $lpItem = new CLpItem(); + /*$lpItem = new CLpItem(); $lpItem->setItemType(TOOL_DOCUMENT); - $new = $this->displayDocumentForm('add', $lpItem); + $new = $this->displayDocumentForm('add', $lpItem);*/ /*$lpItem = new CLpItem(); $lpItem->setItemType(TOOL_READOUT_TEXT); @@ -7970,13 +7963,13 @@ class learnpath $headers = [ get_lang('Files'), get_lang('Create a new document'), - get_lang('Create read-out text'), + //get_lang('Create read-out text'), get_lang('Upload'), ]; return Display::tabs( $headers, - [$documentTree, $new, $form->returnForm()], + [$documentTree, $form->returnForm()], 'subtab' ); } @@ -9944,6 +9937,7 @@ EOD; $debug = 0; $learnPath = null; $lpObject = Session::read('lpobject'); + if (null !== $lpObject) { $learnPath = UnserializeApi::unserialize('lp', $lpObject); if ($debug) { @@ -9956,7 +9950,9 @@ EOD; } if (!is_object($learnPath)) { - $learnPath = new learnpath($courseCode, $lpId, $user_id); + $repo = Container::getLpRepository(); + $lp = $repo->find($lpId); + $learnPath = new learnpath($lp, api_get_course_info($courseCode), $user_id); if ($debug) { error_log('------getLpFromSession------'); error_log('getLpFromSession: create new learnpath'); @@ -10280,6 +10276,8 @@ EOD; /** * Check if this LP has a created forum in the basis course. * + * @deprecated + * * @return bool */ public function lpHasForum() @@ -10559,7 +10557,7 @@ EOD; $id = empty($rowItem->getPath()) ? '0' : $rowItem->getPath(); $main_dir_path = api_get_path(WEB_CODE_PATH); $link = ''; - $extraParams = api_get_cidreq(true, true, 'learnpath').'&session_id='.$session_id; + $extraParams = api_get_cidreq(true, true, 'learnpath').'&sid='.$session_id; switch ($type) { case 'dir': @@ -10584,13 +10582,13 @@ EOD; $learnpathItemViewResult = $em ->getRepository('ChamiloCourseBundle:CLpItemView') ->findBy( - ['cId' => $course_id, 'lpItemId' => $rowItem->getId(), 'lpViewId' => $lpViewId], + ['cId' => $course_id, 'lpItemId' => $rowItem->getIid(), 'lpViewId' => $lpViewId], ['viewCount' => 'DESC'], 1 ); /** @var CLpItemView $learnpathItemViewData */ $learnpathItemViewData = current($learnpathItemViewResult); - $learnpathItemViewId = $learnpathItemViewData ? $learnpathItemViewData->getId() : 0; + $learnpathItemViewId = $learnpathItemViewData ? $learnpathItemViewData->getIid() : 0; return $main_dir_path.'exercise/overview.php?'.$extraParams.'&' .http_build_query([ @@ -10636,7 +10634,11 @@ EOD; case TOOL_DOCUMENT: $repo = Container::getDocumentRepository(); $document = $repo->find($rowItem->getPath()); - $file = $repo->getResourceFileUrl($document, [], UrlGeneratorInterface::ABSOLUTE_URL); + $params = [ + 'cid' => $course_id, + 'sid' => $session_id, + ]; + $file = $repo->getResourceFileUrl($document, $params, UrlGeneratorInterface::ABSOLUTE_URL); return $file; diff --git a/src/CoreBundle/Resources/views/LearnPath/view.html.twig b/src/CoreBundle/Resources/views/LearnPath/view.html.twig index b55abd3c94..3ca4c6dc7e 100644 --- a/src/CoreBundle/Resources/views/LearnPath/view.html.twig +++ b/src/CoreBundle/Resources/views/LearnPath/view.html.twig @@ -299,7 +299,7 @@ LPViewUtils.setHeightLPToc(); - $('.image-avatar img').load(function () { + $('.image-avatar img').on('load', function () { LPViewUtils.setHeightLPToc(); }); diff --git a/src/CourseBundle/Entity/CLpItemView.php b/src/CourseBundle/Entity/CLpItemView.php index 1c7668621f..227034fba9 100644 --- a/src/CourseBundle/Entity/CLpItemView.php +++ b/src/CourseBundle/Entity/CLpItemView.php @@ -126,6 +126,14 @@ class CLpItemView $this->coreExit = 'none'; } + /** + * @return int + */ + public function getIid(): int + { + return $this->iid; + } + /** * Set lpItemId. * diff --git a/webpack.config.js b/webpack.config.js index b27ae0a678..3b5760c034 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -13,6 +13,7 @@ Encore .addEntry('bootstrap', './assets/js/bootstrap.js') .addEntry('exercise', './assets/js/exercise.js') .addEntry('free-jqgrid', './assets/js/free-jqgrid.js') + .addEntry('lp', './assets/js/lp.js') .addEntry('vue', './assets/vue/main.js') .addStyleEntry('css/app', './assets/css/app.scss')