From 78df09bdd354208e90df4df9b2083ed0b517ce65 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 15 Feb 2011 18:28:09 +0100 Subject: [PATCH] Fixing week view in the new session view see BT#2063 --- main/inc/ajax/course_home.ajax.php | 16 ++++++++++------ main/inc/lib/database.lib.php | 2 +- main/inc/lib/text.lib.php | 2 +- main/newscorm/learnpathList.class.php | 11 ++++++----- main/session/index.php | 5 +++-- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/main/inc/ajax/course_home.ajax.php b/main/inc/ajax/course_home.ajax.php index bca3976cdc..938a63194e 100755 --- a/main/inc/ajax/course_home.ajax.php +++ b/main/inc/ajax/course_home.ajax.php @@ -239,9 +239,9 @@ switch ($action) { $course_list = SessionManager::get_course_list_by_session_id($session_id); $count = 0; - + $temp = array(); foreach ($course_list as $item) { - $list = new LearnpathList(api_get_user_id(),$item['code'],$session_id); + $list = new LearnpathList(api_get_user_id(),$item['code'], $session_id, 'publicated_on DESC'); $flat_list = $list->get_flat_list(); $lps[$item['code']] = $flat_list; $item['title'] = Display::url($item['title'],api_get_path(WEB_COURSE_PATH).$item['directory'].'/?id_session='.$session_id,array('target'=>'_blank')); @@ -271,10 +271,13 @@ switch ($action) { } //Checking LP publicated and expired_on dates - if (!empty($lp_item['publicated_on']) && $lp_item['publicated_on'] != '0000-00-00 00:00:00') { + if (!empty($lp_item['publicated_on']) && $lp_item['publicated_on'] != '0000-00-00 00:00:00') { + $week_data = date('Y', api_strtotime($lp_item['publicated_on'])).' - '.get_week_from_day($lp_item['publicated_on']); if ($now < api_strtotime($lp_item['publicated_on'])) { continue; } + } else { + $week_data = ''; } if (!empty($lp_item['expired_on']) && $lp_item['expired_on'] != '0000-00-00 00:00:00') { @@ -282,11 +285,12 @@ switch ($action) { continue; } } - - $temp[$count]['cell']=array(get_week_from_day($lp_item['publicated_on']), $date, $item['title'], Display::url($lp_item['lp_name'].$icons, $lp_url, array('target'=>'_blank'))); + + $temp[$count]['cell'] = array($week_data, $date, $item['title'], Display::url($lp_item['lp_name'].$icons, $lp_url, array('target'=>'_blank'))); $count++; } - } + } + $response = new stdClass(); $i =0; foreach($temp as $key=>$row) { diff --git a/main/inc/lib/database.lib.php b/main/inc/lib/database.lib.php index 0a6bffbf51..c9a0eed539 100755 --- a/main/inc/lib/database.lib.php +++ b/main/inc/lib/database.lib.php @@ -1384,7 +1384,7 @@ class Database { * @param array * @todo lot of stuff to do here */ - private function parse_conditions($conditions) { + public function parse_conditions($conditions) { if (empty($conditions)) { return ''; } diff --git a/main/inc/lib/text.lib.php b/main/inc/lib/text.lib.php index 4266aa13a8..8467d76ddf 100755 --- a/main/inc/lib/text.lib.php +++ b/main/inc/lib/text.lib.php @@ -623,7 +623,7 @@ function get_last_week() { function get_week_from_day($date) { if (!empty($date)) { $time = api_strtotime($date,'UTC'); - return date('W', $date); + return date('W', $time); } else { return date('W'); } diff --git a/main/newscorm/learnpathList.class.php b/main/newscorm/learnpathList.class.php index 49268a8d2b..0f109f2a2e 100755 --- a/main/newscorm/learnpathList.class.php +++ b/main/newscorm/learnpathList.class.php @@ -30,7 +30,7 @@ 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) { + function __construct($user_id, $course_code='', $session_id = null, $order_by = null) { if (!empty($course_code)){ $course_info = api_get_course_info($course_code); @@ -49,8 +49,11 @@ class learnpathList { $session_id = api_get_session_id(); } $condition_session = api_get_session_condition($session_id, false, true); - - $sql = "SELECT * FROM $lp_table $condition_session ORDER BY display_order ASC, name ASC"; + $order = "ORDER BY display_order ASC, name ASC"; + if (isset($order_by)) { + $order = Database::parse_conditions(array('order'=>$order_by)); + } + $sql = "SELECT * FROM $lp_table $condition_session $order"; $res = Database::query($sql); $names = array(); while ($row = Database::fetch_array($res,'ASSOC')) { @@ -96,8 +99,6 @@ class learnpathList { } else { $row['expired_on'] = ''; } - - $this->list[$row['id']] = array( 'lp_type' => $row['lp_type'], 'lp_session' => $row['session_id'], diff --git a/main/session/index.php b/main/session/index.php index 675e8699b9..a06ac36798 100644 --- a/main/session/index.php +++ b/main/session/index.php @@ -260,9 +260,10 @@ $column_week_model = array ( array('name'=>'course', 'index'=>'course', 'width'=>'400', 'align'=>'left', 'sortable'=>'false'), array('name'=>'lp', 'index'=>'lp', 'width'=>'200', 'align'=>'center','sortable'=>'false')); - $extra_params_week['grouping'] = 'true'; -$extra_params_week['groupingView'] = array('groupField'=>array('week'), +//For more details see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:grouping +$extra_params_week['groupingView'] = array('groupDataSorted' =>true, + 'groupField'=>array('week'), 'groupColumnShow'=>'false', 'groupText' => array(''.get_lang('PeriodWeek').' {0}')); //$extra_params_week['autowidth'] = 'true'; //use the width of the parent