Fix LP view use assets/js/lp.js, fix doc upload from LP - WIP

pull/3741/head
Julio Montoya 5 years ago
parent 0957e8c44b
commit 05e539203f
  1. 15
      assets/js/lp.js
  2. 19
      public/main/inc/ajax/document.ajax.php
  3. 11
      public/main/inc/ajax/lp.ajax.php
  4. 13
      public/main/inc/lib/display.lib.php
  5. 18
      public/main/inc/lib/document.lib.php
  6. 57
      public/main/inc/lib/fileUpload.lib.php
  7. 2
      public/main/inc/lib/tracking.lib.php
  8. 34
      public/main/lp/learnpath.class.php
  9. 2
      src/CoreBundle/Resources/views/LearnPath/view.html.twig
  10. 8
      src/CourseBundle/Entity/CLpItemView.php
  11. 1
      webpack.config.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;

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Framework\Container;
@ -37,7 +38,7 @@ switch ($action) {
$sessionId = api_get_session_id();
if (!$is_allowed_to_edit && $sessionId &&
$_REQUEST['curdirpath'] == "/basic-course-documents__{$sessionId}__0"
$_REQUEST['curdirpath'] === "/basic-course-documents__{$sessionId}__0"
) {
$session = SessionManager::fetch($sessionId);
@ -66,18 +67,8 @@ switch ($action) {
exit;
}
$directoryParentId = isset($_REQUEST['directory_parent_id']) ? $_REQUEST['directory_parent_id'] : 0;
$currentDirectory = '';
if (empty($directoryParentId)) {
$currentDirectory = isset($_REQUEST['curdirpath']) ? $_REQUEST['curdirpath'] : '';
} else {
$documentData = DocumentManager::get_document_data_by_id($directoryParentId, api_get_course_id());
if ($documentData) {
$currentDirectory = $documentData['path'];
}
}
$ifExists = isset($_POST['if_exists']) ? $_POST['if_exists'] : '';
$directoryParentId = $_REQUEST['directory_parent_id'] ?? 0;
$ifExists = $_POST['if_exists'] ?? '';
$unzip = isset($_POST['unzip']) ? 1 : 0;
if (empty($ifExists)) {
@ -107,7 +98,7 @@ switch ($action) {
$globalFile['files'] = $file;
$document = DocumentManager::upload_document(
$globalFile,
$currentDirectory,
null,
'',
'', // comment
$unzip,

@ -171,6 +171,12 @@ switch ($action) {
break;
case 'get_forum_thread':
// @todo fix get forum thread
echo json_encode([
'error' => 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';

@ -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;

@ -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 .= '<a data_id="'.$node['id'].'" data_type="document" class="moved ui-sortable-handle link_with_id">';
$link .= $folder.'&nbsp;'.$node['slug'];
$link .= $folder.'&nbsp;'.addslashes($node['title']);
$link .= '</a>';
$link .= '</div>';
@ -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,

@ -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,

@ -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

@ -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;

@ -299,7 +299,7 @@
LPViewUtils.setHeightLPToc();
$('.image-avatar img').load(function () {
$('.image-avatar img').on('load', function () {
LPViewUtils.setHeightLPToc();
});

@ -126,6 +126,14 @@ class CLpItemView
$this->coreExit = 'none';
}
/**
* @return int
*/
public function getIid(): int
{
return $this->iid;
}
/**
* Set lpItemId.
*

@ -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')

Loading…
Cancel
Save