Add search extra field in company_reports.php BT#17131

pull/3213/head
Julio Montoya 5 years ago
parent b994031ee2
commit e54d88ee9d
  1. 58
      main/inc/ajax/model.ajax.php
  2. 53
      main/inc/lib/course.lib.php
  3. 8
      main/inc/lib/extra_field.lib.php
  4. 184
      main/mySpace/company_reports.php
  5. 71
      main/session/session_list.php

@ -160,8 +160,20 @@ if (($search || $forceSearch) && ($search !== 'false')) {
}
if (!empty($filters)) {
if (in_array($action, ['get_questions', 'get_sessions', 'get_sessions_tracking'])) {
if (in_array($action,
[
'get_user_course_report_resumed',
'get_user_course_report',
'get_questions',
'get_sessions',
'get_sessions_tracking',
]
)) {
switch ($action) {
case 'get_user_course_report_resumed':
case 'get_user_course_report':
$type = 'user';
break;
case 'get_questions':
$type = 'question';
break;
@ -197,6 +209,7 @@ if (($search || $forceSearch) && ($search !== 'false')) {
}
}
}
$result = $extraField->getExtraFieldRules($filters, 'extra_');
$extra_fields = $result['extra_fields'];
@ -503,7 +516,8 @@ switch ($action) {
null,
$courseCodeList,
$userIdList,
$sessionIdList
$sessionIdList,
['where' => $whereCondition, 'extra' => $extra_fields]
);
} else {
$count = CourseManager::get_count_user_list_from_course_code(
@ -511,7 +525,8 @@ switch ($action) {
['ruc'],
$courseCodeList,
$userIdList,
$sessionIdList
$sessionIdList,
['where' => $whereCondition, 'extra' => $extra_fields]
);
}
break;
@ -1012,7 +1027,7 @@ switch ($action) {
get_lang('CountCertificates'),
];
$extra_fields = UserManager::get_extra_fields(
$userExtraFields = UserManager::get_extra_fields(
0,
100,
null,
@ -1021,8 +1036,8 @@ switch ($action) {
true
);
if (!empty($extra_fields)) {
foreach ($extra_fields as $extra) {
if (!empty($userExtraFields)) {
foreach ($userExtraFields as $extra) {
if ($extra['1'] == 'ruc') {
continue;
}
@ -1031,10 +1046,6 @@ switch ($action) {
}
}
if (!in_array($sidx, ['training_hours'])) {
//$sidx = 'training_hours';
}
if (api_is_student_boss() && empty($userIdList)) {
$result = [];
break;
@ -1053,7 +1064,9 @@ switch ($action) {
$courseCodeList,
$userIdList,
null,
$sessionIdList
$sessionIdList,
null,
['where' => $whereCondition, 'extra' => $extra_fields]
);
$new_result = [];
@ -1086,7 +1099,7 @@ switch ($action) {
get_lang('CourseAdvance'),
];
$extra_fields = UserManager::get_extra_fields(
$userExtraFields = UserManager::get_extra_fields(
0,
100,
null,
@ -1094,8 +1107,8 @@ switch ($action) {
true,
true
);
if (!empty($extra_fields)) {
foreach ($extra_fields as $extra) {
if (!empty($userExtraFields)) {
foreach ($userExtraFields as $extra) {
$columns[] = $extra['1'];
$column_names[] = $extra['3'];
}
@ -1115,10 +1128,10 @@ switch ($action) {
break;
}
//get sessions
$arrSessions = [];
// get sessions
$sessions = [];
if (count($sessionIdList) > 0) {
$arrSessions = CourseManager::get_user_list_from_course_code(
$sessions = CourseManager::get_user_list_from_course_code(
null,
null,
"LIMIT $start, $limit",
@ -1135,8 +1148,8 @@ switch ($action) {
);
}
//get courses
$arrCourses = CourseManager::get_user_list_from_course_code(
// get courses
$courses = CourseManager::get_user_list_from_course_code(
null,
null,
"LIMIT $start, $limit",
@ -1148,11 +1161,14 @@ switch ($action) {
null,
[],
$userIdList,
null
null,
null,
null,
['where' => $whereCondition, 'extra' => $extra_fields]
);
//merge courses and sessions
$result = array_merge($arrSessions, $arrCourses);
$result = array_merge($sessions, $courses);
if (api_is_student_boss()) {
$userGroup = new UserGroup();

@ -1403,7 +1403,8 @@ class CourseManager
$userIdList = [],
$filterByActive = null,
$sessionIdList = [],
$searchByKeyword = ''
$searchByKeyword = '',
$options = []
) {
$course_table = Database::get_main_table(TABLE_MAIN_COURSE);
$sessionTable = Database::get_main_table(TABLE_MAIN_SESSION);
@ -1435,6 +1436,23 @@ class CourseManager
}
$filter_by_status_condition = null;
$sqlInjectWhere = '';
$whereExtraField = '';
$injectExtraFields = '';
$sqlInjectJoins = '';
if (!empty($options)) {
$extraFieldModel = new ExtraField('user');
$conditions = $extraFieldModel->parseConditions($options, 'user');
if (!empty($conditions)) {
$injectExtraFields = $conditions['inject_extra_fields'];
if (!empty($injectExtraFields)) {
$injectExtraFields = ', '.$injectExtraFields;
}
$sqlInjectJoins = $conditions['inject_joins'];
$whereExtraField = $conditions['where'];
//$sqlInjectWhere = $conditions['inject_where'];
}
}
if (!empty($session_id) || !empty($sessionIdList)) {
$sql = 'SELECT DISTINCT
@ -1446,6 +1464,7 @@ class CourseManager
course.*,
course.id AS c_id,
session.name as session_name
'.$injectExtraFields.'
';
if ($return_count) {
$sql = " SELECT COUNT(user.user_id) as count";
@ -1474,13 +1493,14 @@ class CourseManager
$courseCondition
INNER JOIN $sessionTable session
ON session_course_user.session_id = session.id
$sqlInjectJoins
";
$where[] = ' session_course_user.c_id IS NOT NULL ';
// 2 = coach
// 0 = student
if (isset($filter_by_status)) {
$filter_by_status = intval($filter_by_status);
$filter_by_status = (int) $filter_by_status;
$filter_by_status_condition = " session_course_user.status = $filter_by_status AND ";
}
} else {
@ -1496,24 +1516,29 @@ class CourseManager
user.id as user_id,
user.email,
course_rel_user.is_tutor,
user.* ';
user.*
'.$injectExtraFields;
} else {
$sql = 'SELECT DISTINCT
course_rel_user.status as status_rel,
user.id as user_id,
user.email,
course_rel_user.is_tutor,
user.* ';
user.*
'.$injectExtraFields
;
}
}
$sql .= " FROM ".Database::get_main_table(TABLE_MAIN_USER)." as user
LEFT JOIN ".Database::get_main_table(TABLE_MAIN_COURSE_USER)." as course_rel_user
ON
user.id = course_rel_user.user_id AND
course_rel_user.relation_type <> ".COURSE_RELATION_TYPE_RRHH."
user.id = course_rel_user.user_id AND
course_rel_user.relation_type <> ".COURSE_RELATION_TYPE_RRHH."
INNER JOIN $course_table course
ON course_rel_user.c_id = course.id ";
ON (course_rel_user.c_id = course.id)
$sqlInjectJoins
";
if (!empty($course_code)) {
$sql .= " AND course_rel_user.c_id = $courseId";
@ -1548,7 +1573,9 @@ class CourseManager
}
}
$sql .= " WHERE $filter_by_status_condition ".implode(' OR ', $where);
$sql .= " WHERE
$filter_by_status_condition
".implode(' OR ', $where);
if ($multiple_access_url) {
$current_access_url_id = api_get_current_access_url_id();
@ -1587,6 +1614,8 @@ class CourseManager
) ";
}
$sql .= $whereExtraField;
$sql .= " $order_by $limit";
$rs = Database::query($sql);
@ -1774,6 +1803,7 @@ class CourseManager
* @param array $courseCodeList
* @param array $userIdList
* @param array $sessionIdList
* @param array $options
*
* @return array|int
*/
@ -1782,7 +1812,8 @@ class CourseManager
$extra_field = [],
$courseCodeList = [],
$userIdList = [],
$sessionIdList = []
$sessionIdList = [],
$options = []
) {
return self::get_user_list_from_course_code(
null,
@ -1797,7 +1828,9 @@ class CourseManager
$courseCodeList,
$userIdList,
null,
$sessionIdList
$sessionIdList,
null,
$options
);
}

@ -2350,7 +2350,13 @@ JAVASCRIPT;
$counter = 1;
$extra_field_obj = new ExtraField($this->type);
foreach ($extra_fields as &$extra) {
if (!isset($extra['id'])) {
continue;
}
$extra_field_info = $extra_field_obj->get($extra['id']);
if (empty($extra_field_info)) {
continue;
}
$extra['extra_field_info'] = $extra_field_info;
if (isset($extra_field_info['field_type']) &&
@ -2573,7 +2579,7 @@ JAVASCRIPT;
} else {
// Extra fields
if (false === strpos($rule->field, '_second')) {
//No _second
// No _second
$original_field = str_replace($stringToSearch, '', $rule->field);
$field_option = $this->get_handler_field_info_by_field_variable($original_field);

@ -1,9 +1,9 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Special report for corporate users.
*
* @package chamilo.reporting
*/
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
@ -20,7 +20,7 @@ $tool_name = get_lang('Report');
$this_section = SECTION_TRACKING;
$htmlHeadXtra[] = api_get_jqgrid_js();
$sessionId = isset($_GET['session_id']) ? intval($_GET['session_id']) : -1;
$sessionId = isset($_GET['session_id']) ? (int) $_GET['session_id'] : -1;
//jqgrid will use this URL to do the selects
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_user_course_report&session_id='.$sessionId;
@ -40,32 +40,88 @@ $columns = [
//Column config
$column_model = [
['name' => 'course', 'index' => 'title', 'width' => '180', 'align' => 'left', 'wrap_cell' => 'true'],
['name' => 'user', 'index' => 'user', 'width' => '100', 'align' => 'left', 'sortable' => 'false', 'wrap_cell' => 'true'],
['name' => 'email', 'index' => 'email', 'width' => '100', 'align' => 'left', 'sortable' => 'false', 'wrap_cell' => 'true'],
['name' => 'time', 'index' => 'time', 'width' => '50', 'align' => 'left', 'sortable' => 'false'],
['name' => 'certificate', 'index' => 'certificate', 'width' => '50', 'align' => 'left', 'sortable' => 'false'],
['name' => 'progress_100', 'index' => 'progress_100', 'width' => '50', 'align' => 'left', 'sortable' => 'false'],
['name' => 'progress', 'index' => 'progress', 'width' => '50', 'align' => 'left', 'sortable' => 'false'],
[
'name' => 'course',
'index' => 'title',
'width' => '180',
'align' => 'left',
'wrap_cell' => 'true',
'search' => 'false',
],
[
'name' => 'user',
'index' => 'user',
'width' => '100',
'align' => 'left',
'sortable' => 'false',
'wrap_cell' => 'true',
'search' => 'false',
],
[
'name' => 'email',
'index' => 'email',
'width' => '100',
'align' => 'left',
'sortable' => 'false',
'wrap_cell' => 'true',
'search' => 'false',
],
[
'name' => 'time',
'index' => 'time',
'width' => '50',
'align' => 'left',
'sortable' => 'false',
'search' => 'false',
],
[
'name' => 'certificate',
'index' => 'certificate',
'width' => '50',
'align' => 'left',
'sortable' => 'false',
'search' => 'false',
],
[
'name' => 'progress_100',
'index' => 'progress_100',
'width' => '50',
'align' => 'left',
'sortable' => 'false',
'search' => 'false',
],
[
'name' => 'progress',
'index' => 'progress',
'width' => '50',
'align' => 'left',
'sortable' => 'false',
'search' => 'false',
],
];
if (!empty($extra_fields)) {
foreach ($extra_fields as $extra) {
$col = [
'name' => $extra['1'],
'index' => $extra['1'],
'index' => 'extra_'.$extra['1'],
'width' => '120',
'sortable' => 'false',
'wrap_cell' => 'true',
];
$column_model[] = $col;
$columns[] = $extra['3'];
}
}
if (api_is_student_boss()) {
$column_model[] = ['name' => 'group', 'index' => 'group', 'width' => '50', 'align' => 'left', 'sortable' => 'false'];
$column_model[] = [
'name' => 'group',
'index' => 'group',
'width' => '50',
'align' => 'left',
'sortable' => 'false',
];
$columns[] = get_lang('Group');
}
@ -76,21 +132,92 @@ $extra_params['height'] = 'auto';
$htmlHeadXtra[] = '<script>
$(function() {
'.Display::grid_js('user_course_report', $url, $columns, $column_model, $extra_params, [], null, true).'
jQuery("#user_course_report").jqGrid("navGrid","#user_course_report_pager",{
view:false,
edit:false,
add:false,
del:false,
search:false,
excel:true
});
'.Display::grid_js(
'user_course_report',
$url,
$columns,
$column_model,
$extra_params,
[],
null,
true
).'
jQuery("#user_course_report").jqGrid("navButtonAdd","#user_course_report_pager", {
caption:"",
onClickButton : function () {
jQuery("#user_course_report").jqGrid("excelExport",{"url":"'.$url.'&export_format=xls"});
}
var added_cols = [];
var original_cols = [];
function clean_cols(grid, added_cols) {
// Cleaning
for (key in added_cols) {
grid.hideCol(key);
}
grid.showCol(\'name\');
grid.showCol(\'display_start_date\');
grid.showCol(\'display_end_date\');
grid.showCol(\'course_title\');
}
function show_cols(grid, added_cols) {
grid.showCol("name").trigger("reloadGrid");
for (key in added_cols) {
grid.showCol(key);
}
}
var grid = $("#user_course_report");
var prmSearch = {
multipleSearch : true,
overlay : false,
width: "auto",
caption: "'.addslashes(get_lang('Search')).'",
formclass: "data_table",
onSearch : function() {
var postdata = grid.jqGrid("getGridParam", "postData");
if (postdata && postdata.filters) {
filters = jQuery.parseJSON(postdata.filters);
clean_cols(grid, added_cols);
added_cols = [];
$.each(filters, function(key, value) {
if (key == "rules") {
$.each(value, function(subkey, subvalue) {
if (subvalue.data == undefined) {
}
added_cols[subvalue.field] = subvalue.field;
});
}
});
show_cols(grid, added_cols);
}
},
onReset: function() {
clean_cols(grid, added_cols);
}
}
grid.jqGrid(
"navGrid",
"#user_course_report_pager",
{
view:false,
edit:false,
add:false,
del:false,
search:true,
excel:true
},
{height:280,reloadAfterSubmit:false}, // edit options
{height:280,reloadAfterSubmit:false}, // add options
{reloadAfterSubmit:false},
prmSearch
);
grid.searchGrid(prmSearch);
grid.jqGrid("navButtonAdd","#user_course_report_pager", {
caption:"",
onClickButton : function () {
grid.jqGrid("excelExport",{"url":"'.$url.'&export_format=xls"});
}
});
});
</script>';
@ -127,7 +254,7 @@ if (!empty($actions)) {
$content .= $actions;
}
$content .= Display::url(
get_lang("CompanyReportResumed"),
get_lang('CompanyReportResumed'),
api_get_path(WEB_CODE_PATH)."mySpace/company_reports_resumed.php",
[
'class' => 'btn btn-success',
@ -136,7 +263,6 @@ $content .= Display::url(
$content .= '</div>';
$content .= '<h1 class="page-header">'.get_lang('CompanyReport').'</h1>';
$content .= Display::grid_html('user_course_report');
$tpl = new Template($tool_name);
$tpl->assign('content', $content);
$tpl->display_one_col_template();

@ -184,7 +184,7 @@ $orderUrl = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=order';
// Cleaning
for (key in added_cols) {
grid.hideCol(key);
};
}
grid.showCol('name');
grid.showCol('display_start_date');
grid.showCol('display_end_date');
@ -195,7 +195,7 @@ $orderUrl = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=order';
grid.showCol('name').trigger('reloadGrid');
for (key in added_cols) {
grid.showCol(key);
};
}
}
var second_filters = [];
@ -254,37 +254,36 @@ $orderUrl = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=order';
?>
setSearchSelect("status");
var grid = $("#sessions"),
prmSearch = {
multipleSearch : true,
overlay : false,
width: 'auto',
caption: '<?php echo addslashes(get_lang('Search')); ?>',
formclass:'data_table',
onSearch : function() {
var postdata = grid.jqGrid('getGridParam', 'postData');
if (postdata && postdata.filters) {
filters = jQuery.parseJSON(postdata.filters);
clean_cols(grid, added_cols);
added_cols = [];
$.each(filters, function(key, value) {
if (key == 'rules') {
$.each(value, function(subkey, subvalue) {
if (subvalue.data == undefined) {
}
added_cols[subvalue.field] = subvalue.field;
});
}
});
show_cols(grid, added_cols);
}
},
onReset: function() {
var grid = $("#sessions");
var prmSearch = {
multipleSearch : true,
overlay : false,
width: 'auto',
caption: '<?php echo addslashes(get_lang('Search')); ?>',
formclass:'data_table',
onSearch : function() {
var postdata = grid.jqGrid('getGridParam', 'postData');
if (postdata && postdata.filters) {
filters = jQuery.parseJSON(postdata.filters);
clean_cols(grid, added_cols);
added_cols = [];
$.each(filters, function(key, value) {
if (key == 'rules') {
$.each(value, function(subkey, subvalue) {
if (subvalue.data == undefined) {
}
added_cols[subvalue.field] = subvalue.field;
});
}
});
show_cols(grid, added_cols);
}
};
},
onReset: function() {
clean_cols(grid, added_cols);
}
};
original_cols = grid.jqGrid('getGridParam', 'colModel');
@ -333,7 +332,15 @@ $orderUrl = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=order';
searchDialogAll.addClass("table");
var searchDialog = $("#searchmodfbox_"+grid[0].id);
searchDialog.addClass("ui-jqgrid ui-widget ui-widget-content ui-corner-all");
searchDialog.css({position:"adsolute", "z-index":"100", "float":"left", "top":"55%", "left" : "25%", "padding" : "5px", "border": "1px solid #CCC"})
searchDialog.css({
position: "absolute",
"z-index": "100",
"float": "left",
"top": "55%",
"left": "25%",
"padding": "5px",
"border": "1px solid #CCC"
})
var gbox = $("#gbox_"+grid[0].id);
gbox.before(searchDialog);
gbox.css({clear:"left"});

Loading…
Cancel
Save