Adding course filter in session list see BT#7011

1.9.x
Julio Montoya 13 years ago
parent ff17b0001c
commit fa868fbf39
  1. 10
      main/admin/course_list.php
  2. 37
      main/admin/session_list.php
  3. 25
      main/inc/ajax/course.ajax.php
  4. 5
      main/inc/ajax/model.ajax.php
  5. 23
      main/inc/ajax/session.ajax.php
  6. 24
      main/inc/lib/sessionmanager.lib.php

@ -330,15 +330,17 @@ if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
});
});
</script>';
$actions .= $sessionFilter->return_form();
$actions .= '<div style="float: right; ">';
$actions .= '<div class="pull-right">';
$actions .= '<a href="course_add.php">'.Display::return_icon('new_course.png', get_lang('AddCourse'),'',ICON_SIZE_MEDIUM).'</a> ';
if (api_get_setting('course_validation') == 'true') {
$actions .= '<a href="course_request_review.php">'.Display::return_icon('course_request_pending.png', get_lang('ReviewCourseRequests'),'',ICON_SIZE_MEDIUM).'</a>';
}
$actions .= '</div>';
$actions .= '<div class="pull-right">';
$actions .= $sessionFilter->return_form();
$actions .= '</div>';
$actions .= $form->return_form();
if (isset($_GET['session_id']) && !empty($_GET['session_id'])) {

@ -45,8 +45,34 @@ if (!empty($error_message)) {
Display::display_normal_message($error_message, false);
}
//jqgrid will use this URL to do the selects
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions';
$sessionFilter = new FormValidator('course_filter', 'get', '', '', array('class'=> 'form-search'), false);
$url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_course';
$courseList = array();
$courseId = isset($_GET['course_id']) ? $_GET['course_id'] : null;
if (!empty($courseId)) {
$courseInfo = api_get_course_info_by_id($courseId);
$courseList[] = array('id' => $courseInfo['id'], 'text' => $courseInfo['title']);
}
$sessionFilter->addElement('select_ajax', 'course_name', get_lang('SearchCourse'), null, array('url' => $url, 'defaults' => $courseList));
$url = api_get_self();
$actions = '
<script>
$(function() {
$("#course_name").on("change", function() {
var courseId = $(this).val();
console.log(courseId);
window.location = "'.$url.'?course_id="+courseId;
});
});
</script>';
// jqgrid will use this URL to do the selects
if (!empty($courseId)) {
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&course_id='.$courseId;
} else {
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions';
}
if (isset($_REQUEST['keyword'])) {
//Begin with see the searchOper param
@ -170,14 +196,19 @@ $(function() {
jQuery("#sessions").jqGrid('filterToolbar', options);
var sgrid = $("#sessions")[0];
sgrid.triggerToolbar();
});
</script>
<div class="actions">
<?php
echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/session_add.php">'.Display::return_icon('new_session.png',get_lang('AddSession'),'',ICON_SIZE_MEDIUM).'</a>';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/add_many_session_to_category.php">'.Display::return_icon('session_to_category.png',get_lang('AddSessionsInCategories'),'',ICON_SIZE_MEDIUM).'</a>';
echo '<a href="'.api_get_path(WEB_CODE_PATH).'admin/session_category_list.php">'.Display::return_icon('folder.png',get_lang('ListSessionCategory'),'',ICON_SIZE_MEDIUM).'</a>';
echo $actions;
echo '<div class="pull-right">';
echo $sessionFilter->return_form();
echo '</div>';
echo '</div>';
echo Display::grid_html('sessions');
Display::display_footer();

@ -12,7 +12,6 @@ $user_id = api_get_user_id();
switch ($action) {
case 'add_course_vote':
$course_id = intval($_REQUEST['course_id']);
$star = intval($_REQUEST['star']);
@ -51,7 +50,31 @@ switch ($action) {
} else {
echo json_encode(array());
}
}
break;
case 'search_course':
if (api_is_platform_admin()) {
$courseList = Coursemanager::get_courses_list(
0,
10,
1, //$orderby = 1,
'ASC',
-1,
$_REQUEST['q']
);
$results = array();
foreach ($courseList as $courseInfo) {
$results[] = array('id' => $courseInfo['id'], 'text' => $courseInfo['title']);
}
if (!empty($results)) {
/*foreach ($results as &$item) {
$item['id'] = $item['code'];
}*/
echo json_encode($results);
} else {
echo json_encode(array());
}
}
break;
default:

@ -197,6 +197,10 @@ switch ($action) {
$count = get_count_exam_hotpotatoes_results($hotpot_path);
break;
case 'get_sessions':
$courseId = isset($_GET['course_id']) && !empty($_GET['course_id']) ? intval($_GET['course_id']) : null;
if (!empty($courseId)) {
$where_condition .= " c.id = $courseId";
}
$count = SessionManager::get_count_admin($where_condition);
break;
/*case 'get_extra_fields':
@ -418,6 +422,7 @@ switch ($action) {
$columns = array(
'name', 'nbr_courses', 'nbr_users', 'category_name', 'date_start','date_end', 'coach_name', 'session_active', 'visibility'
);
$result = SessionManager::get_sessions_admin(
array(
'where' => $where_condition,

@ -47,6 +47,29 @@ switch ($action) {
}
}
break;
case 'search_session_by_course':
if (api_is_platform_admin()) {
$results = SessionManager::get_sessions_list(array('s.name LIKE' => "%".$_REQUEST['q']."%"));
$results2 = array();
if (!empty($results)) {
foreach ($results as $item) {
$item2 = array();
foreach ($item as $id => $internal) {
if ($id == 'id') {
$item2[$id] = $internal;
}
if ($id == 'name') {
$item2['text'] = $internal;
}
}
$results2[] = $item2;
}
echo json_encode($results2);
} else {
echo json_encode(array());
}
}
break;
default:
echo '';
}

@ -258,6 +258,15 @@ class SessionManager
$where_condition = "1 = 1";
}
$courseCondition = null;
if (strpos($where_condition, 'c.id')) {
$table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$tableCourse = Database::get_main_table(TABLE_MAIN_COURSE);
$courseCondition = " INNER JOIN $table course_rel_session ON (s.id = course_rel_session.id_session)
INNER JOIN $tableCourse c ON (course_rel_session.course_code = c.code)
";
}
$sql = "SELECT count(id) as total_rows FROM (
SELECT
IF (
@ -274,6 +283,7 @@ class SessionManager
FROM $tbl_session s
LEFT JOIN $tbl_session_category sc ON s.session_category_id = sc.id
INNER JOIN $tbl_user u ON s.id_coach = u.user_id
$courseCondition
$extraJoin
$where AND $where_condition ) as session_table";
@ -299,6 +309,7 @@ class SessionManager
LEFT JOIN $tbl_session_category sc ON s.session_category_id = sc.id
INNER JOIN $tbl_user u ON s.id_coach = u.user_id
INNER JOIN $table_access_url_rel_session ar ON ar.session_id = s.id
$courseCondition
$extraJoin
$where AND $where_condition) as session_table";
}
@ -362,6 +373,15 @@ class SessionManager
$today = api_strtotime($today, 'UTC');
$today = date('Y-m-d', $today);
$courseCondition = null;
if (strpos($options['where'], 'c.id')) {
$table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$tableCourse = Database::get_main_table(TABLE_MAIN_COURSE);
$courseCondition = " INNER JOIN $table course_rel_session ON (s.id = course_rel_session.id_session)
INNER JOIN $tableCourse c ON (course_rel_session.course_code = c.code)
";
}
$select = "SELECT * FROM (SELECT
IF (
(s.date_start <= '$today' AND '$today' < s.date_end) OR
@ -374,7 +394,7 @@ class SessionManager
as session_active,
s.name,
nbr_courses,
nbr_users,
s.nbr_users,
s.date_start,
s.date_end,
$coach_name,
@ -400,6 +420,7 @@ class SessionManager
$query = "$select FROM $tbl_session s
LEFT JOIN $tbl_session_category sc ON s.session_category_id = sc.id
LEFT JOIN $tbl_user u ON s.id_coach = u.user_id
$courseCondition
$extraJoin
$where $order $limit";
@ -411,6 +432,7 @@ class SessionManager
LEFT JOIN $tbl_session_category sc ON s.session_category_id = sc.id
INNER JOIN $tbl_user u ON s.id_coach = u.user_id
INNER JOIN $table_access_url_rel_session ar ON ar.session_id = s.id AND ar.access_url_id = $access_url_id
$courseCondition
$extraJoin
$where $order $limit";
}

Loading…
Cancel
Save