Minor - format code.

1.9.x
Julio Montoya 12 years ago
parent cfac0250b8
commit dd2dbe8432
  1. 72
      main/newscorm/learnpathList.class.php
  2. 27
      main/newscorm/lp_list.php

@ -13,7 +13,8 @@
* @uses Database.lib.php to use the database
* @uses learnpath.class.php to generate learnpath objects to get in the list
*/
class learnpathList {
class learnpathList
{
public $list = array(); // Holds a flat list of learnpaths data from the database.
public $ref_list = array(); // Holds a list of references to the learnpaths objects (only filled by get_refs()).
public $alpha_list = array(); // Holds a flat list of learnpaths sorted by alphabetical name order.
@ -30,16 +31,17 @@ class learnpathList {
* @param int Optional session id (otherwise we use api_get_session_id())
* @return void
*/
function __construct($user_id, $course_code = '', $session_id = null, $order_by = null, $check_publication_dates = false) {
function __construct($user_id, $course_code = '', $session_id = null, $order_by = null, $check_publication_dates = false)
{
$course_info = api_get_course_info($course_code);
$lp_table = Database::get_course_table(TABLE_LP_MAIN);
$tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
$this->course_code = $course_code;
$this->course_code = $course_code;
$this->user_id = $user_id;
$course_id = $course_info['real_id'];
if (empty($course_id)) {
return false;
}
@ -50,68 +52,81 @@ class learnpathList {
} else {
$session_id = api_get_session_id();
}
$condition_session = api_get_session_condition($session_id, true, true);
$order = "ORDER BY display_order ASC, name ASC";
if (isset($order_by)) {
$order = Database::parse_conditions(array('order'=>$order_by));
$order = Database::parse_conditions(array('order'=>$order_by));
}
$now = api_get_utc_datetime();
$time_conditions = '';
if ($check_publication_dates) {
$time_conditions = " AND ( (publicated_on <> '0000-00-00 00:00:00' AND publicated_on < '$now' AND expired_on <> '0000-00-00 00:00:00' AND expired_on > '$now' ) OR
(publicated_on <> '0000-00-00 00:00:00' AND publicated_on < '$now' AND expired_on = '0000-00-00 00:00:00') OR
(publicated_on = '0000-00-00 00:00:00' AND expired_on <> '0000-00-00 00:00:00' AND expired_on > '$now') OR
(publicated_on = '0000-00-00 00:00:00' AND expired_on = '0000-00-00 00:00:00' ))
$time_conditions = " AND (
(publicated_on <> '0000-00-00 00:00:00' AND publicated_on < '$now' AND expired_on <> '0000-00-00 00:00:00' AND expired_on > '$now' ) OR
(publicated_on <> '0000-00-00 00:00:00' AND publicated_on < '$now' AND expired_on = '0000-00-00 00:00:00') OR
(publicated_on = '0000-00-00 00:00:00' AND expired_on <> '0000-00-00 00:00:00' AND expired_on > '$now') OR
(publicated_on = '0000-00-00 00:00:00' AND expired_on = '0000-00-00 00:00:00' ))
";
}
$sql = "SELECT * FROM $lp_table WHERE c_id = $course_id $time_conditions $condition_session $order";
$sql = "SELECT * FROM $lp_table
WHERE c_id = $course_id $time_conditions $condition_session $order";
$res = Database::query($sql);
$names = array();
while ($row = Database::fetch_array($res,'ASSOC')) {
// Check if published.
$pub = '';
// Use domesticate here instead of Database::escape_string because
// it prevents ' to be slashed and the input (done by learnpath.class.php::toggle_visibility())
// is done using domesticate()
$myname = domesticate($row['name']);
$mylink = 'newscorm/lp_controller.php?action=view&lp_id='.$row['id'].'&id_session='.$session_id;
$sql2="SELECT * FROM $tbl_tool WHERE c_id = $course_id AND (name='$myname' and image='scormbuilder.gif' and link LIKE '$mylink%')";
//error_log('New LP - learnpathList::__construct - getting visibility - '.$sql2, 0);
$sql2 = "SELECT * FROM $tbl_tool
WHERE
c_id = $course_id AND (
name='$myname' AND
image='scormbuilder.gif' AND
link LIKE '$mylink%'
)";
$res2 = Database::query($sql2);
if (Database::num_rows($res2) > 0) {
$row2 = Database::fetch_array($res2);
$pub = $row2['visibility'];
} else {
$pub = 'i';
}
// Check if visible.
$vis = api_get_item_visibility(api_get_course_info($course_code), 'learnpath', $row['id'], $session_id);
if (!empty($row['created_on']) && $row['created_on'] != '0000-00-00 00:00:00') {
$row['created_on'] = $row['created_on'];
} else {
$row['created_on'] = '';
}
if (!empty($row['modified_on']) && $row['modified_on'] != '0000-00-00 00:00:00') {
$row['modified_on'] = $row['modified_on'];
} else {
$row['modified_on'] = '';
}
if (!empty($row['publicated_on']) && $row['publicated_on'] != '0000-00-00 00:00:00') {
$row['publicated_on'] = $row['publicated_on'];
} else {
$row['publicated_on'] = '';
}
if (!empty($row['expired_on']) && $row['expired_on'] != '0000-00-00 00:00:00') {
$row['expired_on'] = $row['expired_on'];
} else {
$row['expired_on'] = '';
}
$this->list[$row['id']] = array(
'lp_type' => $row['lp_type'],
'lp_session' => $row['session_id'],
@ -122,12 +137,11 @@ class learnpathList {
'lp_force_commit' => $row['force_commit'],
'lp_maker' => stripslashes($row['content_maker']),
'lp_proximity' => $row['content_local'],
//'lp_encoding' => $row['default_encoding'],
'lp_encoding' => api_get_system_encoding(), // Chamilo 1.8.8: We intend always to use the system encoding.
'lp_encoding' => api_get_system_encoding(),
'lp_visibility' => $vis,
'lp_published' => $pub,
'lp_prevent_reinit' => $row['prevent_reinit'],
'seriousgame_mode' => $row['seriousgame_mode'],
'seriousgame_mode' => $row['seriousgame_mode'],
'lp_scorm_debug' => $row['debug'],
'lp_display_order' => $row['display_order'],
'lp_preview_image' => stripslashes($row['preview_image']),
@ -137,10 +151,10 @@ class learnpathList {
'modified_on' => $row['modified_on'],
'publicated_on' => $row['publicated_on'],
'expired_on' => $row['expired_on']
);
);
$names[$row['name']] = $row['id'];
}
$this->alpha_list = asort($names);
}
$this->alpha_list = asort($names);
}
/**
@ -176,7 +190,7 @@ class learnpathList {
$course = api_get_course_info($course_code);
//QUery
$sql = "SELECT * FROM $tbl_course_lp
WHERE c_id = %s "; //TODO AND session_id = %s ?
WHERE c_id = %s "; //TODO AND session_id = %s ?
$sql_query = sprintf($sql, $course['real_id']);
$result = Database::query($sql_query);

@ -102,9 +102,13 @@ if ($is_allowed_to_edit) {
$token = Security::get_token();
/* DISPLAY SCORM LIST */
$list = new LearnpathList(api_get_user_id());
$userId = api_get_user_id();
$userInfo = api_get_user_info();
$list = new LearnpathList($userId);
$flat_list = $list->get_flat_list();
if (!empty($flat_list)) {
echo '<table class="data_table">';
echo '<tr>';
@ -129,8 +133,8 @@ if (!empty($flat_list)) {
$autolunch_exists = false;
foreach ($flat_list as $id => $details) {
// Validacion when belongs to a session
$session_img = api_get_session_image($details['lp_session'], $_user['status']);
// Validation when belongs to a session.
$session_img = api_get_session_image($details['lp_session'], $userInfo['status']);
if (!$is_allowed_to_edit && $details['lp_visibility'] == 0) {
// This is a student and this path is invisible, skip.
@ -138,15 +142,18 @@ if (!empty($flat_list)) {
}
// Check if the learnpath is visible for student.
if (!$is_allowed_to_edit && !learnpath::is_lp_visible_for_student($id, api_get_user_id())) {
if (!$is_allowed_to_edit && !learnpath::is_lp_visible_for_student($id, $userId)) {
continue;
}
$start_time = $end_time = '';
if (!$is_allowed_to_edit) {
$time_limits = false;
//This is an old LP (from a migration 1.8.7) so we do nothing
if ((empty($details['created_on']) || $details['created_on'] == '0000-00-00 00:00:00') && (empty($details['modified_on']) || $details['modified_on'] == '0000-00-00 00:00:00')) {
if ((empty($details['created_on']) || $details['created_on'] == '0000-00-00 00:00:00') &&
(empty($details['modified_on']) || $details['modified_on'] == '0000-00-00 00:00:00')
) {
$time_limits = false;
}
@ -154,6 +161,7 @@ if (!empty($flat_list)) {
if ($details['expired_on'] != '' && $details['expired_on'] != '0000-00-00 00:00:00') {
$time_limits = true;
}
if ($time_limits) {
// check if start time
if (!empty($details['publicated_on']) && $details['publicated_on'] != '0000-00-00 00:00:00' &&
@ -192,14 +200,17 @@ if (!empty($flat_list)) {
$url_start_lp = 'lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$id;
$name = Security::remove_XSS($details['lp_name']);
$extra = null;
if ($is_allowed_to_edit) {
$url_start_lp .= '&isStudentView=true';
$dsp_desc = '<em>'.$details['lp_maker'].'</em> '.(learnpath::is_lp_visible_for_student($id, api_get_user_id()) ? '' : ' - ('.get_lang('LPNotVisibleToStudent').')');
$studentVisibility = learnpath::is_lp_visible_for_student($id, $userId);
$dsp_desc = '<em>'.$details['lp_maker'].'</em> '.( $studentVisibility ? '' : ' - ('.get_lang('LPNotVisibleToStudent').')');
$extra = '<div class ="lp_content_type_label">'.$dsp_desc.'</div>';
}
$my_title = $name;
$icon_learnpath = Display::return_icon('learnpath.png', get_lang('LPName'), '', ICON_SIZE_SMALL);
if ($details['lp_visibility'] == 0) {
$my_title = Display::tag('font', $name, array('class' => 'invisible'));
$icon_learnpath = Display::return_icon('learnpath_na.png', get_lang('LPName'), '', ICON_SIZE_SMALL);
@ -218,12 +229,12 @@ if (!empty($flat_list)) {
$dsp_debug = '';
$dsp_order = '';
$progress = learnpath::get_db_progress($id, api_get_user_id(), '%', '', false, api_get_session_id());
$progress = learnpath::get_db_progress($id, $userId, '%', '', false, api_get_session_id());
if ($is_allowed_to_edit) {
$dsp_progress = '<td><center>'.$progress.'</center></td>';
} else {
$dsp_progress = '<td>'.learnpath::get_progress_bar('%', learnpath::get_db_progress($id, api_get_user_id(), '%', '', false, api_get_session_id())).'</td>';
$dsp_progress = '<td>'.learnpath::get_progress_bar('%', learnpath::get_db_progress($id, $userId, '%', '', false, api_get_session_id())).'</td>';
}
$dsp_edit = '<td class="td_actions">';

Loading…
Cancel
Save