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(); $em = Database::getManager();
$title = $document->getTitle(); $title = $document->getTitle();
// Only create a ResourceFile if there's a file involved // Only create a ResourceFile if there's a file involved
if ('file' === $fileType) { if ('file' === $fileType) {
$resourceFile = $resourceNode->getResourceFile(); $resourceFile = $resourceNode->getResourceFile();
if (empty($resourceFile)) { if (null === $resourceFile) {
$resourceFile = new 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'); error_log('UploadedFile');
} else { } else {
// $path points to a file in the directory // $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'); error_log('file_exists');
$mimeType = mime_content_type($realPath); $mimeType = mime_content_type($realPath);
$file = new UploadedFile($realPath, $title, $mimeType, null, true); $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(), $parentResource->getResourceNode(),
$courseEntity, $courseEntity,
$session, $session,
null $group
); );
// Document already exists // 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 = Database::getManager();
$em->persist($document); $em->persist($document);
$em->flush(); $em->flush();
$document = self::addFileToDocument($document, $realPath, $content, $visibility, $group); $document = self::addFileToDocument($document, $realPath, $content, $visibility, $group);
if ($document) { if ($document) {

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

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

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

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

Loading…
Cancel
Save