Cleaning exercise report see #5179

skala
Julio Montoya 14 years ago
parent a0b75c8835
commit dc6d48d058
  1. 168
      main/exercice/exercise.lib.php
  2. 22
      main/inc/ajax/model.ajax.php
  3. 17
      main/inc/lib/course.lib.php
  4. 20
      main/inc/lib/groupmanager.lib.php

@ -793,24 +793,17 @@ function get_session_time_control_key($exercise_id) {
/**
* Gets count of exam results
* @todo this function should be moved in a library + no global calls
* Modified by hubert borderiou 08-11-2011
*/
function get_count_exam_results($exercise_id) {
// I know it's bad to add a static integer here... but
// it factorise function get_exam_results_data
// and I think it worths it.
//This is not bad for the hardcoded value, this is bad because you call 2 times get_exam_results_data()! jm
//@todo use a real count select I know the sql constructions are
$tabres = get_exam_results_data(0, 9999999, 0, "ASC", $exercise_id);
return count($tabres);
function get_count_exam_results($exercise_id, $extra_where_conditions) {
$count = get_exam_results_data(null, null, null, null, $exercise_id, $extra_where_conditions, true);
return $count;
}
/**
* Gets the exam'data results
* @todo this function should be moved in a library + no global calls
*/
function get_exam_results_data($from, $number_of_items, $column, $direction, $exercise_id, $extra_where_conditions = null) {
function get_exam_results_data($from, $number_of_items, $column, $direction, $exercise_id, $extra_where_conditions = null, $get_count = false) {
//@todo replace all this globals
global $documentPath, $filter;
@ -913,8 +906,11 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex
$sqlWhereOption = " AND gru.c_id = ".api_get_course_int_id()." AND gru.user_id = user.user_id ";
$first_and_last_name = api_is_western_name_order() ? "firstname, lastname" : "lastname, firstname";
$sql = "SELECT DISTINCT
if ($get_count) {
$sql_select = "SELECT count(te.exe_id) ";
} else {
$sql_select = "SELECT DISTINCT
user_id,
$first_and_last_name,
ce.title,
@ -929,31 +925,39 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex
exe_user_id,
te.exe_duration,
propagate_neg,
revised,
revised,
group_name,
group_id
FROM
$TBL_EXERCICES AS ce
group_id";
}
$sql = " $sql_select
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 te.exe_cours_id='" . api_get_course_id() . "' $session_id_and
AND ce.active <>-1
AND orig_lp_id = 0
AND orig_lp_item_id = 0
AND ce.c_id=".api_get_course_int_id()."
$exercise_where ";
//var_dump($sql);
// sql for hotpotatoes tests for teacher / tutor view
$hpsql = "SELECT
// sql for hotpotatoes tests for teacher / tutor view
if ($get_count) {
$hpsql_select = "SELECT count(username)";
} else {
$hpsql_select = "SELECT
$first_and_last_name ,
username,
tth.exe_name,
tth.exe_result ,
tth.exe_weighting,
tth.exe_date
tth.exe_date";
}
$hpsql = " $hpsql_select
FROM
$TBL_TRACK_HOTPOTATOES tth,
$TBL_USER user
@ -967,47 +971,12 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex
ORDER BY
tth.exe_cours_id ASC,
tth.exe_date DESC";
} else {
//any view is proposed to the student, they should see the results in the overview.php page
exit;
// Student view
/*
$sql = "SELECT DISTINCT
te.exe_duration,
te.start_date,
firstname,
lastname,
te.exe_result,
te.exe_weighting,
te.exe_date,
te.exe_id,
email as exemail,
steps_counter,
exe_user_id,
ce.results_disabled,
propagate_neg,
revised
FROM
$TBL_EXERCICES AS ce
INNER JOIN $sql_inner_join_tbl_track_exercices AS te ON (te.exe_exo_id = ce.id)
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()."'
AND te.exe_user_id = ".api_get_user_id()." $session_id_and
AND ce.active <>-1
AND orig_lp_id = 0
AND orig_lp_item_id = 0
AND ce.c_id = ".api_get_course_int_id()."
$exercise_where";
$hpsql = "SELECT '', '', '', exe_name, exe_result , exe_weighting, exe_date
FROM $TBL_TRACK_HOTPOTATOES
WHERE exe_user_id = '" . api_get_user_id() . "' AND exe_cours_id = '" . api_get_course_id() . "' $hotpotatoe_where
ORDER BY exe_cours_id ASC, exe_date DESC";
*/
}
if ($get_count) {
$resx = Database::query($sql);
$rowx = Database::fetch_row($resx,'ASSOC');
return $rowx[0];
}
$teacher_list = CourseManager::get_teacher_list_from_course_code(api_get_course_id());
@ -1016,19 +985,18 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex
$teacher_id_list[] = $teacher['user_id'];
}
if (empty($hotpotatoe_where)) {
//Simple exercises
if (empty($hotpotatoe_where)) {
$column = !empty($column) ? Database::escape_string($column) : null;
$from = intval($from);
$number_of_items = intval($number_of_items);
if (!empty($column)) {
$sql .= " ORDER BY $column $direction ";
$sql .= " ORDER BY $column $direction ";
}
$sql .= " LIMIT $from, $number_of_items";
$sq .= " LIMIT $from, $number_of_items";
$results = array();
$results = array();
$resx = Database::query($sql);
while ($rowx = Database::fetch_array($resx,'ASSOC')) {
$results[] = $rowx;
@ -1045,12 +1013,12 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex
$sizeof = count($results);
$user_list_id = array ();
$duration_list = '';
$locked = api_resource_is_locked_by_gradebook($exercise_id, LINK_EXERCISE);
$group_list_info = array();
//Looping results
for ($i = 0; $i < $sizeof; $i++) {
$revised = $results[$i]['revised'];
@ -1060,15 +1028,8 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex
}
$users_array_id[] = $results[$i]['username'] . $results[$i]['firstname'] . $results[$i]['lastname'];
}
if ($is_allowedToEdit || $is_tutor) {
$user = $results[$i]['firstname'] . $results[$i]['lastname'];
$user_groups = displayGroupsForUser('<br/>', $results[$i]['user_id']);
} else {
$user = $results[$i]['firstname'] . $results[$i]['lastname'];
}
//Add all groups by user
$group_name_list = null;
if ($is_empty_sql_inner_join_tbl_user) {
@ -1078,7 +1039,7 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex
if (!isset($group_list_info[$id])) {
$result = GroupManager::get_group_properties($id);
$group_list_info[$id] = $result;
}
}
$group_name_list .= $group_list_info[$id]['name'].' ';
}
$results[$i]['group_name'] = $group_name_list;
@ -1092,46 +1053,14 @@ function get_exam_results_data($from, $number_of_items, $column, $direction, $ex
$dt = api_convert_and_format_date($results[$i]['exe_weighting']);
// we filter the results if we have the permission to
if (isset ($results[$i]['results_disabled']))
if (isset($results[$i]['results_disabled'])) {
$result_disabled = intval($results[$i]['results_disabled']);
else
} else {
$result_disabled = 0;
}
if ($result_disabled == 0) {
if ($is_allowedToEdit || $is_tutor) {
$user = $results[$i]['firstname'] . $results[$i]['lastname'];
$start_date = $results[$i]['start_date'];
} else {
$start_date = $results[$i]['start_date'];
}
if ($start_date != "0000-00-00 00:00:00") {
$start_date_timestamp = api_strtotime($start_date, 'UTC');
$exe_date_timestamp = api_strtotime($results[$i]['exe_date'], 'UTC');
$my_duration = ceil((($exe_date_timestamp - $start_date_timestamp) / 60));
//var_dump($start_date .' - '.$results[$i]['exdate'].' - '.$my_duration);
if ($my_duration == 1 ) {
$duration_list = $my_duration . ' ' . get_lang('MinMinute');
} else {
$duration_list = $my_duration. ' ' . get_lang('MinMinutes');
}
if ($results[$i]['exstep'] > 1) {
$duration_list = ' ( ' . $results[$i]['steps_counter'] . ' ' . get_lang('Steps') . ' )';
}
} else {
$duration_list = get_lang('NoLogOfDuration');
}
// Date conversion
if ($result_disabled == 0) {
// there are already a duration test period calculated??
//echo '<td>'.sprintf(get_lang('DurationFormat'), $duration).'</td>';
// if the float look like 10.00 we show only 10
$my_res = $results[$i]['exe_result'];
$my_total = $results[$i]['exe_weighting'];
@ -1788,7 +1717,10 @@ function displayGroupMenu($in_name, $in_default, $in_onchange="") {
}
/* Return a list of group for user with user_id=in_userid separated with in_separator */
/**
* Return a list of group for user with user_id=in_userid separated with in_separator
* @deprecated ?
*/
function displayGroupsForUser($in_separator, $in_userid) {
$res = implode($in_separator, GroupManager::get_user_group_name($in_userid));
if ($res == "") {

@ -105,7 +105,16 @@ switch ($action) {
case 'get_exercise_results':
require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
$exercise_id = $_REQUEST['exerciseId'];
$count = get_count_exam_results($exercise_id);
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'";
}
}
$count = get_count_exam_results($exercise_id, $where_condition);
break;
case 'get_sessions':
$count = SessionManager::get_count_admin();
@ -188,16 +197,7 @@ switch ($action) {
$columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_duration', 'start_date', 'exe_date', 'score','status','actions');
} else {
//$columns = array('exe_duration', 'start_date', 'exe_date', 'score', 'status', 'actions');
}
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'";
}
}
}
$result = get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition);
break;
case 'get_sessions':

@ -1345,17 +1345,14 @@ class CourseManager {
* @return array with user id
*/
public static function get_teacher_list_from_course_code($course_code) {
$course_code = Database::escape_string($course_code);
// teachers directly subscribed to the course
$teachers = array();
// TODO: This query is not optimal.
$rs = Database::query("SELECT u.user_id, u.lastname, u.firstname, u.email, u.username, u.status " .
"FROM ".Database::get_main_table(TABLE_MAIN_COURSE_USER)." cu, ".Database::get_main_table(TABLE_MAIN_USER)." u ".
"WHERE cu.course_code = '$course_code' " .
"AND cu.status = 1 " .
"AND cu.user_id = u.user_id");
$teachers = array();
$sql = "SELECT u.user_id, u.lastname, u.firstname, u.email, u.username, u.status
FROM ".Database::get_main_table(TABLE_MAIN_COURSE_USER)." cu INNER JOIN ".Database::get_main_table(TABLE_MAIN_USER)." u
ON (cu.user_id = u.user_id)
WHERE cu.course_code = '$course_code' AND
cu.status = 1 ";
$rs = Database::query($sql);
while ($teacher = Database::fetch_array($rs)) {
$teachers[$teacher['user_id']] = $teacher;
}

@ -1588,18 +1588,18 @@ class GroupManager {
* Get all groups where a specific user is subscribed
*/
public static function get_user_group_name ($user_id) {
$table_group_user=Database::get_course_table(TABLE_GROUP_USER);
$table_group=Database::get_course_table(TABLE_GROUP);
$user_id = Database::escape_string($user_id);
$course_id = api_get_course_int_id();
$sql_groups = 'SELECT name FROM '.$table_group.' g,'.$table_group_user.' gu
WHERE gu.c_id= '.$course_id.' AND g.c_id='.$course_id.' AND gu.user_id="'.$user_id.'" AND gu.group_id=g.id';
$table_group_user = Database::get_course_table(TABLE_GROUP_USER);
$table_group = Database::get_course_table(TABLE_GROUP);
$user_id = intval($user_id);
$course_id = api_get_course_int_id();
$sql_groups = "SELECT name FROM $table_group g INNER JOIN $table_group_user gu
ON (gu.group_id=g.id)
WHERE gu.c_id= $course_id AND
g.c_id= $course_id AND
gu.user_id = $user_id";
$res = Database::query($sql_groups);
$groups=array();
while($group = Database::fetch_array($res)) {
while ($group = Database::fetch_array($res)) {
$groups[] .= $group['name'];
}
return $groups;

Loading…
Cancel
Save