Source for file evaluation.class.php
Documentation is available at evaluation.class.php
* Defines a gradebook Evaluation object
* @author Bert Stepp�, Stijn Konings
* @package dokeos.gradebook
* Retrieve evaluations and return them as an array of Evaluation objects
* @param $id evaluation id
* @param $user_id user id (evaluation owner)
* @param $course_code course code
* @param $category_id parent category
* @param $visible visible
public function load ($id = null, $user_id = null, $course_code = null, $category_id = null, $visible = null)
$sql= 'SELECT id,name,description,user_id,course_code,category_id,date,weight,max,visible FROM '. $tbl_grade_evaluations;
$sql.= ' WHERE id = '. $id;
if ($paramcount != 0) $sql .= ' AND';
$sql .= ' user_id = '. $user_id;
if (isset ($course_code))
if ($paramcount != 0) $sql .= ' AND';
$sql .= " course_code = '". $course_code. "'";
if (isset ($category_id))
if ($paramcount != 0) $sql .= ' AND';
$sql .= ' category_id = '. $category_id;
if ($paramcount != 0) $sql .= ' AND';
$sql .= ' visible = '. $visible;
$eval->set_id($data['id']);
$eval->set_name($data['name']);
$eval->set_description($data['description']);
$eval->set_user_id($data['user_id']);
$eval->set_course_code($data['course_code']);
$eval->set_category_id($data['category_id']);
$eval->set_date($data['date']);
$eval->set_weight($data['weight']);
$eval->set_max($data['max']);
$eval->set_visible($data['visible']);
* Insert this evaluation into the database
$sql = 'INSERT INTO '. $tbl_grade_evaluations
. ' (name,user_id,weight,max,visible';
if (isset ($this->category)) $sql .= ',category_id';
if (isset ($this->eval_date)) $sql .= ',date';
die('Error in Evaluation add: required field empty');
* Update the properties of this evaluation in the database
$sql = 'UPDATE '. $tbl_grade_evaluations
$sql .= ', category_id = ';
. ' WHERE id = '. $this->id;
* Delete this evaluation from the database
$sql = 'DELETE FROM '. $tbl_grade_evaluations. ' WHERE id = '. $this->id;
* Check if an evaluation name (with the same parent category) already exists
* @param $name name to check (if not given, the name property of this object will be checked)
* @param $parent parent category
$sql = 'SELECT count(id) AS number'
. ' FROM '. $tbl_grade_evaluations
. " WHERE name = '". $name. "'";
$code = $parent[0]->get_course_code();
if (isset ($code) && $code != '0')
$sql .= ' AND user_id IN ('
. ' SELECT user_id FROM '. $main_course_user_table
. " WHERE course_code = '". $code. "'"
$sql.= ' AND category_id is null';
$sql.= ' AND category_id = '. $parent;
return ($number[0] != 0);
* Are there any results for this evaluation yet ?
* The 'max' property should not be changed then.
$sql= 'SELECT count(id) AS number FROM '. $tbl_grade_results
. ' WHERE evaluation_id = '. $this->id;
return ($number[0] != 0);
* Does this evaluation have any results for a student ?
/* - not used anywhere (yet ?)
public function has_results_for_student($stud_id)
$tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
$sql="SELECT count(id) AS number FROM ".$tbl_grade_results
." WHERE evaluation_id = ".$this->id." AND user_id = ".$stud_id;
$result = api_sql_query($sql, __FILE__, __LINE__);
$number=mysql_fetch_row($result);
return ($number[0] != 0);
* Delete all results for this evaluation
$sql = 'DELETE FROM '. $tbl_grade_results. ' WHERE evaluation_id = '. $this->id;
* Delete this evaluation and all underlying results.
* Check if the given score is possible for this evaluation
* Calculate the score of this evaluation
* @param $stud_id student id (default: all students who have results for this eval - then the average is returned)
* @return array (score, max) if student is given
* array (sum of scores, number of scores) otherwise
* or null if no scores available
foreach ($results as $res)
$score = $res->get_score();
if ((!empty ($score)) || ($score == '0'))
$sum += ($score / $this->get_max());
else if (isset ($stud_id))
return array ($score, $this->get_max());
return array ($sum, $rescount);
* Generate an array of possible categories where this evaluation can be moved to.
* Notice: its own parent will be included in the list: it's up to the frontend
* to disable this element.
* @return array 2-dimensional array - every element contains 3 subelements (id, name, level)
// - course independent evaluation
// -> movable to root or other course independent categories
// - evaluation inside a course
// -> movable to root, independent categories or categories inside the course
$root = array(0, get_lang('RootCat'), $level);
foreach ($crscats as $cat)
$targets[] = array ($cat->get_id(), $cat->get_name(), $level+ 1);
foreach ($indcats as $cat)
$targets[] = array ($cat->get_id(), $cat->get_name(), $level+ 1);
* Internal function used by get_target_categories()
foreach ($subcats as $cat)
$targets[] = array ($cat->get_id(), $cat->get_name(), $level+ 1);
* Move this evaluation to the given category.
* If this evaluation moves from inside a course to outside,
* its course code is also changed.
* Retrieve evaluations where a student has results for
* and return them as an array of Evaluation objects
* @param $cat_id parent category (use 'null' to retrieve them in all categories)
* @param $stud_id student id
$sql = 'SELECT * FROM '. $tbl_grade_evaluations
. '(SELECT evaluation_id FROM '. $tbl_grade_results
. ' WHERE user_id = '. $stud_id. ' AND score IS NOT NULL)';
$sql .= ' AND visible = 1';
$sql .= ' AND category_id = '. $cat_id;
$sql .= ' AND category_id >= 0';
* Get a list of students that do not have a result record for this evaluation
$sql = 'SELECT user_id,lastname,firstname,username FROM '. $tbl_user
. " WHERE lastname LIKE '". $first_letter_user. "%'"
. ' (SELECT user_id FROM '. $tbl_grade_results
. ' WHERE evaluation_id = '. $this->id
* Find evaluations by name
* @param string $name_mask search string
* @return array evaluation objects matching the search criterium
* @todo can be written more efficiently using a new (but very complex) sql query
foreach ($evals as $eval)
// Other methods implementing GradebookItem
return $this->has_results() ? 'evalnotempty' : 'evalempty';
|