[svn r18017] minor - logic changes - allow show only links course active - (see FS#3544)

skala
Isaac Flores 16 years ago
parent df165fbf1f
commit f41b60b9d1
  1. 102
      main/gradebook/lib/be/forumthreadlink.class.php
  2. 23
      main/gradebook/lib/fe/usertable.class.php

@ -122,56 +122,58 @@ class ForumThreadLink extends AbstractLink
}
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'];
$thread_qualify = Database :: get_course_table('forum_thread_qualify', $database_name);
$sql = 'SELECT thread_qualify_max FROM '.Database :: get_course_table(TABLE_FORUM_THREAD, $database_name)." WHERE thread_id = '".$this->get_ref_id()."'";
$query = api_sql_query($sql,__FILE__,__LINE__);
$assignment = Database::fetch_array($query);
$sql = 'SELECT * FROM '.$thread_qualify.' WHERE thread_id = '.$this->get_ref_id();
if (isset($stud_id)){
$sql .= ' AND user_id = '."'".$stud_id."'";
}
// order by id, that way the student's first attempt is accessed first
$sql .= ' ORDER BY qualify_time DESC';
$scores = api_sql_query($sql, __FILE__, __LINE__);
// for 1 student
if (isset($stud_id))
{
if ($data=Database::fetch_array($scores)) {
return array ($data['qualify'], $assignment['thread_qualify_max']);
} else {
return null;
}
} 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 ($assignment['thread_qualify_max'] != 0) {
$students[$data['user_id']] = $data['qualify'];
$rescount++;
$sum += ($data['qualify'] / $assignment['thread_qualify_max']);
}
$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!="") {
$thread_qualify = Database :: get_course_table('forum_thread_qualify', $database_name);
$sql = 'SELECT thread_qualify_max FROM '.Database :: get_course_table(TABLE_FORUM_THREAD, $database_name)." WHERE thread_id = '".$this->get_ref_id()."'";
$query = api_sql_query($sql,__FILE__,__LINE__);
$assignment = Database::fetch_array($query);
$sql = 'SELECT * FROM '.$thread_qualify.' WHERE thread_id = '.$this->get_ref_id();
if (isset($stud_id)){
$sql .= ' AND user_id = '."'".$stud_id."'";
}
// order by id, that way the student's first attempt is accessed first
$sql .= ' ORDER BY qualify_time DESC';
$scores = api_sql_query($sql, __FILE__, __LINE__);
// for 1 student
if (isset($stud_id))
{
if ($data=Database::fetch_array($scores)) {
return array ($data['qualify'], $assignment['thread_qualify_max']);
} else {
return null;
}
} 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 ($assignment['thread_qualify_max'] != 0) {
$students[$data['user_id']] = $data['qualify'];
$rescount++;
$sum += ($data['qualify'] / $assignment['thread_qualify_max']);
}
}
}
}
if ($rescount == 0) {
return null;
} else {
return array ($sum , $rescount);
}
}
if ($rescount == 0) {
return null;
} else {
return array ($sum , $rescount);
}
}
}
}
// INTERNAL FUNCTIONS
@ -248,6 +250,7 @@ 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()."'";
$result = api_sql_query($sql,__FILE__,__LINE__);
$row = Database::fetch_array($result,'ASSOC');
@ -256,6 +259,7 @@ class ForumThreadLink extends AbstractLink
$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();

@ -114,18 +114,19 @@ class UserTable extends SortableTable
// generate the data to display
$sortable_data = array();
foreach ($data_array as $data) {
$row = array ();
$row[] = $this->build_type_column ($data[0]);
$row[] = $this->build_name_link ($data[0]);
$row[] = $data[2];
$row[] = $data[3];
$row[] = $data[4];
$row[] = $data[5];
if ($scoredisplay->is_custom())
$row[] = $data[6];
$sortable_data[] = $row;
if ($data[2]!="") {//filter by course removed
$row = array ();
$row[] = $this->build_type_column ($data[0]);
$row[] = $this->build_name_link ($data[0]);
$row[] = $data[2];
$row[] = $data[3];
$row[] = $data[4];
$row[] = $data[5];
if ($scoredisplay->is_custom())
$row[] = $data[6];
$sortable_data[] = $row;
}
}
return $sortable_data;
}

Loading…
Cancel
Save