Fixing gradebook queries

skala
Julio Montoya 13 years ago
parent 0d62c5e372
commit 2fa676bbac
  1. 26
      main/gradebook/index.php
  2. 4
      main/gradebook/lib/be/abstractlink.class.php
  3. 128
      main/gradebook/lib/be/attendancelink.class.php
  4. 10
      main/gradebook/lib/be/dropboxlink.class.php
  5. 4
      main/gradebook/lib/be/evallink.class.php
  6. 3
      main/gradebook/lib/be/evaluation.class.php
  7. 36
      main/gradebook/lib/be/exerciselink.class.php
  8. 78
      main/gradebook/lib/be/forumthreadlink.class.php
  9. 93
      main/gradebook/lib/be/learnpathlink.class.php
  10. 40
      main/gradebook/lib/be/studentpublicationlink.class.php
  11. 129
      main/gradebook/lib/be/surveylink.class.php
  12. 15
      main/gradebook/lib/fe/displaygradebook.php
  13. 11
      main/gradebook/lib/fe/gradebooktable.class.php

@ -740,16 +740,14 @@ if ($category != '0') {
if (!empty($my_certificate)) {
$url = api_get_path(WEB_PATH) .'certificates/?id='.$my_certificate['id'];
$certificates = Display::url(Display::return_icon('certificate.png', get_lang('Certificates'), array(), 48), $url, array('target'=>'_blank'));
echo '<div class="actions" align="right">';
$certificates = Display::url(Display::return_icon('certificate.png', get_lang('Certificates'), array(), 32), $url, array('target'=>'_blank'));
echo '<div class="actions" align="right">';
echo Display::url($url, $url, array('target'=>'_blank'));
echo $certificates;
echo '<br />'.Display::url($url, $url, array('_blank'));
echo '</div>';
}
}
} //end hack
}
}
@ -759,12 +757,10 @@ if (api_is_allowed_to_edit(null, true)) {
if ( (isset ($_GET['selectcat']) && $_GET['selectcat']<>0) ) {
//
} else {
} else {
if (((isset ($_GET['selectcat']) && $_GET['selectcat']==0) || ((isset($_GET['cidReq']) && $_GET['cidReq']!==''))) || isset($_GET['isStudentView']) && $_GET['isStudentView']=='false') {
$cats = Category :: load(null, null, $course_code, null, null, $session_id, false);
if (!$first_time=1) {
if (!$first_time=1) {
}
}
}
@ -772,8 +768,7 @@ if (api_is_allowed_to_edit(null, true)) {
if ($first_time==1 && api_is_allowed_to_edit(null,true)) {
echo '<meta http-equiv="refresh" content="0;url='.api_get_self().'?cidReq='.$course_code.'" />';
} else {
$cats = Category :: load(null, null, $course_code, null, null, $session_id, false); //already init
$cats = Category :: load(null, null, $course_code, null, null, $session_id, false); //already init
$models = api_get_settings_options('grading_model');
$course_grading_model_id = api_get_course_setting('course_grading_model');
$grading_model = '';
@ -801,8 +796,7 @@ if ($first_time==1 && api_is_allowed_to_edit(null,true)) {
$i++;
} else {
//This is the father
//This is the father
//Create gradebook/add gradebook links
DisplayGradebook::display_header_gradebook($cat, 0, $cat->get_id(), $is_course_admin, $is_platform_admin, $simple_search_form, false, true);
@ -811,13 +805,11 @@ if ($first_time==1 && api_is_allowed_to_edit(null,true)) {
if (!empty($grading_string)) {
Display::display_normal_message($grading_string);
}
}
}
$gradebooktable = new GradebookTable($cat, $allcat, $alleval, $alllink, $addparams);
$gradebooktable->display();
//
}
}
}
}
Display :: display_footer();
Display :: display_footer();

@ -26,10 +26,12 @@ abstract class AbstractLink implements GradebookItem {
protected $weight;
protected $visible;
protected $session_id;
public $course_id;
// CONSTRUCTORS
function AbstractLink() {
function __construct() {
$this->course_id = api_get_course_int_id();
}
// GETTERS AND SETTERS

@ -20,8 +20,9 @@ class AttendanceLink extends AbstractLink
// CONSTRUCTORS
function AttendanceLink() {
$this->set_type(LINK_ATTENDANCE);
function __construct() {
parent::__construct();
$this->set_type(LINK_ATTENDANCE);
}
public function get_type_name() {
@ -45,10 +46,10 @@ class AttendanceLink extends AbstractLink
die('Error in get_not_created_links() : course code not set');
}
$tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
$sql = 'SELECT att.id, att.name, att.attendance_qualify_title
FROM '.$this->get_attendance_table().' att
WHERE att.id NOT IN (SELECT ref_id FROM '.$tbl_grade_links.' WHERE type = '.LINK_ATTENDANCE.' AND course_code = "'.Database::escape_string($this->get_course_code()).'")
WHERE att.c_id = '.$this->course_id.' AND att.id NOT IN (SELECT ref_id FROM '.$tbl_grade_links.' WHERE type = '.LINK_ATTENDANCE.' AND course_code = "'.Database::escape_string($this->get_course_code()).'")
AND att.session_id='.api_get_session_id().'';
$result = Database::query($sql);
@ -73,7 +74,9 @@ class AttendanceLink extends AbstractLink
}
$tbl_attendance = $this->get_attendance_table();
$session_id = api_get_session_id();
$sql = 'SELECT att.id, att.name, att.attendance_qualify_title FROM '.$tbl_attendance.' att WHERE att.active = 1 AND att.session_id = '.intval($session_id).'';
$sql = 'SELECT att.id, att.name, att.attendance_qualify_title
FROM '.$tbl_attendance.' att
WHERE att.c_id = '.$this->course_id.' AND att.active = 1 AND att.session_id = '.intval($session_id).'';
$result = Database::query($sql);
while ($data=Database::fetch_array($result)) {
if (isset($data['attendance_qualify_title']) && $data['attendance_qualify_title'] != ''){
@ -91,69 +94,63 @@ class AttendanceLink extends AbstractLink
* Has anyone done this exercise yet ?
*/
public function has_results() {
$course_info = api_get_course_info($this->course_code);
$tbl_attendance_result = Database :: get_course_table(TABLE_ATTENDANCE_RESULT,$course_info['dbName']);
$sql = 'SELECT count(*) AS number FROM '.$tbl_attendance_result."
WHERE c_id = {$course_info['real_id']} AND attendance_id = '".intval($this->get_ref_id())."'";
WHERE c_id = '.$this->course_id.' AND attendance_id = '".intval($this->get_ref_id())."'";
$result = Database::query($sql);
$number = Database::fetch_row($result);
return ($number[0] != 0);
}
public function calc_score($stud_id = null) {
$course_info = Database :: get_course_info($this->get_course_code());
$database_name = (empty($course_info['db_name']))?$course_info['dbName']:$course_info['db_name'];
if ($database_name!="") {
$tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT, $database_name);
$session_id = api_get_session_id();
public function calc_score($stud_id = null) {
$tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT);
$session_id = api_get_session_id();
// get attendance qualify max
$sql = 'SELECT att.attendance_qualify_max FROM '.$this->get_attendance_table().' att
WHERE att.c_id = '.$course_info['real_id'].' AND att.id = '.intval($this->get_ref_id()).' AND att.session_id='.intval($session_id).'';
$query = Database::query($sql);
$attendance = Database::fetch_array($query);
// get results
$sql = 'SELECT * FROM '.$tbl_attendance_result.'
WHERE c_id = '.$course_info['real_id'].' AND attendance_id = '.intval($this->get_ref_id());
if (isset($stud_id)) {
$sql .= ' AND user_id = '.intval($stud_id);
}
$scores = Database::query($sql);
// for 1 student
if (isset($stud_id))
{
if ($data=Database::fetch_array($scores)) {
return array ($data['score'], $attendance['attendance_qualify_max']);
} else {
//We sent the 0/attendance_qualify_max instead of null for correct calculations
return array (0, $attendance['attendance_qualify_max']);
}
} else {// all students -> get average
$students=array(); // user list, needed to make sure we only
// take first attempts into account
$rescount = 0;
$sum = 0;
while ($data=Database::fetch_array($scores)) {
if (!(array_key_exists($data['user_id'],$students))) {
if ($attendance['attendance_qualify_max'] != 0) {
$students[$data['user_id']] = $data['score'];
$rescount++;
$sum += ($data['score'] / $attendance['attendance_qualify_max']);
}
// get attendance qualify max
$sql = 'SELECT att.attendance_qualify_max FROM '.$this->get_attendance_table().' att
WHERE att.c_id = '.$this->course_id.' AND att.id = '.intval($this->get_ref_id()).' AND att.session_id='.intval($session_id).'';
$query = Database::query($sql);
$attendance = Database::fetch_array($query);
// get results
$sql = 'SELECT * FROM '.$tbl_attendance_result.'
WHERE c_id = '.$this->course_id.' AND attendance_id = '.intval($this->get_ref_id());
if (isset($stud_id)) {
$sql .= ' AND user_id = '.intval($stud_id);
}
$scores = Database::query($sql);
// for 1 student
if (isset($stud_id)) {
if ($data = Database::fetch_array($scores)) {
return array ($data['score'], $attendance['attendance_qualify_max']);
} else {
//We sent the 0/attendance_qualify_max instead of null for correct calculations
return array (0, $attendance['attendance_qualify_max']);
}
} else {// all students -> get average
$students=array(); // user list, needed to make sure we only
// take first attempts into account
$rescount = 0;
$sum = 0;
while ($data=Database::fetch_array($scores)) {
if (!(array_key_exists($data['user_id'],$students))) {
if ($attendance['attendance_qualify_max'] != 0) {
$students[$data['user_id']] = $data['score'];
$rescount++;
$sum += ($data['score'] / $attendance['attendance_qualify_max']);
}
}
if ($rescount == 0) {
return null;
} else {
return array ($sum , $rescount);
}
}
}
}
if ($rescount == 0) {
return null;
} else {
return array ($sum , $rescount);
}
}
}
// INTERNAL FUNCTIONS
// INTERNAL FUNCTIONS
/**
* Lazy load function to get the database table of the student publications
@ -166,12 +163,8 @@ class AttendanceLink extends AbstractLink
/**
* Lazy load function to get the database table of the item properties
*/
private function get_itemprop_table () {
if (!isset($this->itemprop_table)) {
$course_info = Database :: get_course_info($this->get_course_code());
$database_name = $course_info['db_name'];
$this->itemprop_table = Database :: get_course_table(TABLE_ITEM_PROPERTY, $database_name);
}
private function get_itemprop_table () {
$this->itemprop_table = Database :: get_course_table(TABLE_ITEM_PROPERTY);
return $this->itemprop_table;
}
@ -206,7 +199,7 @@ class AttendanceLink extends AbstractLink
public function is_valid_link() {
$session_id = api_get_session_id();
$sql = 'SELECT count(att.id) FROM '.$this->get_attendance_table().' att
WHERE att.id = '.intval($this->get_ref_id()).' AND att.session_id='.intval($session_id).'';
WHERE att.c_id = '.$this->course_id.' AND att.id = '.intval($this->get_ref_id()).' AND att.session_id='.intval($session_id).'';
$result = Database::query($sql);
$number = Database::fetch_row($result);
return ($number[0] != 0);
@ -222,7 +215,7 @@ class AttendanceLink extends AbstractLink
$session_id = api_get_session_id();
if ($tbl_name != '') {
$sql = 'SELECT * FROM '.$this->get_attendance_table().' att
WHERE att.id = '.intval($this->get_ref_id()).' AND att.session_id = '.intval($session_id).' ';
WHERE att.c_id = '.$this->course_id.' AND att.id = '.intval($this->get_ref_id()).' AND att.session_id = '.intval($session_id).' ';
$result = Database::query($sql);
$row = Database::fetch_array($result,'ASSOC');
$attendance_id = $row['id'];
@ -237,7 +230,8 @@ class AttendanceLink extends AbstractLink
if ($tbl_name == '') {
return false;
} elseif (!isset($this->attendance_data)) {
$sql = 'SELECT * FROM '.$this->get_attendance_table().' att WHERE att.id = '.intval($this->get_ref_id()).' AND att.session_id='.intval($session_id).'';
$sql = 'SELECT * FROM '.$this->get_attendance_table().' att
WHERE att.c_id = '.$this->course_id.' AND att.id = '.intval($this->get_ref_id()).' AND att.session_id='.intval($session_id).'';
$query = Database::query($sql);
$this->attendance_data = Database::fetch_array($query);
}
@ -247,6 +241,4 @@ class AttendanceLink extends AbstractLink
public function get_icon_name() {
return 'attendance';
}
}
?>
}

@ -18,7 +18,8 @@ class DropboxLink extends EvalLink
// CONSTRUCTORS
function DropboxLink() {
function __construct() {
parent::__construct();
$this->set_type(LINK_DROPBOX);
}
@ -34,17 +35,14 @@ class DropboxLink extends EvalLink
// with the same title as the evaluation name
$eval = $this->get_evaluation();
$sql = 'SELECT filename FROM '.$this->get_dropbox_table()
.' WHERE uploader_id = '.intval($stud_id)
.' WHERE c_id = '.$this->course_id.' AND uploader_id = '.intval($stud_id)
." AND title = '".Database::escape_string($eval->get_name())."'";
$result = Database::query($sql);
if ($fileurl = Database::fetch_row($result)) {
$course_info = Database :: get_course_info($this->get_course_code());
//$url = api_get_path(WEB_PATH).'main/gradebook/open_document.php?file='.$course_info['directory'].'/'.$fileurl[0];
//return $url;
return null;
return null;
} else {
return null;
}

@ -17,8 +17,8 @@ abstract class EvalLink extends AbstractLink
/**
* Constructor
*/
function EvalLink() {
function __construct() {
parent::__construct();
}
// Functions implementing AbstractLink

@ -26,7 +26,8 @@ class Evaluation implements GradebookItem
// CONSTRUCTORS
function Evaluation() {
function __construct() {
parent::__construct();
}
// GETTERS AND SETTERS

@ -22,7 +22,8 @@ class ExerciseLink extends AbstractLink
// CONSTRUCTORS
function ExerciseLink() {
function __construct() {
parent::__construct();
$this->set_type(LINK_EXERCISE);
}
@ -39,12 +40,12 @@ class ExerciseLink extends AbstractLink
}
$tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
$sql = 'SELECT id,title from '.$this->get_exercise_table()
$sql = 'SELECT id, title from '.$this->get_exercise_table()
.' exe WHERE id NOT IN'
.' (SELECT ref_id FROM '.$tbl_grade_links
.' WHERE type = '.LINK_EXERCISE
." AND course_code = '".$this->get_course_code()."'"
.') AND exe.session_id='.api_get_session_id().'';
.') AND exe.session_id='.api_get_session_id().' AND exe.c_id = '.$this->course_id.' ';
$result = Database::query($sql);
$cats=array();
@ -60,10 +61,9 @@ class ExerciseLink extends AbstractLink
public function get_all_links() {
if (empty($this->course_code)) {
die('Error in get_not_created_links() : course code not set');
}
$course_info = api_get_course_info($this->course_code);
}
$sql = 'SELECT id,title from '.$this->get_exercise_table().'
WHERE c_id = '.$course_info['real_id'].' AND active=1 AND session_id='.api_get_session_id().'';
WHERE c_id = '.$this->course_id.' AND active=1 AND session_id='.api_get_session_id().'';
$result = Database::query($sql);
$cats=array();
while ($data=Database::fetch_array($result)) {
@ -98,10 +98,7 @@ class ExerciseLink extends AbstractLink
//the following query should be similar (in conditions) to the one used in exercice/exercice.php, look for note-query-exe-results marker
$sql = 'SELECT * FROM '.$tbl_stats.' WHERE exe_exo_id = '.(int)$this->get_ref_id().' AND orig_lp_id = 0 AND orig_lp_item_id = 0 AND status <>\'incomplete\'';
if (isset($stud_id)){
//$currect_course=api_get_course_id();
//$course_code_exe = (strlen($currect_course)===0) ? $this->get_course_code() : api_get_course_id();
if (isset($stud_id)) {
$course_code_exe = $this->get_course_code();
$sql .= ' AND exe_cours_id="'.$course_code_exe.'" AND exe_user_id = '."'".$stud_id."'";
}
@ -150,11 +147,9 @@ class ExerciseLink extends AbstractLink
$user_id=api_get_user_id();
$course_code=$this->get_course_code();
$status_user=api_get_status_of_user_in_course ($user_id,$course_code);
$url = api_get_path(WEB_PATH)
.'main/gradebook/exercise_jump.php?cidReq='.$this->get_course_code().'&gradebook=view&exerciseId='.$this->get_ref_id();
if ((!api_is_allowed_to_create_course()
&& $this->calc_score(api_get_user_id()) == null) || $status_user!=1) {
$url .= '&amp;doexercise='.$this->get_ref_id();
$url = api_get_path(WEB_PATH).'main/gradebook/exercise_jump.php?cidReq='.$this->get_course_code().'&gradebook=view&exerciseId='.$this->get_ref_id();
if ((!api_is_allowed_to_create_course() && $this->calc_score(api_get_user_id()) == null) || $status_user!=1) {
$url .= '&amp;doexercise='.$this->get_ref_id();
}
return $url;
}
@ -179,15 +174,15 @@ class ExerciseLink extends AbstractLink
* Check if this still links to an exercise
*/
public function is_valid_link() {
$sql = 'SELECT count(id) from '.$this->get_exercise_table()
.' WHERE id = '.(int)$this->get_ref_id().' AND session_id='.api_get_session_id().'';
$sql = 'SELECT count(id) from '.$this->get_exercise_table().'
WHERE c_id = '.$this->course_id.' AND id = '.(int)$this->get_ref_id().' AND session_id='.api_get_session_id().'';
$result = Database::query($sql);
$number=Database::fetch_row($result);
return ($number[0] != 0);
}
public function get_type_name() {
return get_lang('DokeosExercises');
return get_lang('Exercises');
}
public function needs_name_and_description() {
@ -225,8 +220,9 @@ class ExerciseLink extends AbstractLink
if ($tbl_exercise=='') {
return false;
} elseif (!isset($this->exercise_data)) {
$sql = 'SELECT * from '.$this->get_exercise_table()
.' WHERE id = '.(int)$this->get_ref_id().' AND session_id ='.api_get_session_id().'';
$sql = 'SELECT * from '.$this->get_exercise_table().'
WHERE c_id = '.$this->course_id.' AND id = '.(int)$this->get_ref_id().' AND session_id ='.api_get_session_id().'';
$result = Database::query($sql);
$this->exercise_data=Database::fetch_array($result);
}

@ -20,7 +20,8 @@ class ForumThreadLink extends AbstractLink
// CONSTRUCTORS
function ForumThreadLink() {
function __construct() {
parent::__construct();
$this->set_type(LINK_FORUM_THREAD);
}
@ -72,15 +73,14 @@ class ForumThreadLink extends AbstractLink
public function get_all_links() {
if (empty($this->course_code)) {
die('Error in get_not_created_links() : course code not set');
}
$course_info = api_get_course_info($this->course_code);
}
$tbl_grade_links = Database :: get_course_table(TABLE_FORUM_THREAD);
$tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
$sql = 'SELECT tl.thread_id, tl.thread_title, tl.thread_title_qualify
FROM '.$tbl_grade_links.' tl ,'.$tbl_item_property.' ip
WHERE tl.c_id = '.$course_info['real_id'].' AND
ip.c_id = '.$course_info['real_id'].' AND
WHERE tl.c_id = '.$this->course_id.' AND
ip.c_id = '.$this->course_id.' AND
tl.thread_id = ip.ref AND
ip.tool = "forum_thread" AND
ip.visibility<>2 AND tl.session_id='.api_get_session_id().' GROUP BY ip.ref ';
@ -101,29 +101,25 @@ class ForumThreadLink extends AbstractLink
/**
* Has anyone done this exercise yet ?
*/
public function has_results() {
$course_info = api_get_course_info($this->course_code);
$tbl_grade_links = Database :: get_course_table(TABLE_FORUM_POST,$course_info['dbName']);
public function has_results() {
$tbl_grade_links = Database :: get_course_table(TABLE_FORUM_POST);
$sql = 'SELECT count(*) AS number FROM '.$tbl_grade_links."
WHERE c_id = ".$course_info['real_id']." AND thread_id = '".$this->get_ref_id()."'";
WHERE c_id = ".$this->course_id." AND thread_id = '".$this->get_ref_id()."'";
$result = Database::query($sql);
$number=Database::fetch_row($result);
return ($number[0] != 0);
}
public function calc_score($stud_id = null) {
$course_info = Database :: get_course_info($this->get_course_code());
$database_name = (empty($course_info['db_name']))?$course_info['dbName']:$course_info['db_name'];
public function calc_score($stud_id = null) {
if (!empty($database_name)) {
$thread_qualify = Database :: get_course_table(TABLE_FORUM_THREAD_QUALIFY, $database_name);
$thread_qualify = Database :: get_course_table(TABLE_FORUM_THREAD_QUALIFY);
$sql = 'SELECT thread_qualify_max FROM '.Database :: get_course_table(TABLE_FORUM_THREAD, $database_name)."
WHERE c_id = ".$course_info['real_id']." AND thread_id = '".$this->get_ref_id()."'";
$sql = 'SELECT thread_qualify_max FROM '.Database :: get_course_table(TABLE_FORUM_THREAD)."
WHERE c_id = ".$this->course_id." AND thread_id = '".$this->get_ref_id()."'";
$query = Database::query($sql);
$assignment = Database::fetch_array($query);
$sql = "SELECT * FROM $thread_qualify WHERE c_id = ".$course_info['real_id']." AND thread_id = ".$this->get_ref_id();
$sql = "SELECT * FROM $thread_qualify WHERE c_id = ".$this->course_id." AND thread_id = ".$this->get_ref_id();
if (isset($stud_id)) {
$sql .= ' AND user_id = '."'".intval($stud_id)."'";
}
@ -175,34 +171,21 @@ class ForumThreadLink extends AbstractLink
* Lazy load function to get the database table of the student publications
*/
private function get_forum_thread_table () {
$course_info = Database :: get_course_info($this->get_course_code());
$database_name = isset($course_info['db_name']) ? $course_info['db_name'] : '';
if ($database_name!='') {
if (!isset($this->forum_thread_table)) {
$this->forum_thread_table = Database :: get_course_table(TABLE_FORUM_THREAD, $database_name);
}
return $this->forum_thread_table;
} else {
return '';
}
return $this->forum_thread_table = Database :: get_course_table(TABLE_FORUM_THREAD);
}
/**
* Lazy load function to get the database table of the item properties
*/
private function get_itemprop_table () {
if (!isset($this->itemprop_table)) {
$course_info = Database :: get_course_info($this->get_course_code());
$database_name = $course_info['db_name'];
$this->itemprop_table = Database :: get_course_table(TABLE_ITEM_PROPERTY, $database_name);
}
$this->itemprop_table = Database :: get_course_table(TABLE_ITEM_PROPERTY);
return $this->itemprop_table;
}
public function needs_name_and_description() {
return false;
}
public function needs_max() {
return false;
}
@ -229,10 +212,10 @@ class ForumThreadLink extends AbstractLink
* Check if this still links to an exercise
*/
public function is_valid_link() {
$sql = 'SELECT count(id) from '.$this->get_forum_thread_table()
.' WHERE thread_id = '.$this->get_ref_id().' AND session_id='.api_get_session_id().'';
$sql = 'SELECT count(id) from '.$this->get_forum_thread_table().'
WHERE c_id = '.$this->course_id.' AND thread_id = '.$this->get_ref_id().' AND session_id='.api_get_session_id().'';
$result = Database::query($sql);
$number=Database::fetch_row($result);
$number = Database::fetch_row($result);
return ($number[0] != 0);
}
@ -242,26 +225,22 @@ class ForumThreadLink extends AbstractLink
public function get_link() {
//it was extracts the forum id
$tbl_name=$this->get_forum_thread_table();
if ($tbl_name!="") {
$sql = 'SELECT * FROM '.$this->get_forum_thread_table()." WHERE thread_id = '".$this->get_ref_id()."' AND session_id = ".api_get_session_id()."";
$sql = 'SELECT * FROM '.$this->get_forum_thread_table()."
WHERE c_id = '.$this->course_id.' AND thread_id = '".$this->get_ref_id()."' AND session_id = ".api_get_session_id()."";
$result = Database::query($sql);
$row = Database::fetch_array($result,'ASSOC');
$forum_id=$row['forum_id'];
$url = api_get_path(WEB_PATH)
.'main/forum/viewthread.php?cidReq='.$this->get_course_code().'&thread='.$this->get_ref_id().'&gradebook=view&forum='.$forum_id;
$url = api_get_path(WEB_PATH).'main/forum/viewthread.php?cidReq='.$this->get_course_code().'&thread='.$this->get_ref_id().'&gradebook=view&forum='.$forum_id;
return $url;
}
}
private function get_exercise_data() {
$tbl_name=$this->get_forum_thread_table();
if ($tbl_name=='') {
return false;
}elseif (!isset($this->exercise_data)) {
$sql = 'SELECT * FROM '.$this->get_forum_thread_table()." WHERE thread_id = '".$this->get_ref_id()."' AND session_id=".api_get_session_id()."";
$query = Database::query($sql);
$this->exercise_data = Database::fetch_array($query);
if (!isset($this->exercise_data)) {
$sql = 'SELECT * FROM '.$this->get_forum_thread_table()."
WHERE c_id = '.$this->course_id.' AND thread_id = '".$this->get_ref_id()."' AND session_id=".api_get_session_id()."";
$query = Database::query($sql);
$this->exercise_data = Database::fetch_array($query);
}
return $this->exercise_data;
}
@ -269,5 +248,4 @@ class ForumThreadLink extends AbstractLink
public function get_icon_name() {
return 'forum';
}
}

@ -21,8 +21,8 @@ class LearnpathLink extends AbstractLink
// CONSTRUCTORS
function LearnpathLink()
{
function __construct() {
parent::__construct();
$this->set_type(LINK_LEARNPATH);
}
@ -40,8 +40,8 @@ class LearnpathLink extends AbstractLink
$tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
$sql = 'SELECT id,name from '.$this->get_learnpath_table()
.' lp WHERE id NOT IN'
$sql = 'SELECT id, name from '.$this->get_learnpath_table().' lp
WHERE c_id = '.$this->course_id.' AND id NOT IN '
.' (SELECT ref_id FROM '.$tbl_grade_links
.' WHERE type = '.LINK_LEARNPATH
." AND course_code = '".$this->get_course_code()."'"
@ -50,8 +50,7 @@ class LearnpathLink extends AbstractLink
$result = Database::query($sql);
$cats=array();
while ($data=Database::fetch_array($result))
{
while ($data=Database::fetch_array($result)) {
$cats[] = array ($data['id'], $data['name']);
}
return $cats;
@ -64,13 +63,11 @@ class LearnpathLink extends AbstractLink
if (empty($this->course_code))
die('Error in get_not_created_links() : course code not set');
$course_info = api_get_course_info($this->course_code);
$sql = 'SELECT id,name FROM '.$this->get_learnpath_table().' WHERE session_id = '.api_get_session_id().' ';
$sql = 'SELECT id, name FROM '.$this->get_learnpath_table().' WHERE c_id = '.$this->course_id.' AND session_id = '.api_get_session_id().' ';
$result = Database::query($sql);
$cats=array();
while ($data=Database::fetch_array($result))
{
$cats = array();
while ($data=Database::fetch_array($result)) {
$cats[] = array ($data['id'], $data['name']);
}
return $cats;
@ -81,13 +78,11 @@ class LearnpathLink extends AbstractLink
* Has anyone used this learnpath yet ?
*/
public function has_results() {
$course_info = api_get_course_info($this->get_course_code());
$tbl_stats = Database::get_course_table(TABLE_LP_VIEW,$course_info['dbName']);
$tbl_stats = Database::get_course_table(TABLE_LP_VIEW);
$sql = "SELECT count(id) AS number FROM $tbl_stats
WHERE c_id = {$course_info['real_id']} AND lp_id = ".$this->get_ref_id();
WHERE c_id = ".$this->course_id." AND lp_id = ".$this->get_ref_id();
$result = Database::query($sql);
$number=Database::fetch_array($result,'NUM');
$number = Database::fetch_array($result,'NUM');
return ($number[0] != 0);
}
@ -98,44 +93,32 @@ class LearnpathLink extends AbstractLink
* array (sum of scores, number of scores) otherwise
* or null if no scores available
*/
public function calc_score($stud_id = null)
{
$course_info = api_get_course_info($this->get_course_code());
$tbl_stats = Database::get_course_table(TABLE_LP_VIEW);
if (is_null($course_info['dbName'])===true) {
return false;
}
$sql = "SELECT * FROM $tbl_stats WHERE c_id = {$course_info['real_id']} AND lp_id = ".$this->get_ref_id();
public function calc_score($stud_id = null) {
$tbl_stats = Database::get_course_table(TABLE_LP_VIEW);
$sql = "SELECT * FROM $tbl_stats WHERE c_id = ".$this->course_id." AND lp_id = ".$this->get_ref_id();
if (isset($stud_id))
$sql .= ' AND user_id = '.intval($stud_id);
// order by id, that way the student's first attempt is accessed first
$sql .= ' ORDER BY view_count DESC';
$sql .= ' ORDER BY view_count DESC';
$scores = Database::query($sql);
// for 1 student
if (isset($stud_id))
{
if ($data=Database::fetch_array($scores))
{
if (isset($stud_id)) {
if ($data=Database::fetch_array($scores)) {
return array ($data['progress'], 100);
}
else
} else
return null;
}
// all students -> get average
else
{
else {
$students=array(); // user list, needed to make sure we only
// take first attempts into account
$rescount = 0;
$sum = 0;
while ($data=Database::fetch_array($scores))
{
if (!(array_key_exists($data['user_id'],$students)))
{
while ($data=Database::fetch_array($scores)) {
if (!(array_key_exists($data['user_id'], $students))) {
$students[$data['user_id']] = $data['progress'];
$rescount++;
$sum += ($data['progress'] / 100);
@ -189,37 +172,31 @@ class LearnpathLink extends AbstractLink
/**
* Check if this still links to a learnpath
*/
public function is_valid_link()
{
public function is_valid_link() {
$sql = 'SELECT count(id) FROM '.$this->get_learnpath_table()
.' WHERE id = '.$this->get_ref_id().' AND session_id='.api_get_session_id().'';
.' WHERE c_id = '.$this->course_id.' AND id = '.$this->get_ref_id().' AND session_id='.api_get_session_id().'';
$result = Database::query($sql);
$number=Database::fetch_row($result,'NUM');
$number = Database::fetch_row($result,'NUM');
return ($number[0] != 0);
}
public function get_type_name()
{
return get_lang('DokeosLearningPaths');
public function get_type_name() {
return get_lang('LearningPaths');
}
public function needs_name_and_description()
{
public function needs_name_and_description() {
return false;
}
public function needs_max()
{
public function needs_max() {
return false;
}
public function needs_results()
{
public function needs_results() {
return false;
}
public function is_allowed_to_change_name()
{
public function is_allowed_to_change_name() {
return false;
}
@ -228,7 +205,7 @@ class LearnpathLink extends AbstractLink
/**
* Lazy load function to get the database table of the learnpath
*/
private function get_learnpath_table () {
private function get_learnpath_table() {
$this->learnpath_table = Database :: get_course_table(TABLE_LP_MAIN);
return $this->learnpath_table;
}
@ -237,10 +214,7 @@ class LearnpathLink extends AbstractLink
* Lazy load function to get the database contents of this learnpath
*/
private function get_learnpath_data() {
$tb_learnpath=$this->get_learnpath_table();
if ($tb_learnpath=='') {
return false;
} elseif (!isset($this->learnpath_data)) {
if (!isset($this->learnpath_data)) {
$sql = 'SELECT * from '.$this->get_learnpath_table()
.' WHERE id = '.$this->get_ref_id().' AND session_id='.api_get_session_id().'';
$result = Database::query($sql);
@ -252,5 +226,4 @@ class LearnpathLink extends AbstractLink
public function get_icon_name() {
return 'learnpath';
}
}
}

@ -20,7 +20,8 @@ class StudentPublicationLink extends AbstractLink
// CONSTRUCTORS
function StudentPublicationLink() {
public function __construct() {
parent::__construct();
$this->set_type(LINK_STUDENTPUBLICATION);
}
@ -40,7 +41,10 @@ class StudentPublicationLink extends AbstractLink
$stud_id = intval($stud_id);
$sql = 'SELECT pub.url FROM '.$this->get_itemprop_table().' prop, '.$this->get_studpub_table().' pub'
." WHERE prop.tool = 'work'"
." WHERE
prop.c_id = ".$this->course_id." AND
pub.c_id = ".$this->course_id." AND
prop.tool = 'work'"
.' AND prop.insert_user_id = '.$stud_id
.' AND prop.ref = pub.id'
." AND pub.title = '".Database::escape_string($eval->get_name())."' AND pub.session_id=".api_get_session_id()."";
@ -79,7 +83,7 @@ class StudentPublicationLink extends AbstractLink
$tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
$sql = 'SELECT id,url from '.$this->get_studpub_table()
.' pup WHERE has_properties != '."''".' AND id NOT IN'
.' pup WHERE c_id = '.$this->course_id.' AND has_properties != '."''".' AND id NOT IN'
.' (SELECT ref_id FROM '.$tbl_grade_links
.' WHERE type = '.LINK_STUDENTPUBLICATION
." AND course_code = '".Database::escape_string($this->get_course_code())."'"
@ -100,12 +104,11 @@ class StudentPublicationLink extends AbstractLink
public function get_all_links() {
if (empty($this->course_code)) {
die('Error in get_not_created_links() : course code not set');
}
$course_info = api_get_course_info($this->course_code);
}
$tbl_grade_links = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
$sql = "SELECT id, url FROM $tbl_grade_links
WHERE c_id = {$course_info['real_id']} AND has_properties != '' AND filetype='folder' AND session_id = ".api_get_session_id()."";
WHERE c_id = {$this->course_id} AND has_properties != '' AND filetype='folder' AND session_id = ".api_get_session_id()."";
$result = Database::query($sql);
while ($data = Database::fetch_array($result)) {
$cats[] = array ($data['id'], basename($data['url']));
@ -118,25 +121,22 @@ class StudentPublicationLink extends AbstractLink
* Has anyone done this exercise yet ?
*/
public function has_results() {
$course_info = api_get_course_info($this->course_code);
$tbl_grade_links = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
$sql = 'SELECT count(*) AS number FROM '.$tbl_grade_links."
WHERE c_id = {$course_info['real_id']} AND
WHERE c_id = {$this->course_id} AND
parent_id = '".intval($this->get_ref_id())."' AND
session_id =".api_get_session_id()."";
$result = Database::query($sql);
$number=Database::fetch_row($result);
$number = Database::fetch_row($result);
return ($number[0] != 0);
}
public function calc_score($stud_id = null) {
$stud_id = intval($stud_id);
$course_info = Database::get_course_info($this->get_course_code());
$tbl_stats = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$stud_id = intval($stud_id);
$tbl_stats = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
$sql = 'SELECT * FROM '.$tbl_stats."
WHERE c_id = {$course_info['real_id']} AND
WHERE c_id = {$this->course_id} AND
id = '".intval($this->get_ref_id())."' AND
session_id = ".api_get_session_id()."";
$query = Database::query($sql);
@ -147,7 +147,9 @@ class StudentPublicationLink extends AbstractLink
} else {
$v_assigment_id = $assignment['id'];
}
$sql = 'SELECT * FROM '.$tbl_stats.' WHERE parent_id ="'.$v_assigment_id.'" AND session_id='.api_get_session_id().'';
$sql = 'SELECT * FROM '.$tbl_stats.'
WHERE c_id = '.$this->course_id.' AND parent_id ="'.$v_assigment_id.'" AND session_id='.api_get_session_id().'';
if (!empty($stud_id)) {
$sql .= " AND user_id = $stud_id ";
}
@ -245,13 +247,11 @@ class StudentPublicationLink extends AbstractLink
return false;
}
public function is_valid_link() {
$course_info = Database :: get_course_info($this->get_course_code());
public function is_valid_link() {
$sql = 'SELECT count(id) from '.$this->get_studpub_table().'
WHERE c_id = "'.$course_info['real_id'].'" AND id = '.intval($this->get_ref_id()).' AND session_id='.api_get_session_id();
WHERE c_id = "'.$this->course_id.'" AND id = '.intval($this->get_ref_id()).' AND session_id='.api_get_session_id();
$result = Database::query($sql);
$number=Database::fetch_row($result);
$number = Database::fetch_row($result);
return ($number[0] != 0);
}

@ -15,7 +15,8 @@ class SurveyLink extends AbstractLink
{
private $survey_table = null;
function SurveyLink() {
public function __construct() {
parent::__construct();
$this->set_type(LINK_SURVEY);
}
@ -97,29 +98,21 @@ class SurveyLink extends AbstractLink
* Has anyone done this survey yet?
*/
public function has_results($stud_id=null) {
$course_info = Database :: get_course_info($this->get_course_code());
$database_name = (empty($course_info['db_name'])) ? $course_info['dbName'] : $course_info['db_name'];
if ($database_name != '') {
$ref_id = intval($this->get_ref_id());
$session_id = api_get_session_id();
$tbl_survey = Database::get_course_table(TABLE_SURVEY, $database_name);
$tbl_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION, $database_name);
$get_individual_score = !is_null($stud_id);
$sql = "SELECT COUNT(i.answered) FROM $tbl_survey AS s JOIN $tbl_survey_invitation AS i ON s.code = i.survey_code
WHERE s.c_id = {$course_info['real_id']} AND
i.c_id = {$course_info['real_id']} AND
s.survey_id = $ref_id AND
i.session_id = $session_id";
$sql_result = Database::query($sql);
$data = Database::fetch_array($sql_result);
return ($data[0] != 0);
}
return false;
$ref_id = intval($this->get_ref_id());
$session_id = api_get_session_id();
$tbl_survey = Database::get_course_table(TABLE_SURVEY);
$tbl_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION);
$get_individual_score = !is_null($stud_id);
$sql = "SELECT COUNT(i.answered) FROM $tbl_survey AS s JOIN $tbl_survey_invitation AS i ON s.code = i.survey_code
WHERE s.c_id = {$this->course_id} AND
i.c_id = {$this->course_id} AND
s.survey_id = $ref_id AND
i.session_id = $session_id";
$sql_result = Database::query($sql);
$data = Database::fetch_array($sql_result);
return ($data[0] != 0);
}
public function calc_score($stud_id = null) {
@ -127,61 +120,47 @@ class SurveyLink extends AbstractLink
// Note: Max score is assumed to be always 1 for surveys,
// only student's participation is to be taken into account.
$max_score = 1;
$ref_id = intval($this->get_ref_id());
$session_id = api_get_session_id();
$tbl_survey = Database::get_course_table(TABLE_SURVEY, $database_name);
$tbl_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION, $database_name);
$course_info = Database :: get_course_info($this->get_course_code());
$database_name = (empty($course_info['db_name'])) ? $course_info['dbName'] : $course_info['db_name'];
if ($database_name != '') {
$ref_id = intval($this->get_ref_id());
$session_id = api_get_session_id();
$tbl_survey = Database::get_course_table(TABLE_SURVEY, $database_name);
$tbl_survey_invitation = Database::get_course_table(TABLE_SURVEY_INVITATION, $database_name);
$get_individual_score = !is_null($stud_id);
$get_individual_score = !is_null($stud_id);
$sql = "SELECT i.answered FROM $tbl_survey AS s JOIN $tbl_survey_invitation AS i
$sql = "SELECT i.answered FROM $tbl_survey AS s JOIN $tbl_survey_invitation AS i
ON s.code = i.survey_code
WHERE s.c_id = {$course_info['real_id']} AND
i.c_id = {$course_info['real_id']} AND
WHERE s.c_id = {$this->course_id} AND
i.c_id = {$this->course_id} AND
s.survey_id = $ref_id AND i.session_id = $session_id";
if ($get_individual_score) {
$sql .= ' AND i.user = '.intval($stud_id);
}
$sql_result = Database::query($sql);
if ($get_individual_score) {
$sql .= ' AND i.user = '.intval($stud_id);
}
if ($get_individual_score) {
$sql_result = Database::query($sql);
if ($get_individual_score) {
// for 1 student
if ($data = Database::fetch_array($sql_result)) {
return array ($data['answered'] ? $max_score : 0, $max_score);
}
return array(0, $max_score);
} else {
// for all the students -> get average
$students = array();
$rescount = 0;
$sum = 0;
while ($data = Database::fetch_array($sql_result)) {
$sum += $data['answered'] ? $max_score : 0;
$rescount++;
}
$sum = $sum / $max_score;
if ($rescount == 0) {
return null;
}
return array($sum, $rescount);
if ($data = Database::fetch_array($sql_result)) {
return array ($data['answered'] ? $max_score : 0, $max_score);
}
}
return null;
return array(0, $max_score);
} else {
// for all the students -> get average
$students = array();
$rescount = 0;
$sum = 0;
while ($data = Database::fetch_array($sql_result)) {
$sum += $data['answered'] ? $max_score : 0;
$rescount++;
}
$sum = $sum / $max_score;
if ($rescount == 0) {
return null;
}
return array($sum, $rescount);
}
}
/**
@ -198,7 +177,7 @@ class SurveyLink extends AbstractLink
public function is_valid_link() {
$session_id = api_get_session_id();
$sql = 'SELECT count(survey_id) FROM '.$this->get_survey_table().'
WHERE survey_id = '.intval($this->get_ref_id()).' AND session_id='.intval($session_id).'';
WHERE c_id = '.$this->course_id.' AND survey_id = '.intval($this->get_ref_id()).' AND session_id='.intval($session_id).'';
$result = Database::query($sql);
$number = Database::fetch_row($result);
return ($number[0] != 0);
@ -214,7 +193,7 @@ class SurveyLink extends AbstractLink
$session_id = api_get_session_id();
if ($tbl_name != '') {
$sql = 'SELECT survey_id FROM '.$this->get_survey_table().'
WHERE survey_id = '.intval($this->get_ref_id()).' AND session_id = '.intval($session_id).' ';
WHERE c_id = '.$this->course_id.' AND survey_id = '.intval($this->get_ref_id()).' AND session_id = '.intval($session_id).' ';
$result = Database::query($sql);
$row = Database::fetch_array($result, 'ASSOC');
$survey_id = $row['survey_id'];
@ -230,7 +209,7 @@ class SurveyLink extends AbstractLink
if ($tbl_name == '') {
return false;
} elseif (!isset($this->survey_data)) {
$sql = 'SELECT * FROM '.$tbl_name.' WHERE survey_id = '.intval($this->get_ref_id()).' AND session_id='.intval($session_id).'';
$sql = 'SELECT * FROM '.$tbl_name.' WHERE c_id = '.$this->course_id.' AND survey_id = '.intval($this->get_ref_id()).' AND session_id='.intval($session_id).'';
$query = Database::query($sql);
$this->survey_data = Database::fetch_array($query);
}
@ -244,6 +223,4 @@ class SurveyLink extends AbstractLink
private static function html_to_text($string) {
return trim(api_html_entity_decode(strip_tags(str_ireplace(array('<p>', '</p>', '<br />', '<br/>', '<br>'), array('', ' ', ' ', ' ', ' '), $string)), ENT_QUOTES));
}
}
?>
}

@ -401,9 +401,9 @@ class DisplayGradebook
$user_id = api_get_user_id();
$user= get_user_info_from_id($user_id);
$catcourse= Category::load($catobj->get_id());
$catcourse = Category::load($catobj->get_id());
$scoredisplay = ScoreDisplay :: instance();
$scorecourse = $catcourse[0]->calc_score($user_id);
$scorecourse = $catcourse[0]->calc_score($user_id);
// generating the total score for a course
$allevals= $catcourse[0]->get_evaluations($user_id,true);
@ -415,21 +415,24 @@ class DisplayGradebook
$item = $evals_links[$count];
$score = $item->calc_score($user_id);
$my_score_denom=($score[1]==0) ? 1 : $score[1];
$item_value+=$score[0]/$my_score_denom*$item->get_weight();
$item_total+=$item->get_weight();
$item_value +=$score[0]/$my_score_denom*$item->get_weight();
$item_total +=$item->get_weight();
//$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT);
//var_dump($item_value.' - '.$item_total);
}
$children = $catcourse[0]->get_subcategories(api_get_user_id(), api_get_course_id(), api_get_session_id());
$count = 1;
if (!empty($children)) {
$count = count($children);
}
$item_value = $item_value/$count;
$item_total = $item_total / $count;
$item_total = $item_total/$count;
$item_value = number_format($item_value, 2, '.', ' ');
$total_score = array($item_value, $item_total);
$scorecourse_display = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT);
$cattotal = Category :: load(0);

@ -33,8 +33,7 @@ class GradebookTable extends SortableTable {
$this->evals_links = array_merge($evals, $links);
$this->currentcat = $currentcat;
$this->datagen = new GradebookDataGenerator($cats, $evals, $links);
$this->datagen = new GradebookDataGenerator($cats, $evals, $links);
if (isset($addparams)) {
$this->set_additional_parameters($addparams);
}
@ -137,7 +136,6 @@ class GradebookTable extends SortableTable {
$sortable_data = array();
$weight_total_links = 0;
foreach ($data_array as $data) {
// list of items inside the gradebook (exercises, lps, forums, etc)
@ -167,7 +165,7 @@ class GradebookTable extends SortableTable {
//$row[] = $invisibility_span_open.$data[2] . $invisibility_span_close;
//Weight
$row[] = $invisibility_span_open .'<h3>'.$data[3] .'% </h3>'.$invisibility_span_close;
$row[] = $invisibility_span_open .'<h4>'.$data[3] .'% </h4>'.$invisibility_span_close;
if (api_is_allowed_to_edit(null, true)) {
$weight_total_links += intval($data[3]);
} else {
@ -190,10 +188,9 @@ class GradebookTable extends SortableTable {
} else {
//students get the results and certificates columns
if (count($this->evals_links)>0 && $status_user!=1 ) {
$value_data = isset($data[4]) ? $data[4] : null;
$value_data = isset($data[4]) ? $data[4] : null;
if (!is_null($value_data)) {
$row[] = $value_data;
$row[] = Display::tag('h4', $value_data);
}
}
}

Loading…
Cancel
Save