Improving speed loading LP see BT#4701

skala
Julio Montoya 13 years ago
parent 1cca977ecc
commit ab8e11974c
  1. 35
      main/newscorm/learnpath.class.php
  2. 37
      main/newscorm/lp_view.php

@ -1497,7 +1497,7 @@ class learnpath {
error_log('New LP - In learnpath::get_total_items_count_without_chapters()', 0); error_log('New LP - In learnpath::get_total_items_count_without_chapters()', 0);
} }
$total = 0; $total = 0;
foreach ($this->items as $temp => $temp2) { foreach ($this->items as $temp2) {
if (!in_array($temp2->get_type(), array ( if (!in_array($temp2->get_type(), array (
'dokeos_chapter', 'dokeos_chapter',
'chapter', 'chapter',
@ -1536,6 +1536,7 @@ class learnpath {
!empty($this->items[$this->last_item_seen]) && !empty($this->items[$this->last_item_seen]) &&
$this->items[$this->last_item_seen]->get_type() != 'dir' && $this->items[$this->last_item_seen]->get_type() != 'dir' &&
$this->items[$this->last_item_seen]->get_type() != 'dokeos_chapter' $this->items[$this->last_item_seen]->get_type() != 'dokeos_chapter'
//with this change (below) the LP will NOT go to the next item, it will take lp item we left
//&& !$this->items[$this->last_item_seen]->is_done() //&& !$this->items[$this->last_item_seen]->is_done()
) { ) {
@ -2693,7 +2694,7 @@ class learnpath {
* Uses the table generated by get_toc() and returns an HTML-formatted string ready to display * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display
* @return string HTML TOC ready to display * @return string HTML TOC ready to display
*/ */
public function get_html_toc() { public function get_html_toc($toc_list = null) {
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$course_code = api_get_course_id(); $course_code = api_get_course_id();
$is_allowed_to_edit = api_is_allowed_to_edit(null, true); $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
@ -2704,7 +2705,9 @@ class learnpath {
if ($this->debug > 0) { if ($this->debug > 0) {
error_log('New LP - In learnpath::get_html_toc()', 0); error_log('New LP - In learnpath::get_html_toc()', 0);
} }
$list = $this->get_toc(); if (empty($toc_list)) {
$toc_list = $this->get_toc();
}
//echo $this->current; //echo $this->current;
//$parent = $this->items[$this->current]->get_parent(); //$parent = $this->items[$this->current]->get_parent();
//if (empty($parent)) { $parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()]; } //if (empty($parent)) { $parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()]; }
@ -2741,7 +2744,7 @@ class learnpath {
$color_counter = 0; $color_counter = 0;
$i = 0; $i = 0;
foreach ($list as $item) { foreach ($toc_list as $item) {
if ($this->debug > 2) { if ($this->debug > 2) {
//error_log('New LP - learnpath::get_html_toc(): using item ' . $item['id'], 0); //error_log('New LP - learnpath::get_html_toc(): using item ' . $item['id'], 0);
} }
@ -2795,7 +2798,7 @@ class learnpath {
$title = Security::remove_XSS($title); $title = Security::remove_XSS($title);
if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dir' && $item['type'] != 'dokeos_module') { if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dir' && $item['type'] != 'dokeos_module') {
//$html .= "<a href='lp_controller.php?".api_get_cidreq()."&action=content&lp_id=".$this->get_id()."&item_id=".$item['id']."' target='lp_content_frame_name'>".$title."</a>" ; //$html .= "<a href='lp_controller.php?".api_get_cidreq()."&action=content&lp_id=".$this->get_id()."&item_id=".$item['id']."' target='lp_content_frame_name'>".$title."</a>" ;
$url = $this->get_link('http', $item['id'], $list); $url = $this->get_link('http', $item['id'], $toc_list);
//$html .= '<a href="'.$url.'" target="content_name" onClick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ; //$html .= '<a href="'.$url.'" target="content_name" onClick="top.load_item('.$item['id'].',\''.$url.'\');">'.$title.'</a>' ;
//$html .= '<a href="" onClick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ; //$html .= '<a href="" onClick="top.load_item('.$item['id'].',\''.$url.'\');return false;">'.$title.'</a>' ;
@ -2902,7 +2905,7 @@ class learnpath {
$item_id = $this->get_current_item_id(); $item_id = $this->get_current_item_id();
} }
if (empty ($item_id)) { if (empty($item_id)) {
if ($this->debug > 2) { if ($this->debug > 2) {
error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object', 0); error_log('New LP - In learnpath::get_link() - no current item id found in learnpath object', 0);
} }
@ -2955,7 +2958,12 @@ class learnpath {
if (in_array($lp_item_type, array('quiz', 'document', 'link', 'forum', 'thread', 'student_publication'))) { if (in_array($lp_item_type, array('quiz', 'document', 'link', 'forum', 'thread', 'student_publication'))) {
$lp_type = 1; $lp_type = 1;
} }
if ($this->debug > 2) {
error_log('New LP - In learnpath::get_link() - $lp_type ' . $lp_type, 0);
error_log('New LP - In learnpath::get_link() - $lp_item_type ' . $lp_item_type, 0);
}
// Now go through the specific cases to get the end of the path. // Now go through the specific cases to get the end of the path.
// @todo Use constants instead of int values. // @todo Use constants instead of int values.
@ -2965,8 +2973,9 @@ class learnpath {
$file = 'lp_content.php?type=dir'; $file = 'lp_content.php?type=dir';
} else { } else {
require_once 'resourcelinker.inc.php'; require_once 'resourcelinker.inc.php';
$file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
$file = rl_get_resource_link_for_learnpath(api_get_course_id(), $this->get_id(), $item_id);
if ($this->debug > 0) { if ($this->debug > 0) {
error_log('rl_get_resource_link_for_learnpath - file: ' . $file, 0); error_log('rl_get_resource_link_for_learnpath - file: ' . $file, 0);
} }
@ -2983,9 +2992,15 @@ class learnpath {
$lp_view_id = $this->get_view_id(); $lp_view_id = $this->get_view_id();
$prevent_reinit = $this->items[$this->current]->get_prevent_reinit(); $prevent_reinit = $this->items[$this->current]->get_prevent_reinit();
if (empty($provided_toc)) { if (empty($provided_toc)) {
if ($this->debug > 0) {
error_log('In learnpath::get_link() Loading get_toc ', 0);
}
$list = $this->get_toc(); $list = $this->get_toc();
} else { } else {
if ($this->debug > 0) {
error_log('In learnpath::get_link() Loading get_toc from "cache" ', 0);
}
$list = $provided_toc; $list = $provided_toc;
} }

@ -121,16 +121,30 @@ $htmlHeadXtra[] = '<script type="text/javascript" src="js/storageapi.js"></scrip
* Get a link to the corresponding document. * Get a link to the corresponding document.
*/ */
if ($debug) {
error_log(" src: $src ");
error_log(" lp_type: $lp_type ");
}
$get_toc_list = $_SESSION['oLP']->get_toc();
$type_quiz = false;
foreach ($get_toc_list as $toc) {
if ($toc['id'] == $lp_item_id && ($toc['type']=='quiz')) {
$type_quiz = true;
}
}
if (!isset($src)) { if (!isset($src)) {
$src = ''; $src = '';
switch ($lp_type) { switch ($lp_type) {
case 1: case 1:
$_SESSION['oLP']->stop_previous_item(); $_SESSION['oLP']->stop_previous_item();
$htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript" language="javascript"></script>'; $htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript" language="javascript"></script>';
$prereq_check = $_SESSION['oLP']->prerequisites_match($lp_item_id); $prereq_check = $_SESSION['oLP']->prerequisites_match($lp_item_id);
if ($prereq_check === true) { if ($prereq_check === true) {
$src = $_SESSION['oLP']->get_link('http', $lp_item_id); $src = $_SESSION['oLP']->get_link('http', $lp_item_id, $get_toc_list);
//Prevents FF 3.6 + Adobe Reader 9 bug see BT#794 when calling a pdf file in a LP. //Prevents FF 3.6 + Adobe Reader 9 bug see BT#794 when calling a pdf file in a LP.
$file_info = parse_url($src); $file_info = parse_url($src);
@ -150,7 +164,7 @@ if (!isset($src)) {
$htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript" language="javascript"></script>'; $htmlHeadXtra[] = '<script src="scorm_api.php" type="text/javascript" language="javascript"></script>';
$prereq_check = $_SESSION['oLP']->prerequisites_match($lp_item_id); $prereq_check = $_SESSION['oLP']->prerequisites_match($lp_item_id);
if ($prereq_check === true) { if ($prereq_check === true) {
$src = $_SESSION['oLP']->get_link('http',$lp_item_id); $src = $_SESSION['oLP']->get_link('http',$lp_item_id, $get_toc_list);
$_SESSION['oLP']->start_current_item(); // starts time counter manually if asset $_SESSION['oLP']->start_current_item(); // starts time counter manually if asset
} else { } else {
$src = 'blank.php?error=prerequisites'; $src = 'blank.php?error=prerequisites';
@ -162,7 +176,7 @@ if (!isset($src)) {
$htmlHeadXtra[] = '<script src="'.$_SESSION['oLP']->get_js_lib().'" type="text/javascript" language="javascript"></script>'; $htmlHeadXtra[] = '<script src="'.$_SESSION['oLP']->get_js_lib().'" type="text/javascript" language="javascript"></script>';
$prereq_check = $_SESSION['oLP']->prerequisites_match($lp_item_id); $prereq_check = $_SESSION['oLP']->prerequisites_match($lp_item_id);
if ($prereq_check === true) { if ($prereq_check === true) {
$src = $_SESSION['oLP']->get_link('http',$lp_item_id); $src = $_SESSION['oLP']->get_link('http',$lp_item_id, $get_toc_list);
$_SESSION['oLP']->start_current_item(); // starts time counter manually if asset $_SESSION['oLP']->start_current_item(); // starts time counter manually if asset
} else { } else {
$src = 'blank.php'; $src = 'blank.php';
@ -173,23 +187,14 @@ if (!isset($src)) {
} }
} }
$list = $_SESSION['oLP']->get_toc();
$type_quiz = false;
foreach($list as $toc) {
if ($toc['id'] == $lp_item_id && ($toc['type']=='quiz')) {
$type_quiz = true;
}
}
$autostart = 'true'; $autostart = 'true';
// Update status, total_time from lp_item_view table when you finish the exercises in learning path. // Update status, total_time from lp_item_view table when you finish the exercises in learning path.
if ($debug) { if ($debug) {
error_log('$type_quiz: '.$type_quiz); error_log('$type_quiz: '.$type_quiz);
error_log('$_REQUEST[exeId]: '.$_REQUEST['exeId']); error_log('$_REQUEST[exeId]: '.intval($_REQUEST['exeId']));
error_log('$lp_id: '.$lp_id); error_log('$lp_id: '.$lp_id);
error_log('$_GET[lp_item_id]: '.$_GET['lp_item_id']); error_log('$_GET[lp_item_id]: '.intval($_GET['lp_item_id']));
} }
if ($type_quiz && !empty($_REQUEST['exeId']) && isset($lp_id) && isset($_GET['lp_item_id'])) { if ($type_quiz && !empty($_REQUEST['exeId']) && isset($lp_id) && isset($_GET['lp_item_id'])) {
@ -374,7 +379,7 @@ if (Database::num_rows($res_media) > 0) {
<!-- TOC layout --> <!-- TOC layout -->
<div id="toc_id" name="toc_name" style="overflow: auto; padding:0;margin-top:0px;width:100%;float:left"> <div id="toc_id" name="toc_name" style="overflow: auto; padding:0;margin-top:0px;width:100%;float:left">
<div id="learning_path_toc"> <div id="learning_path_toc">
<?php echo $_SESSION['oLP']->get_html_toc(); ?> <?php echo $_SESSION['oLP']->get_html_toc($get_toc_list); ?>
<?php if (!empty($_SESSION['oLP']->scorm_debug)) { //only show log ?> <?php if (!empty($_SESSION['oLP']->scorm_debug)) { //only show log ?>
<!-- log message layout --> <!-- log message layout -->

Loading…
Cancel
Save