Source for file gradebook_data_generator.class.php
Documentation is available at gradebook_data_generator.class.php
* Class to select, sort and transform object data into array data,
* used for the general gradebook view
// Sorting types constants
const GDG_SORT_DESCRIPTION = 4;
const GDG_SORT_WEIGHT = 8;
const GDG_SORT_DATE = 16;
const GDG_SORT_DESC = 64;
$allcats = (isset ($cats) ? $cats : array());
$allevals = (isset ($evals) ? $evals : array());
$alllinks = (isset ($links) ? $links : array());
// merge categories, evaluations and links
* Get total number of items (rows)
* @return array 2-dimensional array - each array contains the elements:
* 0: cat/eval/link object
* 5: student's score (if student logged in)
public function get_data ($sorting = 0, $start = 0, $count = null, $ignore_score_color = false)
// do some checks on count, redefine if invalid value
$allitems = $this->items;
if ($sorting & self :: GDG_SORT_TYPE)
usort($allitems, array('GradebookDataGenerator', 'sort_by_type'));
elseif ($sorting & self :: GDG_SORT_NAME)
usort($allitems, array('GradebookDataGenerator', 'sort_by_name'));
elseif ($sorting & self :: GDG_SORT_DESCRIPTION)
usort($allitems, array('GradebookDataGenerator', 'sort_by_description'));
elseif ($sorting & self :: GDG_SORT_WEIGHT)
usort($allitems, array('GradebookDataGenerator', 'sort_by_weight'));
elseif ($sorting & self :: GDG_SORT_DATE)
usort($allitems, array('GradebookDataGenerator', 'sort_by_date'));
if ($sorting & self :: GDG_SORT_DESC)
$visibleitems = array_slice($allitems, $start, $count);
// generate the data to display
foreach ($visibleitems as $item)
$row[] = $item->get_name();
$row[] = $item->get_description();
$row[] = $item->get_weight();
* Returns the link to the certificate generation, if the score is enough, otherwise
* returns an empty string. This only works with categories.
if(is_a($item, 'Category'))
$link = '<a href="gradebook.php?export_certificate=1&cat='. $item->get_id(). '&user='. api_get_user_id(). '">'. get_lang('Certificate'). '</a>';
// Make sure to only use functions as defined in the GradebookItem interface !
if ($item1->get_item_type() == $item2->get_item_type())
return ($item1->get_item_type() < $item2->get_item_type() ? - 1 : 1);
if ($item1->get_weight() == $item2->get_weight())
return ($item1->get_weight() < $item2->get_weight() ? - 1 : 1);
if ($item1->get_date() == $item2->get_date())
return ($item1->get_date() < $item2->get_date() ? - 1 : 1);
switch ($item->get_item_type())
. $scoredisplay->display_score($score,$displaytype);
return $scoredisplay->display_score($score,$displaytype);
$date = $item->get_date();
if (!isset ($date) || empty($date))
return date("j/n/Y g:i", $date);
|