diff --git a/main/lp/learnpath.class.php b/main/lp/learnpath.class.php index 22394047c0..dcd452d042 100755 --- a/main/lp/learnpath.class.php +++ b/main/lp/learnpath.class.php @@ -3111,12 +3111,11 @@ class learnpath 'dir' ); } - /** * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display * @return string HTML TOC ready to display */ - public function get_html_toc($toc_list = null) + public function getListArrayToc($toc_list = null) { if ($this->debug > 0) { error_log('In learnpath::get_html_toc()', 0); @@ -3124,81 +3123,75 @@ class learnpath if (empty($toc_list)) { $toc_list = $this->get_toc(); } - $html = '
'; - $html .= '
'; - // Temporary variables. $mycurrentitemid = $this->get_current_item_id(); - $color_counter = 0; - $i = 0; - - foreach ($toc_list as $item) { - // Style Status - $class_name = [ - 'not attempted' => 'scorm_not_attempted', - 'incomplete' => 'scorm_not_attempted', - 'failed' => 'scorm_failed', - 'completed' => 'scorm_completed', - 'passed' => 'scorm_completed', - 'succeeded' => 'scorm_completed', - 'browsed' => 'scorm_completed', + $list = []; + $arrayList = []; + $classStatus = [ + 'not attempted' => 'scorm_not_attempted', + 'incomplete' => 'scorm_not_attempted', + 'failed' => 'scorm_failed', + 'completed' => 'scorm_completed', + 'passed' => 'scorm_completed', + 'succeeded' => 'scorm_completed', + 'browsed' => 'scorm_completed', ]; + foreach ($toc_list as $item) { - $rowColor = ' '; + $list['id'] = $item['id']; + $list['status'] = $item['status']; + $cssStatus = null; + + if (isset($classStatus[$item['status']])) { + $cssStatus = $classStatus[$item['status']]; + } + + $classStyle = ' '; $dirTypes = self::getChapterTypes(); if (in_array($item['type'], $dirTypes)) { - $rowColor ='scorm_item_section '; + $classStyle = 'scorm_item_section '; } if ($item['id'] == $this->current) { - $rowColor = 'scorm_item_normal '.$rowColor.' scorm_highlight'; + $classStyle = 'scorm_item_normal '.$classStyle.'scorm_highlight'; } elseif (!in_array($item['type'], $dirTypes)) { - $rowColor = 'scorm_item_normal '.$rowColor.' '; + $classStyle = 'scorm_item_normal '.$classStyle.' '; } - - $html .= '
'; - - // Learning path title $title = $item['title']; - if (empty ($title)) { + if (empty($title)) { $title = self::rl_get_resource_name(api_get_course_id(), $this->get_id(), $item['id']); } - $title = Security::remove_XSS($title); - - // Learning path personalization - // build the LP tree - // The anchor atoc_ will let us center the TOC on the currently viewed item &^D - $description = $item['description']; - if (empty($description)) { - $description = $title; - } - if (in_array($item['type'], $dirTypes)) { - // Chapters - $html .= '
'; + $title = Security::remove_XSS($item['title']); + + if (empty($item['description'])) { + $list['description'] = $title; } else { - $html .= '
'; - $html .= ''; + $list['description'] = $item['description']; } + + $list['class'] = $classStyle.' '.$cssStatus; + $list['level'] = $item['level']; + $list['type'] = $item['type']; if (in_array($item['type'], $dirTypes)) { - // Chapter - // if you want to put an image before, you should use css - $html .= stripslashes($title); + $list['css_level'] = 'level_'.$item['level']; } else { - $this->get_link('http', $item['id'], $toc_list); - $html .= '' . stripslashes($title) . ''; + $list['css_level'] = 'level_'.$item['level'] + .' scorm_type_' + .learnpath::format_scorm_type_item($item['type']); } - $html .= "
"; - if ($rowColor != '') { - $html .= '
'; + if (in_array($item['type'], $dirTypes)) { + $list['title'] = stripslashes($title); + } else { + $list['title'] = stripslashes($title); + $list['url'] = $this->get_link('http', $item['id'], $toc_list); + $list['current_id'] = $mycurrentitemid; } - - $color_counter++; + $arrayList[] = $list; } - $html .= "
"; - $html .= "
"; - return $html; + + return $arrayList; } /** diff --git a/main/lp/lp_view.php b/main/lp/lp_view.php index 901e1285a2..d29bda333f 100755 --- a/main/lp/lp_view.php +++ b/main/lp/lp_view.php @@ -540,10 +540,7 @@ $template->assign( $template->assign('lp_author', $_SESSION['oLP']->get_author()); $template->assign('lp_mode', $_SESSION['oLP']->mode); $template->assign('lp_title_scorm', $_SESSION['oLP']->name); -$template->assign( - 'lp_html_toc', - $_SESSION['oLP']->get_html_toc($get_toc_list) -); +$template->assign('data_list', $_SESSION['oLP']->getListArrayToc($get_toc_list)); $template->assign('lp_id', $_SESSION['oLP']->lp_id); $template->assign('lp_current_item_id', $_SESSION['oLP']->get_current_item_id()); diff --git a/main/template/default/learnpath/scorm_list.tpl b/main/template/default/learnpath/scorm_list.tpl new file mode 100644 index 0000000000..2e0bc046cd --- /dev/null +++ b/main/template/default/learnpath/scorm_list.tpl @@ -0,0 +1,26 @@ +{% if data_list is not empty %} +
+
+

{{ lp_title_scorm }}

+
+ {% for item in data_list %} +
+ {% if item.type == 'dir' %} +
+ {{ item.title }} +
+ {% else %} + + {% endif %} +
+ {% endfor %} +
+
+
+{% endif %} +{{ accorden_toc }} \ No newline at end of file diff --git a/main/template/default/learnpath/view.tpl b/main/template/default/learnpath/view.tpl index 63733b2a91..f92cfc70f0 100644 --- a/main/template/default/learnpath/view.tpl +++ b/main/template/default/learnpath/view.tpl @@ -65,11 +65,8 @@
{# TOC layout #}
-
-

{{ lp_title_scorm }}

- {{ lp_html_toc }} + {% include template ~ '/learnpath/scorm_list.tpl' %}
-
{# end TOC layout #}