Fixing $whereCondition query.

1.9.x
Julio Montoya 11 years ago
parent 3febc10e3a
commit 1536839d6c
  1. 17
      main/exercice/exercise.lib.php
  2. 24
      main/exercice/live_stats.php
  3. 6
      main/exercice/question.class.php
  4. 59
      main/exercice/stats.php
  5. 161
      main/inc/ajax/model.ajax.php
  6. 79
      main/inc/lib/sessionmanager.lib.php
  7. 36
      main/work/work.lib.php

@ -968,10 +968,6 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex
//@todo replace all this globals
global $documentPath, $filter;
if (empty($extra_where_conditions)) {
$extra_where_conditions = "1 = 1 ";
}
$course_id = api_get_course_int_id();
$course_code = api_get_course_id();
@ -1106,12 +1102,13 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex
FROM $TBL_EXERCICES AS ce
INNER JOIN $sql_inner_join_tbl_track_exercices AS te ON (te.exe_exo_id = ce.id)
INNER JOIN $sql_inner_join_tbl_user AS user ON (user.user_id = exe_user_id)
WHERE $extra_where_conditions AND
te.status != 'incomplete'
AND te.exe_cours_id='" . api_get_course_id() . "' $session_id_and
AND ce.active <>-1
AND ce.c_id=".api_get_course_int_id()."
$exercise_where ";
WHERE
te.status != 'incomplete' AND
te.exe_cours_id='" . api_get_course_id() . "' $session_id_and AND
ce.active <>-1 AND ce.c_id=".api_get_course_int_id()."
$exercise_where
$extra_where_conditions
";
// sql for hotpotatoes tests for teacher / tutor view

@ -21,8 +21,8 @@ $objExercise = new Exercise();
$result = $objExercise->read($exercise_id);
if (!$result) {
api_not_allowed(true);
}
api_not_allowed(true);
}
$interbreadcrumb[] = array ("url" => "exercice.php?gradebook=$gradebook", "name" => get_lang('Exercices'));
$interbreadcrumb[] = array ("url" => "admin.php?exerciseId=$exercise_id","name" => $objExercise->name);
@ -38,7 +38,7 @@ Display::display_header(get_lang('StudentsWhoAreTakingTheExerciseRightNow'));
$minutes = 60;
$url = api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?a=get_live_stats&exercise_id='.$objExercise->id.'&minutes='.$minutes;
//The order is important you need to check the the $column variable in the model.ajax.php file
//The order is important you need to check the the $column variable in the model.ajax.php file
$columns = array(get_lang('FirstName'), get_lang('LastName'), get_lang('Time'), get_lang('QuestionsAlreadyAnswered'), get_lang('Score'));
//Column config
@ -48,20 +48,20 @@ $column_model = array(
array('name'=>'start_date', 'index'=>'start_date', 'width'=>'100', 'align'=>'left'),
array('name'=>'question', 'index'=>'count_questions', 'width'=>'60', 'align'=>'left', 'sortable'=>'false'),
array('name'=>'score', 'index'=>'score', 'width'=>'50', 'align'=>'left','sortable'=>'false'),
);
//Autowidth
);
//Autowidth
$extra_params['autowidth'] = 'true';
//height auto
$extra_params['height'] = 'auto';
//height auto
$extra_params['height'] = 'auto';
/*
//With this function we can add actions to the jgrid (edit, delete, etc)
$action_links = 'function action_formatter(cellvalue, options, rowObject) {
return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
'&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?action=copy&id=\'+options.rowId+\'">'.Display::return_icon('copy.png',get_lang('Copy'),'',ICON_SIZE_SMALL).'</a>'.
'&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>'.
'\';
'\';
}';
*/
*/
?>
<script>
@ -72,8 +72,8 @@ function refreshGrid() {
}
$(function() {
<?php
echo Display::grid_js('live_stats', $url, $columns, $column_model, $extra_params, array(), $action_links,true);
<?php
echo Display::grid_js('live_stats', $url, $columns, $column_model, $extra_params, array(), null, true);
?>
refreshGrid();
});
@ -85,6 +85,6 @@ echo $actions = Display::div($actions, array('class'=> 'actions'));
//echo Display::page_header($objExercise->name);
//echo Display::page_header(get_lang('StudentsWhoAreTakingTheExerciseRightNow'));
echo Display::grid_html('live_stats');
echo Display::grid_html('live_stats');
Display::display_footer();

@ -1541,12 +1541,10 @@ abstract class Question
* Get course medias
* @param int course id
*/
static function get_course_medias($course_id, $start = 0, $limit = 100, $sidx = "question", $sord = "ASC", $where_condition = array()) {
static function get_course_medias($course_id, $start = 0, $limit = 100, $sidx = "question", $sord = "ASC", $where_condition = array())
{
$table_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
$default_where = array('c_id = ? AND parent_id = 0 AND type = ?' => array($course_id, MEDIA_QUESTION));
if (!empty($where_condition)) {
//$where_condition
}
$result = Database::select('*', $table_question,
array(
'limit' => " $start, $limit",

@ -10,6 +10,7 @@ require_once 'exercise.lib.php';
$this_section = SECTION_COURSES;
$exercise_id = (isset($_GET['exerciseId']) && !empty($_GET['exerciseId'])) ? intval($_GET['exerciseId']) : 0;
$gradebook = isset($gradebook) ? $gradebook : null;
$objExercise = new Exercise();
$result = $objExercise->read($exercise_id);
@ -45,7 +46,7 @@ $headers = array(
if (!empty($question_list)) {
foreach ($question_list as $question_id) {
$question_obj = Question::read($question_id);
$exercise_stats = get_student_stats_by_question($question_id, $exercise_id, api_get_course_id(), api_get_session_id());
$exercise_stats = get_student_stats_by_question($question_id, $exercise_id, api_get_course_id(), api_get_session_id());
$count_users = get_number_students_question_with_answer_count($question_id, $exercise_id, api_get_course_id(), api_get_session_id());
$data[$question_id]['name'] = cut($question_obj->question, 100);
@ -55,9 +56,9 @@ if (!empty($question_list)) {
if ($count_students) {
$percentange = $count_users/$count_students*100;
}
$data[$question_id]['students_who_try_exercise'] = Display::bar_progress($percentange, false, $count_users .' / '.$count_students);
$data[$question_id]['lowest_score'] = round($exercise_stats['min'], 2);
$data[$question_id]['average_score'] = round($exercise_stats['average'], 2);
$data[$question_id]['highest_score'] = round($exercise_stats['max'], 2);
@ -92,7 +93,7 @@ $headers = array(
get_lang('Question'),
get_lang('Answer'),
get_lang('Correct'),
get_lang('NumberStudentWhoSelectedIt')
get_lang('NumberStudentWhoSelectedIt')
);
$data = array();
@ -105,20 +106,20 @@ if (!empty($question_list)) {
$answer = new Answer($question_id);
$answer_count = $answer->selectNbrAnswers();
for ($answer_id = 1; $answer_id <= $answer_count; $answer_id++) {
$answer_info = $answer->selectAnswer($answer_id);
$is_correct = $answer->isCorrect($answer_id);
$correct_answer = $is_correct == 1 ? get_lang('Yes') : get_lang('No');
$real_answer_id = $answer->selectAutoId($answer_id);
//$data[$id]['name'] .=$answer_count;
//Overwriting values depending of the question
switch ($question_obj->type) {
case FILL_IN_BLANKS :
$answer_info_db = $answer_info;
$answer_info = substr($answer_info, 0, strpos($answer_info, '::'));
$correct_answer = $is_correct;
$correct_answer = $is_correct;
$answers = $objExercise->fill_in_blank_answer_to_array($answer_info);
$counter = 0;
foreach ($answers as $answer_item) {
@ -127,36 +128,36 @@ if (!empty($question_list)) {
} else {
$data[$id]['name'] = '-';
}
$data[$id]['answer'] = $answer_item;
$data[$id]['answer'] = $answer_item;
$answer_item = api_substr($answer_item, 1);
$answer_item = api_substr($answer_item, 0, api_strlen($answer_item) -1);
$data[$id]['correct'] = '-';
$count = get_number_students_answer_count($real_answer_id, $question_id, $exercise_id, api_get_course_id(), api_get_session_id(), FILL_IN_BLANKS, $answer_info_db, $answer_item);
$percentange = 0;
if (!empty($count_students)) {
$percentange = $count/$count_students*100;
}
$data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students);
$id++;
$counter++;
$counter++;
}
break;
case MATCHING:
if ($is_correct == 0) {
if ($answer_id == 1) {
if ($is_correct == 0) {
if ($answer_id == 1) {
$data[$id]['name'] = cut($question_obj->question, 100);
} else {
$data[$id]['name'] = '-';
}
}
$correct = '';
for ($i = 1; $i <= $answer_count; $i++) {
$is_correct_i = $answer->isCorrect($i);
$is_correct_i = $answer->isCorrect($i);
if ($is_correct_i != 0 && $is_correct_i == $answer_id) {
$correct = $answer->selectAnswer($i);
break;
@ -164,50 +165,50 @@ if (!empty($question_list)) {
}
$data[$id]['answer'] = $correct;
$data[$id]['correct'] = $answer_info;
$count = get_number_students_answer_count($answer_id, $question_id, $exercise_id, api_get_course_id(), api_get_session_id(), MATCHING);
$percentange = 0;
if (!empty($count_students)) {
$percentange = $count/$count_students*100;
}
$data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students);
}
}
break;
case HOT_SPOT:
if ($answer_id == 1) {
if ($answer_id == 1) {
$data[$id]['name'] = cut($question_obj->question, 100);
} else {
$data[$id]['name'] = '-';
}
$data[$id]['answer'] = $answer_info;
$data[$id]['correct'] = '-';
$count = get_number_students_answer_hotspot_count($answer_id, $question_id, $exercise_id, api_get_course_id(), api_get_session_id());
$count = get_number_students_answer_hotspot_count($answer_id, $question_id, $exercise_id, api_get_course_id(), api_get_session_id());
$percentange = 0;
if (!empty($count_students)) {
$percentange = $count/$count_students*100;
}
$data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students);
$data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students);
break;
default:
if ($answer_id == 1) {
if ($answer_id == 1) {
$data[$id]['name'] = cut($question_obj->question, 100);
} else {
$data[$id]['name'] = '-';
}
$data[$id]['answer'] = $answer_info;
$data[$id]['correct'] = $correct_answer;
$count = get_number_students_answer_count($real_answer_id, $question_id, $exercise_id, api_get_course_id(), api_get_session_id());
$percentange = 0;
if (!empty($count_students)) {
$percentange = $count/$count_students*100;
}
$data[$id]['attempts'] = Display::bar_progress($percentange, false, $count .' / '.$count_students);
}
}
$id++;
}
}
}

@ -56,31 +56,32 @@ if (!in_array(
// Search features
$ops = array (
'eq' => '=', //equal
'ne' => '<>', //not equal
'lt' => '<', //less than
'le' => '<=', //less than or equal
'gt' => '>', //greater than
'ge' => '>=', //greater than or equal
'bw' => 'LIKE', //begins with
'bn' => 'NOT LIKE', //doesn't begin with
'in' => 'LIKE', //is in
'ni' => 'NOT LIKE', //is not in
'ew' => 'LIKE', //ends with
'en' => 'NOT LIKE', //doesn't end with
'cn' => 'LIKE', //contains
'nc' => 'NOT LIKE' //doesn't contain
);
//@todo move this in the display_class or somewhere else
function get_where_clause($col, $oper, $val)
function getWhereClause($col, $oper, $val)
{
global $ops;
$ops = array(
'eq' => '=', //equal
'ne' => '<>', //not equal
'lt' => '<', //less than
'le' => '<=', //less than or equal
'gt' => '>', //greater than
'ge' => '>=', //greater than or equal
'bw' => 'LIKE', //begins with
'bn' => 'NOT LIKE', //doesn't begin with
'in' => 'LIKE', //is in
'ni' => 'NOT LIKE', //is not in
'ew' => 'LIKE', //ends with
'en' => 'NOT LIKE', //doesn't end with
'cn' => 'LIKE', //contains
'nc' => 'NOT LIKE' //doesn't contain
);
if (empty($col)) {
return '';
}
if ($oper == 'bw' || $oper == 'bn') {
$val .= '%';
}
@ -91,40 +92,41 @@ function get_where_clause($col, $oper, $val)
$val = '%'.$val.'%';
}
$val = Database::escape_string($val);
return " $col {$ops[$oper]} '$val' ";
}
//if there is no search request sent by jqgrid, $where should be empty
$where_condition = "";
// If there is no search request sent by jqgrid, $where should be empty
$whereCondition = null;
$operation = isset($_REQUEST['oper']) ? $_REQUEST['oper'] : false;
$export_format = isset($_REQUEST['export_format']) ? $_REQUEST['export_format'] : 'csv';
$search_field = isset($_REQUEST['searchField']) ? $_REQUEST['searchField'] : false;
$search_oper = isset($_REQUEST['searchOper']) ? $_REQUEST['searchOper'] : false;
$search_string = isset($_REQUEST['searchString']) ? $_REQUEST['searchString'] : false;
$exportFormat = isset($_REQUEST['export_format']) ? $_REQUEST['export_format'] : 'csv';
$searchField = isset($_REQUEST['searchField']) ? $_REQUEST['searchField'] : false;
$searchOperator = isset($_REQUEST['searchOper']) ? $_REQUEST['searchOper'] : false;
$searchString = isset($_REQUEST['searchString']) ? $_REQUEST['searchString'] : false;
$search = isset($_REQUEST['_search']) ? $_REQUEST['_search'] : false;
$forceSearch = isset($_REQUEST['_force_search']) ? $_REQUEST['_force_search'] : false;
if ($search || $forceSearch) {
$where_condition = ' 1 = 1 ';
$where_condition_in_form = get_where_clause($search_field, $search_oper, $search_string);
$whereConditionInForm = getWhereClause($searchField, $searchOperator, $searchString);
if (!empty($where_condition_in_form)) {
$where_condition .= ' AND '.$where_condition_in_form;
if (!empty($whereConditionInForm)) {
$whereCondition .= ' AND '.$whereConditionInForm;
}
$filters = isset($_REQUEST['filters']) ? json_decode($_REQUEST['filters']) : false;
if (!empty($filters)) {
$where_condition .= ' AND ( ';
$whereCondition .= ' AND ( ';
$counter = 0;
foreach ($filters->rules as $key => $rule) {
$where_condition .= get_where_clause($rule->field, $rule->op, $rule->data);
$whereCondition .= getWhereClause($rule->field, $rule->op, $rule->data);
if ($counter < count($filters->rules) -1) {
$where_condition .= $filters->groupOp;
$whereCondition .= $filters->groupOp;
}
$counter++;
}
$where_condition .= ' ) ';
$whereCondition .= ' ) ';
}
}
@ -181,11 +183,11 @@ switch ($action) {
break;
case 'get_work_teacher':
require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
$count = getWorkListTeacher(0, $limit, $sidx, $sord, $where_condition, true);
$count = getWorkListTeacher(0, $limit, $sidx, $sord, $whereCondition, true);
break;
case 'get_work_student':
require_once api_get_path(SYS_CODE_PATH).'work/work.lib.php';
$count = getWorkListStudent(0, $limit, $sidx, $sord, $where_condition, true);
$count = getWorkListStudent(0, $limit, $sidx, $sord, $whereCondition, true);
break;
case 'get_work_user_list_all':
@ -205,8 +207,8 @@ switch ($action) {
$documents = getAllDocumentToWork($work_id, api_get_course_int_id());
if (empty($documents)) {
$where_condition .= " AND u.user_id = ".api_get_user_id();
$count = get_work_user_list(0, $limit, $sidx, $sord, $work_id, $where_condition, null, true);
$whereCondition .= " AND u.user_id = ".api_get_user_id();
$count = get_work_user_list(0, $limit, $sidx, $sord, $work_id, $whereCondition, null, true);
} else {
$count = get_work_user_list_from_documents(
0,
@ -215,7 +217,7 @@ switch ($action) {
$sord,
$work_id,
api_get_user_id(),
$where_condition,
$whereCondition,
true
);
}
@ -244,13 +246,9 @@ switch ($action) {
if (isset($_GET['filter_by_user']) && !empty($_GET['filter_by_user'])) {
$filter_user = intval($_GET['filter_by_user']);
if ($where_condition == "") {
$where_condition .= " te.exe_user_id = '$filter_user'" ;
} else {
$where_condition .= " AND te.exe_user_id = '$filter_user'";
}
$whereCondition .= " AND te.exe_user_id = '$filter_user'";
}
$count = get_count_exam_results($exercise_id, $where_condition);
$count = get_count_exam_results($exercise_id, $whereCondition);
break;
case 'get_hotpotatoes_exercise_results':
require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
@ -268,9 +266,9 @@ switch ($action) {
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";
$whereCondition .= " AND c.id = $courseId";
}
$count = SessionManager::get_count_admin($where_condition);
$count = SessionManager::get_count_admin($whereCondition);
break;
case 'get_session_lp_progress':
case 'get_session_progress':
@ -378,7 +376,7 @@ $columns = array();
switch ($action) {
case 'get_course_exercise_medias':
$columns = array('question');
$result = Question::get_course_medias($course_id, $start, $limit, $sidx, $sord, $where_condition);
$result = Question::get_course_medias($course_id, $start, $limit, $sidx, $sord, $whereCondition);
break;
case 'get_user_course_report_resumed':
$columns = array(
@ -471,7 +469,7 @@ switch ($action) {
break;
case 'get_user_skill_ranking':
$columns = array('photo', 'firstname', 'lastname', 'skills_acquired', 'currently_learning', 'rank');
$result = $skill->get_user_list_skill_ranking($start, $limit, $sidx, $sord, $where_condition);
$result = $skill->get_user_list_skill_ranking($start, $limit, $sidx, $sord, $whereCondition);
$result = msort($result, 'skills_acquired', 'asc');
$skills_in_course = array();
@ -495,11 +493,11 @@ switch ($action) {
break;
case 'get_work_teacher':
$columns = array('type', 'title', 'sent_date', 'expires_on', 'ends_on', 'actions');
$result = getWorkListTeacher($start, $limit, $sidx, $sord, $where_condition);
$result = getWorkListTeacher($start, $limit, $sidx, $sord, $whereCondition);
break;
case 'get_work_student':
$columns = array('type', 'title', 'expires_on', 'others', 'actions');
$result = getWorkListStudent($start, $limit, $sidx, $sord, $where_condition);
$result = getWorkListStudent($start, $limit, $sidx, $sord, $whereCondition);
break;
case 'get_work_user_list_all':
if (isset($_GET['type']) && $_GET['type'] == 'simple') {
@ -509,7 +507,7 @@ switch ($action) {
} else {
$columns = array('type', 'firstname', 'lastname', 'title', 'sent_date', 'actions');
}
$result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $where_condition);
$result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $whereCondition);
break;
case 'get_work_user_list_others':
if (isset($_GET['type']) && $_GET['type'] == 'simple') {
@ -519,8 +517,8 @@ switch ($action) {
} else {
$columns = array('type', 'firstname', 'lastname', 'title', 'sent_date', 'actions');
}
$where_condition .= " AND u.user_id <> ".api_get_user_id();
$result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $where_condition);
$whereCondition .= " AND u.user_id <> ".api_get_user_id();
$result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $whereCondition);
break;
case 'get_work_user_list':
if (isset($_GET['type']) && $_GET['type'] == 'simple') {
@ -534,8 +532,8 @@ switch ($action) {
$documents = getAllDocumentToWork($work_id, api_get_course_int_id());
if (empty($documents)) {
$where_condition .= " AND u.user_id = ".api_get_user_id();
$result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $where_condition);
$whereCondition .= " AND u.user_id = ".api_get_user_id();
$result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $whereCondition);
} else {
$result = get_work_user_list_from_documents(
$start,
@ -544,7 +542,7 @@ switch ($action) {
$sord,
$work_id,
api_get_user_id(),
$where_condition
$whereCondition
);
}
break;
@ -557,7 +555,7 @@ switch ($action) {
'firstname', 'lastname', 'username', 'group_name', 'exe_duration', 'start_date', 'exe_date', 'score', 'status', 'lp', 'actions'
);
}
$result = get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition);
$result = get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $whereCondition);
break;
case 'get_work_student_list_overview':
if (!api_is_allowed_to_edit()) {
@ -587,7 +585,7 @@ switch ($action) {
} else {
$columns = array('exe_date', 'score', 'actions');
}
$result = get_exam_results_hotpotatoes_data($start, $limit, $sidx, $sord, $hotpot_path, $where_condition);
$result = get_exam_results_hotpotatoes_data($start, $limit, $sidx, $sord, $hotpot_path, $whereCondition);
break;
case 'get_sessions_tracking':
if (api_is_drh()) {
@ -647,7 +645,7 @@ switch ($action) {
$result = SessionManager::get_sessions_admin(
array(
'where' => $where_condition,
'where' => $whereCondition,
'order' => "$sidx $sord",
'limit'=> "$start , $limit"
)
@ -679,7 +677,7 @@ switch ($action) {
$result = SessionManager::get_exercise_progress($sessionId, $courseId, $exerciseId, $answer,
array(
'where' => $where_condition,
'where' => $whereCondition,
'order' => "$sidx $sord",
'limit'=> "$start , $limit"
)
@ -687,8 +685,7 @@ switch ($action) {
break;
case 'get_session_lp_progress':
$sessionId = 0;
if (!empty($_GET['session_id']) && !empty($_GET['course_id']))
{
if (!empty($_GET['session_id']) && !empty($_GET['course_id'])) {
$sessionId = intval($_GET['session_id']);
$courseId = intval($_GET['course_id']);
$course = api_get_course_info_by_id($courseId);
@ -712,7 +709,7 @@ switch ($action) {
$result = SessionManager::get_session_lp_progress($sessionId, $courseId,
array(
'where' => $where_condition,
'where' => $whereCondition,
'order' => "$sidx $sord",
'limit'=> "$start , $limit"
)
@ -720,8 +717,10 @@ switch ($action) {
break;
case 'get_survey_overview':
$sessionId = 0;
if (!empty($_GET['session_id']) && !empty($_GET['course_id']) && !empty($_GET['survey_id']))
{
if (!empty($_GET['session_id']) &&
!empty($_GET['course_id']) &&
!empty($_GET['survey_id'])
) {
$sessionId = intval($_GET['session_id']);
$courseId = intval($_GET['course_id']);
$surveyId = intval($_GET['survey_id']);
@ -745,7 +744,7 @@ switch ($action) {
$result = SessionManager::get_survey_overview($sessionId, $courseId, $surveyId,
array(
'where' => $where_condition,
'where' => $whereCondition,
'order' => "$sidx $sord",
'limit'=> "$start , $limit"
)
@ -800,14 +799,13 @@ switch ($action) {
'surveys_progress' ,
);
$sessionId = 0;
if (!empty($_GET['course_id']) && !empty($_GET['session_id']))
{
if (!empty($_GET['course_id']) && !empty($_GET['session_id'])) {
$sessionId = intval($_GET['session_id']);
$courseId = intval($_GET['course_id']);
}
$result = SessionManager::get_session_progress($sessionId, $courseId,
array(
'where' => $where_condition,
'where' => $whereCondition,
'order' => "$sidx $sord",
'limit'=> "$start , $limit"
)
@ -824,8 +822,7 @@ switch ($action) {
'timeLoggedIn',
);
$sessionId = 0;
if (!empty($_GET['course_id']) && !empty($_GET['session_id']))
{
if (!empty($_GET['course_id']) && !empty($_GET['session_id'])) {
$sessionId = intval($_GET['session_id']);
$courseId = intval($_GET['course_id']);
$studentId = intval($_GET['student_id']);
@ -834,9 +831,15 @@ switch ($action) {
$date_to = intval($_GET['date_to']);
}
$result = SessionManager::get_user_data_access_tracking_overview(intval($sessionId), intval($courseId), intval($studentId), intval($profile), $date_to, $date_from,
$result = SessionManager::get_user_data_access_tracking_overview(
$sessionId,
$courseId,
$studentId,
$profile,
$date_to,
$date_from,
array(
'where' => $where_condition,
'where' => $whereCondition,
'order' => "$sidx $sord",
'limit'=> "$start , $limit"
)
@ -852,7 +855,13 @@ switch ($action) {
$result = Database::select(
'*',
$obj->table,
array('where' => array('parent_id = ? AND c_id = ?' => array('0', $course_id)), 'order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit")
array(
'where' => array(
'parent_id = ? AND c_id = ?' => array('0', $course_id)
),
'order'=>"$sidx $sord",
'LIMIT'=> "$start , $limit"
)
);
$new_result = array();
foreach ($result as $item) {
@ -873,7 +882,7 @@ switch ($action) {
if (!in_array($sidx, $columns)) {
$sidx = 'name';
}
$result = Database::select('*', $obj->table, array('order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
$result = Database::select('*', $obj->table, array('order'=>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
$new_result = array();
foreach ($result as $item) {
if ($item['parent_id'] != 0) {
@ -1093,7 +1102,7 @@ if (in_array($action, $allowed_actions)) {
}
$j++;
}
switch ($export_format) {
switch ($exportFormat) {
case 'xls':
//TODO add date if exists
$file_name = (!empty($action)) ? $action : 'company_report';

@ -255,7 +255,7 @@ class SessionManager
$where_condition
);
} else {
$where_condition = "1 = 1";
$where_condition = " AND 1 = 1";
}
$courseCondition = null;
@ -285,7 +285,7 @@ class SessionManager
INNER JOIN $tbl_user u ON s.id_coach = u.user_id
$courseCondition
$extraJoin
$where AND $where_condition ) as session_table";
$where $where_condition ) as session_table";
if (api_is_multiple_url_enabled()) {
@ -311,13 +311,14 @@ class SessionManager
INNER JOIN $table_access_url_rel_session ar ON ar.session_id = s.id
$courseCondition
$extraJoin
$where AND $where_condition) as session_table";
$where $where_condition) as session_table";
}
}
$result_rows = Database::query($sql);
$row = Database::fetch_array($result_rows);
$num = $row['total_rows'];
return $num;
}
@ -525,16 +526,13 @@ class SessionManager
$where = " WHERE a.course_code = '%s'";
if (!empty($sessionId)) {
$where .= " AND a.session_id = %d
AND q.id = %d";
} else
{
$where .= " AND a.session_id = %d AND q.id = %d";
} else {
$where .= " AND q.title = '%s'";
}
//2 = show all questions (wrong and correct answered)
if ($answer != 2)
{
if ($answer != 2) {
$where .= sprintf(' AND qa.correct = %d', $answer);
}
@ -544,7 +542,7 @@ class SessionManager
}
if (!empty($options['where'])) {
$where .= ' AND '.$options['where'];
$where .= ' '.$options['where'];
}
$order = null;
@ -573,20 +571,18 @@ class SessionManager
INNER JOIN $user u ON u.user_id = a.user_id
$where $order $limit";
if (!empty($sessionId))
{
if (!empty($sessionId)) {
$sql_query = sprintf($sql, $course['code'], $sessionId, $exerciseId);
} else
{
} else {
$sql_query = sprintf($sql, $course['code'], $exercise['title']);
}
$rs = Database::query($sql_query);
while ($row = Database::fetch_array($rs))
{
while ($row = Database::fetch_array($rs)) {
$row['correct'] = ($row['correct'] == 1) ? get_lang('Yes') : get_lang('No');
$data[] = $row;
}
return $data;
}
/**
@ -624,7 +620,7 @@ class SessionManager
}
if (!empty($options['where'])) {
$where .= ' AND '.$options['where'];
$where .= ' '.$options['where'];
}
$order = null;
@ -717,7 +713,7 @@ class SessionManager
}
if (!empty($options['where'])) {
$where .= ' AND '.$options['where'];
$where .= ' '.$options['where'];
}
$order = null;
@ -775,6 +771,7 @@ class SessionManager
}
return $table;
}
/**
* Gets the progress of the given session
* @param int session id
@ -783,7 +780,6 @@ class SessionManager
*/
public static function get_session_progress($sessionId, $courseId, $options)
{
//tables
$session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$user = Database::get_main_table(TABLE_MAIN_USER);
@ -817,7 +813,7 @@ class SessionManager
}
if (!empty($options['where'])) {
$where .= ' AND '.$options['where'];
$where .= ' '.$options['where'];
}
$order = null;
@ -1047,6 +1043,7 @@ class SessionManager
$track_e_course_access = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
return Database::count_rows($track_e_course_access);
}
/**
* Get the ip, total of clicks, login date and time logged in for all user, in one session
* @todo track_e_course_access table should have ip so we dont have to look for it in track_e_login
@ -1054,8 +1051,8 @@ class SessionManager
* @author César Perales <cesar.perales@beeznest.com>, Beeznest Team
* @version Chamilo 1.9.6
*/
function get_user_data_access_tracking_overview($sessionId, $courseId, $studentId = 0, $profile = '', $date_from = '', $date_to = '', $options) {
global $_configuration;
function get_user_data_access_tracking_overview($sessionId, $courseId, $studentId = 0, $profile = '', $date_from = '', $date_to = '', $options)
{
// database table definition
$user = Database :: get_main_table(TABLE_MAIN_USER);
$course = Database :: get_main_table(TABLE_MAIN_COURSE);
@ -1063,31 +1060,26 @@ class SessionManager
$track_e_course_access = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
global $export_csv;
if ($export_csv)
{
if ($export_csv) {
$is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
} else {
$is_western_name_order = api_is_western_name_order();
}
if (isset($sessionId) && !empty($sessionId))
{
if (isset($sessionId) && !empty($sessionId)) {
$where = sprintf(" WHERE a.session_id = %d", intval($sessionId));
}
if (isset($courseId) && !empty($courseId))
{
if (isset($courseId) && !empty($courseId)) {
$where .= sprintf(" AND c.id = %d", intval($courseId)) ;
}
if (isset($studentId) && !empty($studentId))
{
if (isset($studentId) && !empty($studentId)) {
$where .= sprintf(" AND u.user_id = %d", intval($studentId));
}
if (isset($profile) && !empty($profile))
{
if (isset($profile) && !empty($profile)) {
$where .= sprintf(" AND u.status = %d", intval($profile));
}
if (!empty($date_to) && !empty($date_from))
{
if (!empty($date_to) && !empty($date_from)) {
//FIX THIS
$to = substr($date_to, 0, 4) .'-' . substr($date_to, 4, 2) . '-' . substr($date_to, 6, 2);
$from = substr($date_from, 0, 4) . '-' . substr($date_from, 4, 2) . '-' . substr($date_from, 6, 2);
@ -1100,7 +1092,7 @@ class SessionManager
}
if (!empty($options['where'])) {
$where .= ' AND '.$options['where'];
$where .= ' '.$options['where'];
}
$order = null;
@ -1119,7 +1111,6 @@ class SessionManager
u.lastname,
u.firstname,
")."
a.logout_course_date,
c.title,
c.code,
@ -1132,14 +1123,12 @@ class SessionManager
$clicks = Tracking::get_total_clicks_by_session();
$data = array ();
while ($user = Database::fetch_assoc($result))
{
while ($user = Database::fetch_assoc($result)) {
$data[] = $user;
}
//foreach
foreach ($data as $key => $info)
{
// Foreach
foreach ($data as $key => $info) {
#building array to display
$return[] = array(
'logindate' => $info['login_course_date'],
@ -1151,9 +1140,9 @@ class SessionManager
'timeLoggedIn' => gmdate("H:i:s", strtotime($info['logout_course_date']) - strtotime($info['login_course_date'])),
);
}
//Search for ip, we do less querys if we iterate the final array
foreach ($return as $key => $info)
{
foreach ($return as $key => $info) {
$sql = sprintf("SELECT login_ip FROM $track_e_login WHERE ('%s' BETWEEN login_date AND logout_date)", $info['logindate']); //TODO add select by user too
$result = Database::query($sql);
$ip = Database::fetch_assoc($result);
@ -3242,6 +3231,10 @@ class SessionManager
}
$courses = explode('|', $enreg['Courses']);
// See BT#6449
if (count($courses) >= 2) {
//
}
foreach ($courses as $course) {
$courseArray = bracketsToArray($course);

@ -1647,10 +1647,6 @@ function getWorkListTeacher($start, $limit, $column, $direction, $where_conditio
$column = !empty($column) ? Database::escape_string($column) : 'sent_date';
$start = intval($start);
$limit = intval($limit);
// check the following until $where_condition is fixed in model.ajax.php +108
if (!empty($where_condition) && substr($where_condition,0,3) != 'AND') {
$where_condition = 'AND '.$where_condition;
}
// Get list from database
if ($is_allowed_to_edit) {
@ -1667,9 +1663,9 @@ function getWorkListTeacher($start, $limit, $column, $direction, $where_conditio
w.c_id = $course_id
$condition_session AND
$active_condition AND
(parent_id = 0)
$where_condition AND
(parent_id = 0) AND
post_group_id = '".$group_id."'
$where_condition
ORDER BY $column $direction
LIMIT $start, $limit";
$result = Database::query($sql);
@ -1691,7 +1687,7 @@ function getWorkListTeacher($start, $limit, $column, $direction, $where_conditio
}
$work['title'] = Display::url($work['title'], $url.'&id='.$workId);
$work['title'] .= ' '.Display::label(get_count_work($work['id']), 'success');
$work['sent_date'] = date_to_str_ago($work['sent_date']).' <br />'.api_get_local_time($work['sent_date']);
$work['sent_date'] = api_get_local_time($work['sent_date']);
$editLink = Display::url(
Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL),
@ -3685,30 +3681,30 @@ function getFormWork($form, $defaults = array())
$form->addElement('checkbox', 'enableEndDate', null, get_lang('EnableEndDate'), 'onclick="javascript: if(this.checked){document.getElementById(\'option3\').style.display = \'block\';}else{document.getElementById(\'option3\').style.display = \'none\';}"');
if (isset($defaults['enableEndDate']) && $defaults['enableEndDate']) {
if (isset($defaults['enableEndDate']) && $defaults['enableEndDate']) {
$form->addElement('html', '<div id="option3" style="display: block;">');
} else {
} else {
$form->addElement('html', '<div id="option3" style="display: none;">');
}
}
$form->addGroup(create_group_date_select($form), 'ends', get_lang('EndsAt'));
$form->addElement('html', '</div>');
$form->addGroup(create_group_date_select($form), 'ends', get_lang('EndsAt'));
$form->addElement('html', '</div>');
$form->addElement('checkbox', 'add_to_calendar', null, get_lang('AddToCalendar'));
$form->addElement('checkbox', 'add_to_calendar', null, get_lang('AddToCalendar'));
//$form->addElement('checkbox', 'allow_text_assignment', null, get_lang('AllowTextAssignments'));
//$form->addElement('checkbox', 'allow_text_assignment', null, get_lang('AllowTextAssignments'));
$form->addElement('select', 'allow_text_assignment', get_lang('DocumentType'), getUploadDocumentType());
$form->addElement('html', '</div>');
$form->addElement('html', '</div>');
if ($defaults['enableExpiryDate'] && $defaults['enableEndDate']) {
if (isset($defaults['enableExpiryDate']) && isset($defaults['enableEndDate'])) {
$form->addRule(array('expires', 'ends'), get_lang('DateExpiredNotBeLessDeadLine'), 'comparedate');
}
if (!empty($defaults)) {
}
if (!empty($defaults)) {
$form->setDefaults($defaults);
}
}
return $form;
return $form;
}
/**

Loading…
Cancel
Save