Minor - format code.

1.9.x
Julio Montoya 11 years ago
parent 77cdde094f
commit fb6f4beae6
  1. 290
      main/exercice/hotpotatoes_exercise_result.class.php

@ -5,56 +5,54 @@
* of type HotpotatoesExerciseResult
* which allows you to export exercises results in multiple presentation forms
* @package chamilo.exercise
* @author
* @version $Id: $
*/
/**
* Code
*/
if(!class_exists('HotpotatoesExerciseResult')):
/**
* Exercise results class
* @package chamilo.exercise
*/
class HotpotatoesExerciseResult
{
private $exercises_list = array(); //stores the list of exercises
private $results = array(); //stores the results
//stores the list of exercises
private $exercises_list = array();
/**
* constructor of the class
*/
public function ExerciseResult($get_questions=false,$get_answers=false) {
}
/**
* Reads exercises information (minimal) from the data base
* @param boolean Whether to get only visible exercises (true) or all of them (false). Defaults to false.
* @return array A list of exercises available
*/
private function _readExercisesList($only_visible = false)
{
$return = array();
$TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST);
//stores the results
private $results = array();
$sql="SELECT id,title,type,random,active FROM $TBL_EXERCISES";
if($only_visible)
{
$sql.= ' WHERE active=1';
}
$sql .= ' ORDER BY title';
$result=Database::query($sql);
// if the exercise has been found
while($row=Database::fetch_array($result,'ASSOC'))
{
$return[] = $row;
}
// exercise not found
return $return;
}
/**
* constructor of the class
*/
public function ExerciseResult($get_questions=false,$get_answers=false)
{
}
/**
* Reads exercises information (minimal) from the data base
* @param boolean Whether to get only visible exercises (true) or all of them (false). Defaults to false.
* @return array A list of exercises available
*/
private function _readExercisesList($only_visible = false)
{
$return = array();
$TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST);
$sql="SELECT id,title,type,random,active FROM $TBL_EXERCISES";
if ($only_visible) {
$sql.= ' WHERE active=1';
}
$sql .= ' ORDER BY title';
$result=Database::query($sql);
// if the exercise has been found
while($row=Database::fetch_array($result,'ASSOC'))
{
$return[] = $row;
}
// exercise not found
return $return;
}
/**
* Gets the results of all students (or just one student if access is limited)
@ -62,99 +60,101 @@ class HotpotatoesExerciseResult
* @param integer User ID. Optional. If no user ID is provided, we take all the results. Defauts to null
*/
// function _getExercisesReporting($document_path, $user_id = null, $filter = 0, $hotpotato_name = null) {
function _getExercisesReporting($document_path, $hotpotato_name) {
function _getExercisesReporting($document_path, $hotpotato_name)
{
$return = array();
$TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST);
$TBL_USER = Database::get_main_table(TABLE_MAIN_USER);
$TBL_TRACK_EXERCISES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$TBL_TRACK_HOTPOTATOES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
$TBL_TRACK_ATTEMPT_RECORDING= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
$cid = api_get_course_id();
$course_id = api_get_course_int_id();
$user_id = intval($user_id);
$session_id_and = ' AND te.session_id = ' . api_get_session_id() . ' ';
$hotpotato_name = Database::escape_string($hotpotato_name);
if (!empty($exercise_id)) {
$session_id_and .= " AND exe_exo_id = $exercise_id ";
}
$TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST);
$TBL_USER = Database::get_main_table(TABLE_MAIN_USER);
$TBL_TRACK_EXERCISES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
$TBL_TRACK_HOTPOTATOES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
$TBL_TRACK_ATTEMPT_RECORDING= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
if (empty($user_id)) {
$sql="SELECT firstname as userpart1, lastname as userpart2 ,
email,
tth.exe_name,
tth.exe_result,
tth.exe_weighting,
tth.exe_date
FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu
WHERE tu.user_id=tth.exe_user_id AND
tth.exe_cours_id = '" . Database :: escape_string($cid) . "' AND
tth.exe_name = '$hotpotato_name'
ORDER BY tth.exe_cours_id ASC, tth.exe_date ASC";
} else {
$user_id_and = ' AND te.exe_user_id = ' . api_get_user_id() . ' ';
// get only this user's results
$sql = "SELECT '', exe_name, exe_result , exe_weighting, exe_date
FROM $TBL_TRACK_HOTPOTATOES
WHERE exe_user_id = '" . $user_id . "' AND
exe_cours_id = '" . Database :: escape_string($cid) . "' AND
tth.exe_name = '$hotpotato_name'
ORDER BY exe_cours_id ASC, exe_date ASC";
}
$cid = api_get_course_id();
$course_id = api_get_course_int_id();
$user_id = intval($user_id);
$session_id_and = ' AND te.session_id = ' . api_get_session_id() . ' ';
$hotpotato_name = Database::escape_string($hotpotato_name);
$results = array();
$resx = Database::query($sql);
while ($rowx = Database::fetch_array($resx,'ASSOC')) {
$results[] = $rowx;
}
if (!empty($exercise_id)) {
$session_id_and .= " AND exe_exo_id = $exercise_id ";
}
$hpresults = array();
$resx = Database::query($sql);
while ($rowx = Database::fetch_array($resx,'ASSOC')) {
$hpresults[] = $rowx;
}
if (empty($user_id)) {
$sql="SELECT firstname as userpart1, lastname as userpart2 ,
email,
tth.exe_name,
tth.exe_result,
tth.exe_weighting,
tth.exe_date
FROM $TBL_TRACK_HOTPOTATOES tth, $TBL_USER tu
WHERE tu.user_id=tth.exe_user_id AND
tth.exe_cours_id = '" . Database :: escape_string($cid) . "' AND
tth.exe_name = '$hotpotato_name'
ORDER BY tth.exe_cours_id ASC, tth.exe_date ASC";
} else {
$user_id_and = ' AND te.exe_user_id = ' . api_get_user_id() . ' ';
// get only this user's results
$sql = "SELECT '', exe_name, exe_result , exe_weighting, exe_date
FROM $TBL_TRACK_HOTPOTATOES
WHERE exe_user_id = '" . $user_id . "' AND
exe_cours_id = '" . Database :: escape_string($cid) . "' AND
tth.exe_name = '$hotpotato_name'
ORDER BY exe_cours_id ASC, exe_date ASC";
}
if ($filter) {
switch ($filter) {
case 1 :
$filter_by_not_revised = true;
break;
case 2 :
$filter_by_revised = true;
break;
default :
null;
}
}
$results = array();
// Print the Result of Hotpotatoes Tests
if (is_array($hpresults)) {
for($i = 0; $i < sizeof($hpresults); $i++) {
$return[$i] = array();
$title = GetQuizName($hpresults[$i]['exe_name'], $document_path);
if ($title =='') {
$title = basename($hpresults[$i]['exe_name']);
}
if(empty($user_id)) {
$return[$i]['email'] = $hpresults[$i]['email'];
$return[$i]['first_name'] = $hpresults[$i]['userpart1'];
$return[$i]['last_name'] = $hpresults[$i]['userpart2'];
}
$return[$i]['title'] = $title;
$return[$i]['exe_date'] = $hpresults[$i]['exe_date'];
$resx = Database::query($sql);
while ($rowx = Database::fetch_array($resx,'ASSOC')) {
$results[] = $rowx;
}
$return[$i]['result'] = $hpresults[$i]['exe_result'];
$return[$i]['max'] = $hpresults[$i]['exe_weighting'];
}
}
$this->results = $return;
return true;
$hpresults = array();
$resx = Database::query($sql);
while ($rowx = Database::fetch_array($resx,'ASSOC')) {
$hpresults[] = $rowx;
}
if ($filter) {
switch ($filter) {
case 1 :
$filter_by_not_revised = true;
break;
case 2 :
$filter_by_revised = true;
break;
default :
null;
}
}
// Print the Result of Hotpotatoes Tests
if (is_array($hpresults)) {
for($i = 0; $i < sizeof($hpresults); $i++) {
$return[$i] = array();
$title = GetQuizName($hpresults[$i]['exe_name'], $document_path);
if ($title =='') {
$title = basename($hpresults[$i]['exe_name']);
}
if(empty($user_id)) {
$return[$i]['email'] = $hpresults[$i]['email'];
$return[$i]['first_name'] = $hpresults[$i]['userpart1'];
$return[$i]['last_name'] = $hpresults[$i]['userpart2'];
}
$return[$i]['title'] = $title;
$return[$i]['exe_date'] = $hpresults[$i]['exe_date'];
$return[$i]['result'] = $hpresults[$i]['exe_result'];
$return[$i]['max'] = $hpresults[$i]['exe_weighting'];
}
}
$this->results = $return;
return true;
}
/**
* Exports the complete report as a CSV file
* @param string Document path inside the document tool
@ -162,7 +162,8 @@ class HotpotatoesExerciseResult
* @param boolean Whether to include user fields or not
* @return boolean False on error
*/
public function exportCompleteReportCSV($document_path='', $hotpotato_name) {
public function exportCompleteReportCSV($document_path='', $hotpotato_name)
{
global $charset;
$this->_getExercisesReporting($document_path, $hotpotato_name);
$filename = 'exercise_results_'.date('YmdGis').'.csv';
@ -171,22 +172,22 @@ class HotpotatoesExerciseResult
}
$data = '';
if (api_is_western_name_order()) {
if(!empty($this->results[0]['first_name'])) {
$data .= get_lang('FirstName').';';
}
if(!empty($this->results[0]['last_name'])) {
$data .= get_lang('LastName').';';
}
} else {
if(!empty($this->results[0]['last_name'])) {
$data .= get_lang('LastName').';';
}
if(!empty($this->results[0]['first_name'])) {
$data .= get_lang('FirstName').';';
if (api_is_western_name_order()) {
if(!empty($this->results[0]['first_name'])) {
$data .= get_lang('FirstName').';';
}
if(!empty($this->results[0]['last_name'])) {
$data .= get_lang('LastName').';';
}
} else {
if(!empty($this->results[0]['last_name'])) {
$data .= get_lang('LastName').';';
}
if(!empty($this->results[0]['first_name'])) {
$data .= get_lang('FirstName').';';
}
}
}
$data .= get_lang('Email').';';
$data .= get_lang('Email').';';
if ($export_user_fields) {
//show user fields section with a big th colspan that spans over all fields
@ -205,15 +206,15 @@ class HotpotatoesExerciseResult
//results
foreach($this->results as $row) {
if (api_is_western_name_order()) {
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';';
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';';
} else {
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';';
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';';
}
if (api_is_western_name_order()) {
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';';
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';';
} else {
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['last_name']), ENT_QUOTES, $charset)).';';
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['first_name']), ENT_QUOTES, $charset)).';';
}
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset)).';';
$data .= str_replace("\r\n",' ',api_html_entity_decode(strip_tags($row['email']), ENT_QUOTES, $charset)).';';
if ($export_user_fields) {
//show user fields data, if any, for this user
@ -283,8 +284,6 @@ class HotpotatoesExerciseResult
}
}
if ($with_column_user) {
$worksheet->write($line,$column,get_lang('Email'));
@ -378,4 +377,3 @@ class HotpotatoesExerciseResult
return true;
}
}
endif;
Loading…
Cancel
Save