Adding js and html wrappers for the jqgrid jquery extension see BT#1631

skala
Julio Montoya 14 years ago
parent 5986cb7678
commit a40dac2cde
  1. 44
      main/inc/ajax/course_home.ajax.php
  2. 92
      main/inc/lib/display.lib.php
  3. 178
      main/session/index.php
  4. 5
      user_portal.php

@ -73,6 +73,10 @@ switch ($action) {
// Function that displays the details of the course description in html.
echo CourseManager::get_details_course_description_html($descriptions, api_get_system_encoding(), false);
break;
/**
* @todo this functions need to belong to a class or a special wrapper to process the AJAX petitions from the jqgrid
*/
case 'session_courses_lp_default':
require_once '../global.inc.php';
@ -84,17 +88,21 @@ switch ($action) {
require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
$page = $_REQUEST['page']; //page
$limit = $_REQUEST['rows']; // quantity of rows
$sidx = $_REQUEST['sidx']; //index to filter
$sord = $_REQUEST['sord']; //asc or desc
$session_id = $_REQUEST['session_id'];
$page = intval($_REQUEST['page']); //page
$limit = intval($_REQUEST['rows']); // quantity of rows
$sidx = $_REQUEST['sidx']; //index to filter
$sord = $_REQUEST['sord']; //asc or desc
if (!in_array($sord, array('asc','desc'))) {
$sord = 'desc';
}
$session_id = intval($_REQUEST['session_id']);
if(!$sidx) $sidx =1;
$start = $limit*$page - $limit;
$course_list = SessionManager::get_course_list_by_session_id($session_id);
$count = 0;
@ -146,11 +154,14 @@ switch ($action) {
require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
$page = $_REQUEST['page']; //page
$limit = $_REQUEST['rows']; // quantity of rows
$sidx = $_REQUEST['sidx']; //index to filter
$sord = $_REQUEST['sord']; //asc or desc
$session_id = $_REQUEST['session_id'];
$page = intval($_REQUEST['page']); //page
$limit = intval($_REQUEST['rows']); // quantity of rows
$sidx = $_REQUEST['sidx']; //index to filter
$sord = $_REQUEST['sord']; //asc or desc
if (!in_array($sord, array('asc','desc'))) {
$sord = 'desc';
}
$session_id = intval($_REQUEST['session_id']);
if(!$sidx) $sidx =1;
@ -208,11 +219,14 @@ switch ($action) {
require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
$page = $_REQUEST['page']; //page
$limit = $_REQUEST['rows']; // quantity of rows
$sidx = $_REQUEST['sidx']; //index to filter
$sord = $_REQUEST['sord']; //asc or desc
$session_id = $_REQUEST['session_id'];
$page = intval($_REQUEST['page']); //page
$limit = intval($_REQUEST['rows']); // quantity of rows
$sidx = $_REQUEST['sidx']; //index to filter
$sord = $_REQUEST['sord']; //asc or desc
if (!in_array($sord, array('asc','desc'))) {
$sord = 'desc';
}
$session_id = intval($_REQUEST['session_id']);
if(!$sidx) $sidx =1;

@ -754,10 +754,10 @@ class Display {
}
/**
* Creates a tab list
* Creates a tab menu
* Requirements: declare the jquery, jquery-ui libraries + the jquery-ui.css in the $htmlHeadXtra variable before the display_header
* Add this script
*
* @example
* <script>
$(function() {
$( "#tabs" ).tabs();
@ -765,7 +765,7 @@ class Display {
</script>
* @param array list of the tab titles
* @param array content that will be showed
* @param string the id of the container of the tab
* @param string the id of the container of the tab in the example "tabs"
* @param array attributes for the ul
*
*/
@ -797,4 +797,90 @@ class Display {
return $main_div ;
}
/**
*
*/
public static function grid_html($div_id){
$table = self::tag('table','',array('id'=>$div_id));
$table .= self::tag('div','',array('id'=>$div_id.'_pager'));
return $table;
}
/**
* This is just a wrapper to use the jqgrid For the other options go here http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options
* This function need to be in the ready jquery function --> $(function() { }
* @param string div id
* @param string url where the jqgrid will ask for data
* @param array Visible columns (you should use get_lang). An array in which we place the names of the columns. This is the text that appears in the head of the grid (Header layer). Example: colname {name:'date', index:'date', width:120, align:'right'},
* @param array the column model : Array which describes the parameters of the columns.This is the most important part of the grid. For a full description of all valid values see colModel API. See the url above.
* @param array extra parameters
* @return string the js code
*
*/
public static function grid_js($div_id, $url, $column_names, $column_model, $extra_params) {
$obj = new stdClass();
$obj->url = $url;
$obj->colNames = $column_names;
$obj->colModel = $column_model;
$obj->pager = $div_id.'_pager';
$obj->datatype = 'json';
if (!empty($extra_params['datatype'])) {
$obj->datatype = $extra_params['datatype'];
}
if (!empty($extra_params['sortname'])) {
$obj->sortname = $extra_params['sortname'];
}
$obj->sortorder = 'desc';
if (!empty($extra_params['sortorder'])) {
$obj->sortorder = $extra_params['sortorder'];
}
if (!empty($extra_params['rowList'])) {
$obj->rowList = $extra_params['rowList'];
}
$obj->viewrecords = 'true';
if (!empty($extra_params['viewrecords']))
$obj->viewrecords = $extra_params['viewrecords'];
if (!empty($extra_params)) {
foreach ($extra_params as $key=>$element){
$obj->$key = $element;
}
}
$json = '$("#'.$div_id.'").jqGrid(';
$json .= json_encode($obj);
$json .= ');';
return $json;
/*
Real Example
$("#list_week").jqGrid({
url:'<?php echo api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=session_courses_lp_by_week&session_id='.$session_id; ?>',
datatype: 'json',
colNames:['Week','Date','Course', 'LP'],
colModel :[
{name:'week', index:'week', width:120, align:'right'},
{name:'date', index:'date', width:120, align:'right'},
{name:'course', index:'course', width:150},
{name:'lp', index:'lp', width:250}
],
pager: '#pager3',
rowNum:100,
rowList:[10,20,30],
sortname: 'date',
sortorder: 'desc',
viewrecords: true,
grouping:true,
groupingView : {
groupField : ['week'],
groupColumnShow : [false],
groupText : ['<b>Week {0} - {1} Item(s)</b>']
}
}); */
}
} //end class Display

@ -6,9 +6,12 @@ $libpath = api_get_path(LIBRARY_PATH);
require_once $libpath.'course.lib.php';
//require_once $libpath.'usermanager.lib.php';
require_once $libpath.'sessionmanager.lib.php';
require_once $libpath.'usermanager.lib.php';
require_once $libpath.'formvalidator/FormValidator.class.php';
require_once $libpath.'text.lib.php';
require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
api_block_anonymous_users(); // Only users who are logged in can proceed.
@ -32,6 +35,8 @@ Display :: display_header($nameTools);
$session_id = intval($_GET['session_id']);
$session_info = SessionManager::fetch($session_id);
$session_list = SessionManager::get_sessions_by_coach(api_get_user_id());
$course_list = SessionManager::get_course_list_by_session_id($session_id);
$course_select = array();
@ -44,11 +49,19 @@ foreach ($course_list as $course_item) {
$course_select[$course_item['id']] = $course_item['title'];
}*/
// Session list form
$form = new FormValidator('exercise_admin', 'get', api_get_self().'?session_id='.$session_id);
$form->addElement('select', 'session_id', get_lang('SessionList'), $session_select, 'onchange="javascript:change_session()"');
$defaults['session_id'] = $session_id;
$form->setDefaults($defaults);
$form->display();
if (count($session_select) > 1) {
$form = new FormValidator('exercise_admin', 'get', api_get_self().'?session_id='.$session_id);
$form->addElement('select', 'session_id', get_lang('SessionList'), $session_select, 'onchange="javascript:change_session()"');
$defaults['session_id'] = $session_id;
$form->setDefaults($defaults);
$form->display();
if ($form->validate()) {
}
}
echo Display::tag('h1', $session_info['name']);
@ -62,19 +75,70 @@ foreach ($course_list as $item) {
$lps[$item['code']] = $flat_list;
foreach ($flat_list as $item) {
//var_dump(get_week_from_day($item['publicated_on']));
}
}
}
if ($form->validate()) {
//Getting all sessions where I'm subscribed
$new_session_list = UserManager::get_personal_session_course_list(api_get_user_id());
echo '<pre>';
$my_session_list = array();
foreach($new_session_list as $item) {
if (isset($item['id_session'])) {
$my_course_list = UserManager::get_courses_list_by_session(api_get_user_id(),$item['id_session'] );
foreach ($my_course_list as $my_course) {
$course_info = api_get_course_info($my_course['code']);
$exercise_list = get_all_exercises($course_info);
foreach($exercise_list as $exercise_item) {
$exercise = new Exercise($course_info['real_id']);
$exercise->read($exercise_item['id']);
$exercise->exercise;
}
}
$my_session_list[$item['id_session']]['session_name']= $item['session_name'];
$my_session_list[$item['id_session']]['courses']= $my_course_list;
}
}
foreach ($my_session_list as $my_session_id => $data) {
//$my_course_list = $data();
}
//print_r($my_session_list);
//Exercise list
/*
$exercise_grid_url = api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=session_courses_lp_default&session_id='.$session_id;
$exercise_grid_columns =array(get_lang('Session'), get_lang(''))
$exercise_grid_column_model
$exercise_grid_settings =
*/
//Default grid settings
$url = api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=session_courses_lp_default&session_id='.$session_id;
$columns = array('Date','Course', 'LP');
$column_model = array(array('name'=>'date', 'index'=>'date', 'width'=>'120', 'align'=>'right'),
array('name'=>'course', 'index'=>'course', 'width'=>'120', 'align'=>'right'),
array('name'=>'lp', 'index'=>'lp', 'width'=>'120', 'align'=>'right'));
//Course grid settings
$url_course = api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=session_courses_lp_by_course&session_id='.$session_id;
$extra_params_course['grouping'] = 'true';
$extra_params_course['groupingView'] = array('groupField'=>array('course'),
'groupColumnShow'=>array('false'),
'groupText' => array('<b>Course {0} - {1} Item(s)</b>'));
//Week grid
$url_week = api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=session_courses_lp_by_course&session_id='.$session_id;
$column_week = array('Week','Date','Course', 'LP');
$column_week_model =array(array('name'=>'week', 'index'=>'week', 'width'=>'120', 'align'=>'right'),
array('name'=>'date', 'index'=>'date', 'width'=>'120', 'align'=>'right'),
array('name'=>'course', 'index'=>'course', 'width'=>'120', 'align'=>'right'),
array('name'=>'lp', 'index'=>'lp', 'width'=>'120','align'=>'right'));
$extra_params_week['grouping'] = 'true';
$extra_params_week['groupingView'] = array('groupField'=>array('week'),
'groupColumnShow'=>array('false'),
'groupText' => array('<b>Week {0} - {1} Item(s)</b>'));
?>
<br />
<script>
@ -87,94 +151,22 @@ $(function() {
$( "#tabs" ).tabs();
$( "#sub_tab" ).tabs();
$("#list_default").jqGrid({
url:'<?php echo api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=session_courses_lp_default&session_id='.$session_id; ?>',
datatype: 'json',
colNames:['Date','Course', 'LP'],
colModel :[
{name:'date', index:'date', width:120, align:'right'},
{name:'course', index:'course', width:150},
{name:'lp', index:'lp', width:250}
],
pager: '#pager1',
rowNum:100,
/* rowList:[10,20,30], */
sortname: 'date',
sortorder: 'desc',
viewrecords: true
});
$("#list_course").jqGrid({
url:'<?php echo api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=session_courses_lp_by_course&session_id='.$session_id; ?>',
datatype: 'json',
colNames:['Date','Course', 'LP'],
colModel :[
{name:'date', index:'date', width:120},
{name:'course', index:'course', width:150},
{name:'lp', index:'lp', width:250}
],
pager: '#pager2',
rowNum:100,
/* rowList:[10,20,30], */
sortname: 'date',
sortorder: 'desc',
viewrecords: true,
grouping:true,
groupingView : {
groupField : ['course'],
groupColumnShow : [false],
groupText : ['<b>Course {0} - {1} Item(s)</b>']
}
});
$("#list_week").jqGrid({
url:'<?php echo api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?a=session_courses_lp_by_week&session_id='.$session_id; ?>',
datatype: 'json',
colNames:['Week','Date','Course', 'LP'],
colModel :[
{name:'week', index:'week', width:120, align:'right'},
{name:'date', index:'date', width:120, align:'right'},
{name:'course', index:'course', width:150},
{name:'lp', index:'lp', width:250}
],
pager: '#pager3',
rowNum:100,
/* rowList:[10,20,30], */
sortname: 'date',
sortorder: 'desc',
viewrecords: true,
grouping:true,
groupingView : {
groupField : ['week'],
groupColumnShow : [false],
groupText : ['<b>Week {0} - {1} Item(s)</b>']
}
});
<?php
echo Display::grid_js('list_default', $url, $columns,$column_model);
echo Display::grid_js('list_course', $url_course,$columns,$column_model,$extra_params_course);
echo Display::grid_js('list_week', $url_week, $column_week,$column_week_model, $extra_params_week);
echo Display::grid_js('exercise_list', $exercise_grid_url, $column_week,$column_week_model, $extra_params_week);
?>
});
</script>
<?php
$lp_table1 = Display::tag('table','',array('id'=>'list_default'));
$lp_table1 .= Display::tag('div','',array('id'=>'pager1'));
$lp_table2 = Display::tag('table','',array('id'=>'list_week'));
$lp_table2 .= Display::tag('div','',array('id'=>'pager2'));
$lp_table3 = Display::tag('table','',array('id'=>'list_course'));
$lp_table3 .= Display::tag('div','',array('id'=>'pager3'));
$headers = array(get_lang('LearningPaths'), get_lang('MyQCM'), get_lang('MyResults'));
$sub_header = array(get_lang('AllLearningPaths'), get_lang('PerWeek'), get_lang('ByCourse'));
$tabs = Display::tabs($sub_header, array($lp_table1,$lp_table2, $lp_table3),'sub_tab');
$tabs = Display::tabs($sub_header, array(Display::grid_html('list_default'), Display::grid_html('list_week'), Display::grid_html('list_course')),'sub_tab');
echo Display::tabs($headers, array($tabs,'bbb','ccc'));
// Footer

@ -36,7 +36,8 @@ $language_file = array('courses', 'index');
$cidReset = true; /* Flag forcing the 'current course' reset,
as we're not inside a course anymore */
unset($_SESSION['this_section']); // For hmtl editor repository.
if (isset($_SESSION['this_section']))
unset($_SESSION['this_section']); // For HTML editor repository.
/* Included libraries */
@ -1348,7 +1349,7 @@ if (is_array($courses_tree)) {
$extra_info = (!empty($s['coach']) ? $s['coach'].' | ' : '').$s['dates'];
//var_dump($s);
//echo get_lang('SessionName') . ': ' . $s['title']. ' - '.(!empty($s['coach']) ? $s['coach'].' - ' : '').$s['dates'];
$session_link = Display::tag('a',$s['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/?id_session='.$session['details']['id']));
$session_link = Display::tag('a',$s['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/?session_id='.$session['details']['id']));
echo '<span>' . $session_link. ' </span> <span style="padding-left: 10px; font-size: 90%; font-weight: normal;">'.$extra_info.'</span>';
if (api_is_platform_admin()) {
echo '<div style="float:right;"><a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session['details']['id'].'">'.Display::return_icon('edit.gif', get_lang('Edit'), array('align' => 'absmiddle')).'</a></div>';

Loading…
Cancel
Save