From d9940dbfa6654e87a5349e390acbc9086d252291 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Thu, 7 Apr 2016 17:18:39 -0500 Subject: [PATCH 1/5] Temp - refs #11048 --- main/inc/lib/document.lib.php | 5 + .../final_item_template/template.html | 15 +++ main/newscorm/learnpath.class.php | 112 +++++++++++++++++- main/newscorm/lp_add_item.php | 10 +- main/newscorm/lp_controller.php | 29 +++++ 5 files changed, 162 insertions(+), 9 deletions(-) create mode 100644 main/newscorm/final_item_template/template.html diff --git a/main/inc/lib/document.lib.php b/main/inc/lib/document.lib.php index 0b4006e00b..392d25e1c6 100755 --- a/main/inc/lib/document.lib.php +++ b/main/inc/lib/document.lib.php @@ -6268,4 +6268,9 @@ class DocumentManager WHERE c_id = $courseId AND session_id = $sessionId AND tool = '".TOOL_DOCUMENT."'"; Database::query($sql); } + + public static function generateFinalItemDocument() + { + + } } diff --git a/main/newscorm/final_item_template/template.html b/main/newscorm/final_item_template/template.html new file mode 100644 index 0000000000..45d2bd56b6 --- /dev/null +++ b/main/newscorm/final_item_template/template.html @@ -0,0 +1,15 @@ + + + + TODO supply a title + + + + +
+ Congratulations! You have finished this learning path +
+ {{ certificate }} + {{ skills }} + + diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index a3338aad82..a3346c0ccc 100755 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -1946,7 +1946,7 @@ class learnpath error_log('New LP - In learnpath::get_last()', 0); } //This is just in case the lesson doesn't cointain a valid scheme, just to avoid "Notices" - if ($this->index > 0) { + if (count($this->ordered_items) > 0) { $this->index = count($this->ordered_items) - 1; return $this->ordered_items[$this->index]; } @@ -5613,7 +5613,11 @@ class learnpath if (file_exists('../img/lp_' . $icon_name . '.gif')) { $icon = Display::return_icon('lp_'.$icon_name.'.gif'); } else { - $icon = Display::return_icon('folder_document.gif'); + if ($arrLP[$i]['item_type'] === 'final_item') { + $icon = Display::return_icon('certificate.png'); + } else { + $icon = Display::return_icon('folder_document.gif'); + } } } @@ -6289,6 +6293,7 @@ class learnpath $res_step = Database::query($sql); $row_step = Database :: fetch_array($res_step); $return .= $this->display_manipulate($item_id, $row['item_type']); + var_dump($item_id, $row_step); $return .= $this->display_document_form('edit', $item_id, $row_step); break; case TOOL_LINK : @@ -6364,20 +6369,23 @@ class learnpath // Get al the forums. $forums = $this->get_forums(null, $course_code); + $finish = $this->getFinalItemForm(); + $headers = array( Display::return_icon('folder_document.png', get_lang('Documents'), array(), ICON_SIZE_BIG), Display::return_icon('quiz.png', get_lang('Quiz'), array(), ICON_SIZE_BIG), Display::return_icon('links.png', get_lang('Links'), array(), ICON_SIZE_BIG), Display::return_icon('works.png', get_lang('Works'), array(), ICON_SIZE_BIG), Display::return_icon('forum.png', get_lang('Forums'), array(), ICON_SIZE_BIG), - Display::return_icon('add_learnpath_section.png', get_lang('NewChapter'), array(), ICON_SIZE_BIG) + Display::return_icon('add_learnpath_section.png', get_lang('NewChapter'), array(), ICON_SIZE_BIG), + Display::return_icon('certificate.png', get_lang('Certificate'), [], ICON_SIZE_BIG), ); echo Display::display_normal_message(get_lang('ClickOnTheLearnerViewToSeeYourLearningPath')); $chapter = $_SESSION['oLP']->display_item_form('chapter', get_lang('EnterDataNewChapter'), 'add_item'); echo Display::tabs( $headers, - array($documents, $exercises, $links, $works, $forums, $chapter), 'resource_tab' + array($documents, $exercises, $links, $works, $forums, $chapter, $finish), 'resource_tab' ); return true; @@ -10691,6 +10699,102 @@ EOD; return $forumId; } + private function getFinalItem() + { + if (empty($this->items)) { + return null; + } + + foreach ($this->items as $item) { + if ($item->type !== 'final_item') { + continue; + } + + return $item; + } + } + + private function getFinalItemTemplate() + { + $finalItem = $this->getFinalItem(); + + if (!$finalItem) { + return file_get_contents(api_get_path(SYS_CODE_PATH) . 'newscorm/final_item_template/template.html'); + } + + $doc = DocumentManager::get_document_data_by_id($finalItem->path, $this->cc); + + return file_get_contents($doc['absolute_path']); + } + + /** + * + * @return html + */ + public function getFinalItemForm() + { + $finalItem = $this->getFinalItem(); + $title = ''; + $content = ''; + + if ($finalItem) { + $title = $finalItem->title; + $content = $this->getFinalItemTemplate(); + } + + $courseInfo = api_get_course_info(); + $result = $this->generate_lp_folder($courseInfo); + $relative_path = api_substr($result['dir'], 1, strlen($result['dir'])); + $relative_prefix = '../../'; + + $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 + ]; + + $url = api_get_self() . '?' . api_get_cidreq() . '&' . http_build_query([ + 'type' => 'document', + 'lp_id' => $this->lp_id + ]); + + $form = new FormValidator('final_item', 'POST', $url); + $form->addText('title', get_lang('Title')); + $form->addButtonSave(get_lang('LPCreateDocument')); + $renderer = $form->defaultRenderer(); + $renderer->setElementTemplate('
 {label}{element}
', 'content'); + $form->addHtmlEditor('content', null, null, true, $editorConfig, true); + $form->addHidden('action', 'add_final_item'); + $form->addHidden('previous', $this->get_last()); + + $form->setDefaults(['title' => $title, 'content' => $content]); + + if ($form->validate()) { + $values = $form->exportValues(); + + $lastItemId = $this->get_last(); + + if (!$finalItem) { + $documentId = $this->create_document($this->course_info, $values['content'], $values['title']); + $this->add_item( + 0, + $lastItemId, + 'final_item', + $documentId, + $values['title'], + '' + ); + } else { + $this->edit_document($this->course_info); + } + } + + return $form->returnForm(); + } } if (!function_exists('trim_value')) { diff --git a/main/newscorm/lp_add_item.php b/main/newscorm/lp_add_item.php index 052b8cf240..4f7ed6cf24 100755 --- a/main/newscorm/lp_add_item.php +++ b/main/newscorm/lp_add_item.php @@ -267,7 +267,7 @@ if (isset($new_item_id) && is_numeric($new_item_id)) { case 'module': echo $learnPath->display_item_form($type, get_lang('EnterDataNewModule')); break; - case 'document': + case TOOL_DOCUMENT: if (isset($_GET['file']) && is_numeric($_GET['file'])) { echo $learnPath->display_document_form('add', 0, $_GET['file']); } else { @@ -277,20 +277,20 @@ if (isset($new_item_id) && is_numeric($new_item_id)) { case 'hotpotatoes': echo $learnPath->display_hotpotatoes_form('add', 0, $_GET['file']); break; - case 'quiz': + case TOOL_QUIZ: echo Display::display_warning_message(get_lang('ExerciseCantBeEditedAfterAddingToTheLP')); echo $learnPath->display_quiz_form('add', 0, $_GET['file']); break; - case 'forum': + case TOOL_FORUM: echo $learnPath->display_forum_form('add', 0, $_GET['forum_id']); break; case 'thread': echo $learnPath->display_thread_form('add', 0, $_GET['thread_id']); break; - case 'link': + case TOOL_LINK: echo $learnPath->display_link_form('add', 0, $_GET['file']); break; - case 'student_publication': + case TOOL_STUDENTPUBLICATION: $extra = isset($_GET['file']) ? $_GET['file'] : null; echo $learnPath->display_student_publication_form('add', 0, $extra); break; diff --git a/main/newscorm/lp_controller.php b/main/newscorm/lp_controller.php index 220e9f7e9d..a9325249f2 100755 --- a/main/newscorm/lp_controller.php +++ b/main/newscorm/lp_controller.php @@ -364,6 +364,8 @@ if (isset($_POST['title'])) { } } +$redirectTo = null; + switch ($action) { case 'add_item': if (!$is_allowed_to_edit) { @@ -1385,6 +1387,29 @@ switch ($action) { 'lp_id' => $_SESSION['oLP']->lp_id ])); break; + case 'add_final_item': + var_dump($_POST, $_GET, $lp_found); + if (!$lp_found) { + Display::addFlash( + Display::return_message(get_lang('NoLPFound'), 'error') + ); + break; + } + + $_SESSION['refresh'] = 1; + + if (!isset($_POST['submit']) || empty($post_title)) { + break; + } + + $_SESSION['oLP']->getFinalItemForm(); + + $redirectTo = api_get_self() . '?' . http_build_query([ + 'action' => 'add_item', + 'type' => 'step', + 'lp_id' => intval($_SESSION['oLP']->lp_id) + ]); + break; default: if ($debug > 0) error_log('New LP - default action triggered', 0); require 'lp_list.php'; @@ -1395,3 +1420,7 @@ if (!empty($_SESSION['oLP'])) { $_SESSION['lpobject'] = serialize($_SESSION['oLP']); if ($debug > 0) error_log('New LP - lpobject is serialized in session', 0); } + +if (!empty($redirectTo)) { + header("Location: $redirectTo"); +} From 36635d142199d3c8e6a5adbfd1b531dbbe85d318 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 12 Apr 2016 16:14:25 -0500 Subject: [PATCH 2/5] Fix URL for create forum in lp --- main/newscorm/learnpath.class.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index a3346c0ccc..5a46033536 100755 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -8823,7 +8823,15 @@ class learnpath //First add link $return .= '
  • '; $return .= Display::return_icon('forum_new_small.gif'); - $return .= '' . get_lang('CreateANewForum') . ''; + $return .= Display::url( + get_lang('CreateANewForum'), + api_get_path(WEB_CODE_PATH) . 'forum/index.php?' . api_get_cidreq() . '&' . http_build_query([ + 'action' => 'add', + 'content' => 'forum', + 'lp_id' => $this->lp_id + ]), + ['title' => get_lang('CreateANewForum')] + ); $return .= '
  • '; $return .= '