Fixing tool LP link when copying a LP see BT#7688

1.9.x
Julio Montoya 11 years ago
parent cfd5fc6bdd
commit cac3061054
  1. 79
      main/inc/lib/course_home.lib.php
  2. 9
      main/inc/lib/plugin.lib.php
  3. 82
      main/newscorm/learnpath.class.php
  4. 4
      main/newscorm/lp_controller.php

@ -105,13 +105,10 @@ class CourseHome
foreach ($all_tools as & $tool) { foreach ($all_tools as & $tool) {
if ($tool['image'] == 'scormbuilder.gif') { if ($tool['image'] == 'scormbuilder.gif') {
// display links to lp only for current session
/* if (api_get_session_id() != $tool['session_id']) {
continue;
} */
// check if the published learnpath is visible for student // check if the published learnpath is visible for student
$published_lp_id = self::get_published_lp_id_from_link($tool['link']); $published_lp_id = self::get_published_lp_id_from_link($tool['link']);
if (!api_is_allowed_to_edit(null, true) && !learnpath::is_lp_visible_for_student($published_lp_id, api_get_user_id())) { if (!api_is_allowed_to_edit(null, true) &&
!learnpath::is_lp_visible_for_student($published_lp_id, api_get_user_id(), api_get_course_id(), api_get_session_id())) {
continue; continue;
} }
} }
@ -293,7 +290,8 @@ class CourseHome
// check if the published learnpath is visible for student // check if the published learnpath is visible for student
$published_lp_id = self::get_published_lp_id_from_link($tool['link']); $published_lp_id = self::get_published_lp_id_from_link($tool['link']);
if (!api_is_allowed_to_edit(null, true) && !learnpath::is_lp_visible_for_student($published_lp_id, api_get_user_id())) { if (!api_is_allowed_to_edit(null, true) &&
!learnpath::is_lp_visible_for_student($published_lp_id, api_get_user_id(), api_get_course_id(), api_get_session_id())) {
continue; continue;
} }
} }
@ -460,7 +458,7 @@ class CourseHome
$check = false; $check = false;
foreach ($list as $line) { foreach ($list as $line) {
//Admin can see all tools even if the course_hide_tools configuration is set // Admin can see all tools even if the course_hide_tools configuration is set
if ($is_platform_admin) { if ($is_platform_admin) {
continue; continue;
} }
@ -471,21 +469,39 @@ class CourseHome
} }
while ($temp_row = Database::fetch_assoc($result)) { while ($temp_row = Database::fetch_assoc($result)) {
$add = false;
if ($check) { if ($check) {
if (!in_array($temp_row['name'], $hide_list)) { if (!in_array($temp_row['name'], $hide_list)) {
$all_tools_list[] = $temp_row; $add = true;
} }
} else { } else {
$add = true;
}
if ($temp_row['image'] == 'scormbuilder.gif') {
$lp_id = self::get_published_lp_id_from_link($temp_row['link']);
$lp = new learnpath(api_get_course_id(), $lp_id, api_get_user_id());
$path = $lp->get_preview_image_path(64);
$add = $lp->is_lp_visible_for_student(
$lp_id,
api_get_user_id(),
api_get_course_id(),
api_get_session_id()
);
if ($path) {
$temp_row['custom_image'] = $path;
}
}
if ($add) {
$all_tools_list[] = $temp_row; $all_tools_list[] = $temp_row;
} }
} }
$i = 0;
// Grabbing all the links that have the property on_homepage set to 1 // Grabbing all the links that have the property on_homepage set to 1
$course_link_table = Database::get_course_table(TABLE_LINK); $course_link_table = Database::get_course_table(TABLE_LINK);
$course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY); $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY);
switch ($course_tool_category) { switch ($course_tool_category) {
case TOOL_AUTHORING: case TOOL_AUTHORING:
$sql_links = "SELECT tl.*, tip.visibility $sql_links = "SELECT tl.*, tip.visibility
@ -622,16 +638,13 @@ class CourseHome
$tool['original_link'] = $tool['link']; $tool['original_link'] = $tool['link'];
if ($tool['image'] == 'scormbuilder.gif') { if ($tool['image'] == 'scormbuilder.gif') {
// display links to lp only for current session
/* if ($session_id != $tool['session_id']) {
continue;
} */
// check if the published learnpath is visible for student // check if the published learnpath is visible for student
$published_lp_id = self::get_published_lp_id_from_link($tool['link']); $published_lp_id = self::get_published_lp_id_from_link($tool['link']);
if (api_is_allowed_to_edit(null, true)) { if (api_is_allowed_to_edit(null, true)) {
$studentview = true; $studentview = true;
} }
if (!api_is_allowed_to_edit(null, true) && !learnpath::is_lp_visible_for_student($published_lp_id, api_get_user_id())) { if (!api_is_allowed_to_edit(null, true) &&
!learnpath::is_lp_visible_for_student($published_lp_id, api_get_user_id(), api_get_course_id(), api_get_session_id())) {
continue; continue;
} }
} }
@ -741,7 +754,7 @@ class CourseHome
// Creating title and the link // Creating title and the link
if (isset($tool['category']) && $tool['category'] == 'plugin') { if (isset($tool['category']) && $tool['category'] == 'plugin') {
$plugin_info = $app_plugin->getPluginInfo($tool['name']); $plugin_info = $app_plugin->get_plugin_info($tool['name']);
if (isset($plugin_info) && isset($plugin_info['title'])) { if (isset($plugin_info) && isset($plugin_info['title'])) {
$tool_name = $plugin_info['title']; $tool_name = $plugin_info['title'];
} }
@ -770,7 +783,6 @@ class CourseHome
} }
$i = 0; $i = 0;
$html = ''; $html = '';
if (!empty($items)) { if (!empty($items)) {
@ -781,28 +793,27 @@ class CourseHome
$html .= '<div class="span4 course-tool">'; $html .= '<div class="span4 course-tool">';
$image = (substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.'))).'.png'; $image = (substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.'))).'.png';
$original_image = Display::return_icon($image, $item['name'], array('id' => 'toolimage_'.$item['tool']['id']), ICON_SIZE_BIG, false); if (isset($item['tool']['custom_image'])) {
$original_image = Display::img(
switch ($image) { $item['tool']['custom_image'],
case 'scormbuilder.png': $item['name'],
$image = $original_image; array('id' => 'toolimage_'.$item['tool']['id'])
$lp_id = self::get_published_lp_id_from_link($item['link']); );
if ($lp_id) { } else {
$lp = new learnpath(api_get_course_id(), $lp_id, api_get_user_id()); $original_image = Display::return_icon(
$path = $lp->get_preview_image_path(64); $image,
if ($path) { $item['name'],
$image = '<img src="'.$path.'">'; array('id' => 'toolimage_'.$item['tool']['id']),
} ICON_SIZE_BIG,
} false
break; );
default:
$image = $original_image;
} }
$data .= Display::url($image, $item['url_params']['href'], $item['url_params']); $data .= Display::url($original_image, $item['url_params']['href'], $item['url_params']);
$html .= Display::div($data, array('class' => 'big_icon')); //box-image reflection $html .= Display::div($data, array('class' => 'big_icon')); //box-image reflection
$html .= Display::div('<h4>'.$item['visibility'].$item['extra'].$item['link'].'</h4>', array('class' => 'content')); $html .= Display::div('<h4>'.$item['visibility'].$item['extra'].$item['link'].'</h4>', array('class' => 'content'));
$html .= '</div>'; $html .= '</div>';
break; break;
case 'activity': case 'activity':
$html .= '<div class="offset2 span4 course-tool">'; $html .= '<div class="offset2 span4 course-tool">';

@ -366,6 +366,15 @@ class AppPlugin
return true; return true;
} }
/**
* @param $plugin_name
* @param bool $forced
* @deprecated
*/
public function get_plugin_info($plugin_name, $forced = false) {
return $this->getPluginInfo($plugin_name, $forced);
}
/** /**
* Loads plugin info * Loads plugin info
* @staticvar array $plugin_data * @staticvar array $plugin_data

@ -919,27 +919,28 @@ class learnpath
} }
$lp = Database :: get_course_table(TABLE_LP_MAIN); $lp = Database :: get_course_table(TABLE_LP_MAIN);
$lp_item = Database :: get_course_table(TABLE_LP_ITEM); // Proposed by Christophe (clefevre), see below. $lp_item = Database :: get_course_table(TABLE_LP_ITEM);
$lp_view = Database :: get_course_table(TABLE_LP_VIEW); $lp_view = Database :: get_course_table(TABLE_LP_VIEW);
$lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW); $lp_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
//if ($this->debug > 0) { error_log('New LP - In learnpath::delete()', 0); } //if ($this->debug > 0) { error_log('New LP - In learnpath::delete()', 0); }
// Delete lp item id. // Delete lp item id.
foreach ($this->items as $id => $dummy) { foreach ($this->items as $id => $dummy) {
//$this->items[$id]->delete(); //$this->items[$id]->delete();
$sql_del_view = "DELETE FROM $lp_item_view WHERE c_id = $course_id AND lp_item_id = '" . $id . "'"; $sql = "DELETE FROM $lp_item_view WHERE c_id = $course_id AND lp_item_id = '" . $id . "'";
$res_del_item_view = Database::query($sql_del_view); Database::query($sql);
} }
// Proposed by Christophe (nickname: clefevre), see http://www.dokeos.com/forum/viewtopic.php?t=29673 // Proposed by Christophe (nickname: clefevre)
$sql_del_item = "DELETE FROM $lp_item WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id; $sql = "DELETE FROM $lp_item WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
$res_del_item = Database::query($sql_del_item); Database::query($sql);
$sql_del_view = "DELETE FROM $lp_view WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id; $sql = "DELETE FROM $lp_view WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
//if ($this->debug > 2) { error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view, 0); } //if ($this->debug > 2) { error_log('New LP - Deleting views bound to lp '.$this->lp_id.': '.$sql_del_view, 0); }
$res_del_view = Database::query($sql_del_view); Database::query($sql);
self::toggle_publish($this->lp_id, 'i'); self::toggle_publish($this->lp_id, 'i');
//if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type, 0); } //if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.' of type '.$this->type, 0); }
if ($this->type == 2 || $this->type == 3) { if ($this->type == 2 || $this->type == 3) {
// This is a scorm learning path, delete the files as well. // This is a scorm learning path, delete the files as well.
@ -972,11 +973,25 @@ class learnpath
} }
} }
} }
$sql_del_lp = "DELETE FROM $lp WHERE c_id = ".$course_id." AND id = " . $this->lp_id;
$tbl_tool = Database :: get_course_table(TABLE_TOOL_LIST);
$link = 'newscorm/lp_controller.php?action=view&lp_id='.$this->lp_id;
// Delete tools
$sql = "DELETE FROM $tbl_tool WHERE c_id = ".$course_id." AND (link LIKE '$link%' AND image='scormbuilder.gif')";
Database::query($sql);
$sql = "DELETE FROM $lp WHERE c_id = ".$course_id." AND id = " . $this->lp_id;
//if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp, 0); } //if ($this->debug > 2) { error_log('New LP - Deleting lp '.$this->lp_id.': '.$sql_del_lp, 0); }
Database::query($sql_del_lp); Database::query($sql);
$this->update_display_order(); // Updates the display order of all lps. $this->update_display_order(); // Updates the display order of all lps.
api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $this->lp_id, 'delete', api_get_user_id());
api_item_property_update(
api_get_course_info(),
TOOL_LEARNPATH,
$this->lp_id,
'delete',
api_get_user_id()
);
require_once '../gradebook/lib/be.inc.php'; require_once '../gradebook/lib/be.inc.php';
@ -2152,27 +2167,48 @@ class learnpath
/** /**
* This function checks if the learnpath is visible for student after the progress of its prerequisite is completed, and considering time availability * Checks if the learning path is visible for student after the progress
* of its prerequisite is completed, considering the time availability and
* the LP visibility.
* @param int Learnpath id * @param int Learnpath id
* @param int Student id * @param int Student id
* @param string Course code (optional) * @param string Course code (optional)
* @return bool True if * @param int $sessionId
* @return bool
*/ */
public static function is_lp_visible_for_student($lp_id, $student_id, $courseCode = null) { public static function is_lp_visible_for_student(
$lp_id,
$student_id,
$courseCode = null,
$sessionId = null
) {
$lp_id = (int)$lp_id; $lp_id = (int)$lp_id;
$course = api_get_course_info($courseCode); $course = api_get_course_info($courseCode);
$sessionId = intval($sessionId);
if (empty($sessionId)) {
$sessionId = api_get_session_id();
}
$tbl_learnpath = Database::get_course_table(TABLE_LP_MAIN); $tbl_learnpath = Database::get_course_table(TABLE_LP_MAIN);
// Get current prerequisite // Get current prerequisite
$sql = "SELECT id, prerequisite, publicated_on, expired_on $sql = "SELECT id, prerequisite, publicated_on, expired_on
FROM $tbl_learnpath FROM $tbl_learnpath
WHERE c_id = ".$course['real_id']." AND id = $lp_id"; WHERE c_id = ".$course['real_id']." AND id = $lp_id";
$itemInfo = api_get_item_property_info($course['real_id'], TOOL_LEARNPATH, $lp_id, $sessionId);
// If the item was deleted.
if ($itemInfo['visibility'] == 2) {
return false;
}
$rs = Database::query($sql); $rs = Database::query($sql);
$now = time(); $now = time();
if (Database::num_rows($rs)>0) { if (Database::num_rows($rs)>0) {
$row = Database::fetch_array($rs, 'ASSOC'); $row = Database::fetch_array($rs, 'ASSOC');
$prerequisite = $row['prerequisite']; $prerequisite = $row['prerequisite'];
$is_visible = true; $is_visible = true;
$progress = 0;
if (!empty($prerequisite)) { if (!empty($prerequisite)) {
$progress = self::get_db_progress( $progress = self::get_db_progress(
@ -2181,7 +2217,7 @@ class learnpath
'%', '%',
$courseCode, $courseCode,
false, false,
api_get_session_id() $sessionId
); );
$progress = intval($progress); $progress = intval($progress);
if ($progress < 100) { if ($progress < 100) {
@ -2200,7 +2236,7 @@ class learnpath
} }
} }
//Blocking empty start times see BT#2800 // Blocking empty start times see BT#2800
global $_custom; global $_custom;
if (isset($_custom['lps_hidden_when_no_start_date']) && $_custom['lps_hidden_when_no_start_date']) { if (isset($_custom['lps_hidden_when_no_start_date']) && $_custom['lps_hidden_when_no_start_date']) {
if (empty($row['publicated_on']) || $row['publicated_on'] == '0000-00-00 00:00:00') { if (empty($row['publicated_on']) || $row['publicated_on'] == '0000-00-00 00:00:00') {
@ -2218,8 +2254,10 @@ class learnpath
} }
return $is_visible; return $is_visible;
} }
return false; return false;
} }
/** /**
* Gets a progress bar for the learnpath by counting the number of items in it and the number of items * Gets a progress bar for the learnpath by counting the number of items in it and the number of items
* completed so far. * completed so far.
@ -3809,7 +3847,13 @@ class learnpath
if ($set_visibility != 1) { if ($set_visibility != 1) {
$action = 'invisible'; $action = 'invisible';
} }
return api_item_property_update(api_get_course_info(), TOOL_LEARNPATH, $lp_id, $action, api_get_user_id()); return api_item_property_update(
api_get_course_info(),
TOOL_LEARNPATH,
$lp_id,
$action,
api_get_user_id()
);
} }
/** /**

@ -727,7 +727,7 @@ switch ($action) {
$_SESSION['refresh'] = 1; $_SESSION['refresh'] = 1;
// Remove lp from homepage if it is there. // Remove lp from homepage if it is there.
//$_SESSION['oLP']->toggle_visibility((int)$_GET['lp_id'],'i'); //$_SESSION['oLP']->toggle_visibility((int)$_GET['lp_id'],'i');
$_SESSION['oLP']->delete(null,(int)$_GET['lp_id'],'remove'); $_SESSION['oLP']->delete(null, $_GET['lp_id'], 'remove');
Session::erase('oLP'); Session::erase('oLP');
require 'lp_list.php'; require 'lp_list.php';
} }
@ -752,7 +752,7 @@ switch ($action) {
if ($debug > 0) error_log('New LP - publish action triggered', 0); if ($debug > 0) error_log('New LP - publish action triggered', 0);
if (!$lp_found) { error_log('New LP - No learnpath given for publish', 0); require 'lp_list.php'; } if (!$lp_found) { error_log('New LP - No learnpath given for publish', 0); require 'lp_list.php'; }
else { else {
learnpath::toggle_publish($_REQUEST['lp_id'],$_REQUEST['new_status']); learnpath::toggle_publish($_REQUEST['lp_id'], $_REQUEST['new_status']);
require 'lp_list.php'; require 'lp_list.php';
} }
break; break;

Loading…
Cancel
Save