diff --git a/public/main/inc/lib/document.lib.php b/public/main/inc/lib/document.lib.php index 0ab546bd3e..7fb34de5ba 100644 --- a/public/main/inc/lib/document.lib.php +++ b/public/main/inc/lib/document.lib.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) { diff --git a/public/main/lp/LearnPathItemForm.php b/public/main/lp/LearnPathItemForm.php index 153ee662fc..6a0953f639 100644 --- a/public/main/lp/LearnPathItemForm.php +++ b/public/main/lp/LearnPathItemForm.php @@ -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', '
'); - $form->addHtmlEditor('content_lp', null, null, true, $editorConfig, true); - $form->addElement('html', '
'); - - + $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(' {label}{element}', 'content_lp'); + $form->addElement('html', '
'); + $form->addHtmlEditor('content_lp', null, null, true, $editorConfig, true); + $form->addElement('html', '
'); + if ($document) { $form->addHidden('document_id', $document->getIid()); $content = $lp->display_document( $document, diff --git a/public/main/lp/learnpath.class.php b/public/main/lp/learnpath.class.php index 65926daedd..1396a0296e 100644 --- a/public/main/lp/learnpath.class.php +++ b/public/main/lp/learnpath.class.php @@ -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, diff --git a/public/main/lp/lp_controller.php b/public/main/lp/lp_controller.php index a974f2e9ee..6e68103051 100644 --- a/public/main/lp/lp_controller.php +++ b/public/main/lp/lp_controller.php @@ -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; } diff --git a/src/CourseBundle/Entity/CLpItem.php b/src/CourseBundle/Entity/CLpItem.php index 19b7263565..41ff56d7be 100644 --- a/src/CourseBundle/Entity/CLpItem.php +++ b/src/CourseBundle/Entity/CLpItem.php @@ -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