LP: Fix create html text

pull/3844/head
Julio Montoya 5 years ago
parent c874fe54b1
commit ccaa944452
  1. 8
      public/main/inc/lib/document.lib.php
  2. 38
      public/main/lp/LearnPathItemForm.php
  3. 9
      public/main/lp/learnpath.class.php
  4. 6
      public/main/lp/lp_controller.php
  5. 2
      src/CourseBundle/Entity/CLpItem.php

@ -6105,11 +6105,10 @@ This folder contains all sessions that have been opened in the chat. Although th
$em = Database::getManager();
$title = $document->getTitle();
// Only create a ResourceFile if there's a file involved
if ('file' === $fileType) {
$resourceFile = $resourceNode->getResourceFile();
if (empty($resourceFile)) {
if (null === $resourceFile) {
$resourceFile = new ResourceFile();
}
@ -6118,7 +6117,7 @@ This folder contains all sessions that have been opened in the chat. Although th
error_log('UploadedFile');
} else {
// $path points to a file in the directory
if (file_exists($realPath) && !is_dir($realPath)) {
if (!empty($realPath) && file_exists($realPath) && !is_dir($realPath)) {
error_log('file_exists');
$mimeType = mime_content_type($realPath);
$file = new UploadedFile($realPath, $title, $mimeType, null, true);
@ -6224,7 +6223,7 @@ This folder contains all sessions that have been opened in the chat. Although th
$parentResource->getResourceNode(),
$courseEntity,
$session,
null
$group
);
// Document already exists
@ -6254,7 +6253,6 @@ This folder contains all sessions that have been opened in the chat. Although th
$em = Database::getManager();
$em->persist($document);
$em->flush();
$document = self::addFileToDocument($document, $realPath, $content, $visibility, $group);
if ($document) {

@ -112,7 +112,7 @@ class LearnPathItemForm
$position->freeze();
}
// Content
// Content.
if (in_array($itemType, [TOOL_DOCUMENT, TOOL_LP_FINAL_ITEM, TOOL_READOUT_TEXT], true)) {
$document = null;
if (!empty($lpItem->getPath())) {
@ -121,25 +121,23 @@ class LearnPathItemForm
$document = $repo->find($lpItem->getPath());
}
if ($document) {
if ($document->getResourceNode()->hasEditableTextContent()) {
$editorConfig = [
'ToolbarSet' => 'LearningPathDocuments',
'Width' => '100%',
'Height' => '500',
'FullPage' => true,
// 'CreateDocumentDir' => $relative_prefix,
//'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/',
//'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/'.$relative_path,
];
$renderer = $form->defaultRenderer();
$renderer->setElementTemplate(' {label}{element}', 'content_lp');
$form->addElement('html', '<div class="editor-lp">');
$form->addHtmlEditor('content_lp', null, null, true, $editorConfig, true);
$form->addElement('html', '</div>');
$editorConfig = [
'ToolbarSet' => 'LearningPathDocuments',
'Width' => '100%',
'Height' => '500',
'FullPage' => true,
// 'CreateDocumentDir' => $relative_prefix,
//'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/',
//'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/'.$relative_path,
];
if (($document && $document->getResourceNode()->hasEditableTextContent()) || 'add' === $action) {
$renderer = $form->defaultRenderer();
$renderer->setElementTemplate('&nbsp;{label}{element}', 'content_lp');
$form->addElement('html', '<div class="editor-lp">');
$form->addHtmlEditor('content_lp', null, null, true, $editorConfig, true);
$form->addElement('html', '</div>');
if ($document) {
$form->addHidden('document_id', $document->getIid());
$content = $lp->display_document(
$document,

@ -6200,12 +6200,6 @@ class learnpath
$parentId = 0,
$creatorId = 0
) {
if (!empty($courseInfo)) {
$course_id = $courseInfo['real_id'];
} else {
$course_id = api_get_course_int_id();
}
$creatorId = empty($creatorId) ? api_get_user_id() : $creatorId;
$sessionId = api_get_session_id();
@ -6222,7 +6216,6 @@ class learnpath
$title = disable_dangerous_file($title);
$filename = $title;
$content = !empty($content) ? $content : $_POST['content_lp'];
$tmp_filename = $filename;
/*$i = 0;
while (file_exists($filepath.$tmp_filename.'.'.$extension)) {
@ -6264,8 +6257,6 @@ class learnpath
);
}
//$save_file_path = $dir.$filename;
$document = DocumentManager::addDocument(
$courseInfo,
null,

@ -631,7 +631,7 @@ switch ($action) {
}
Session::write('refresh', 1);
// Creates first root item.
$itemRoot = $lpItemRepo->getItemRoot($lpId);
if (null == $itemRoot) {
$lpItem = new CLpItem();
@ -640,8 +640,6 @@ switch ($action) {
->setPath('root')
->setLp($lp)
->setItemType('root')
//->setNextItemId((int) $next)
//->setPreviousItemId($previous)
;
$em = Database::getManager();
$em->persist($lpItem);
@ -660,7 +658,7 @@ switch ($action) {
$parent = $_POST['parent'] ?? null;
$em = Database::getManager();
if (!empty($parent)) {
$parent = $em->getRepository(CLpItem::class)->find($parent);
$parent = $lpItemRepo->find($parent);
} else {
$parent = null;
}

@ -179,7 +179,7 @@ class CLpItem
public function __toString(): string
{
return (string) ($this->getIid().' '.$this->getTitle());
return $this->getIid().' '.$this->getTitle();
}
public function getIid(): ?int

Loading…
Cancel
Save