Skip to content

Commit

Permalink
MDL-9628 Moving Basic support for compact view from report class to g…
Browse files Browse the repository at this point in the history
…rade_category class, internal to the grade_tree recursive construction
  • Loading branch information
nicolasconnault committed Jul 25, 2007
1 parent e7bbdbb commit 438a5aa
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 55 deletions.
10 changes: 5 additions & 5 deletions grade/report/grader/index.php
Expand Up @@ -116,6 +116,11 @@
//first make sure we have proper final grades - this must be done before constructing of the grade tree
grade_regrade_final_grades($courseid);

// Perform actions
if (!empty($target) && !empty($action) && confirm_sesskey()) {
grade_report_grader::process_action($target, $action);
}

// Initialise the grader report object
$report = new grade_report_grader($courseid, $gpr, $context, $page, $sortitemid);

Expand All @@ -129,11 +134,6 @@
$report->user_prefs['studentsperpage'] = $perpageurl;
}

// Perform actions
if (!empty($target) && !empty($action) && confirm_sesskey()) {
$report->process_action($target, $action);
}

$report->load_users();
$numusers = $report->get_numusers();
$report->load_final_grades();
Expand Down
45 changes: 2 additions & 43 deletions grade/report/grader/lib.php
Expand Up @@ -415,48 +415,7 @@ function get_headerhtml() {
$eid = $element['eid'];
$object = $element['object'];
$type = $element['type'];

// Load user preferences for categories
if ($type == 'category') {
$categoryid = $element['object']->id;
$aggregationview = $this->get_pref('aggregationview', $categoryid);


if ($aggregationview == GRADE_REPORT_AGGREGATION_VIEW_COMPACT) {
$categorystate = get_user_preferences('grade_report_categorystate' . $categoryid, GRADE_CATEGORY_EXPANDED);

$hideall = false;
if (in_array($eid, $columns_to_unset)) {
$categorystate = GRADE_CATEGORY_CONTRACTED;
$hideall = true;
}

// Expand/Contract icon must be set appropriately
if ($categorystate == GRADE_CATEGORY_CONTRACTED) {
// The category is contracted: this means we only show 1 item for this category: the
// category's aggregation item. The others must be removed from the grade_tree
$element['colspan'] = 1;
foreach ($element['children'] as $index => $child) {
if ($child['type'] != 'categoryitem' OR $hideall) {
$columns_to_unset[] = $child['eid'];
}
}

} elseif ($categorystate == GRADE_CATEGORY_EXPANDED) {
// The category is expanded: we only show the non-aggregated items directly descending
// from this category. The category's grade_item must be removed from the grade_tree
$element['colspan']--;
foreach ($element['children'] as $index => $child) {
if ($child['type'] == 'categoryitem') {
$columns_to_unset[] = $child['eid'];
}
}
} else {
debugging("The category state ($categorystate) was not amongst the allowed values (0 or 1)");
var_dump($element);
}
}
} // End of category handling
$categorystate = @$element['categorystate'];

if (!empty($element['colspan'])) {
$colspan = 'colspan="'.$element['colspan'].'"';
Expand Down Expand Up @@ -936,7 +895,7 @@ function get_icons($element) {
}

// If object is a category, display expand/contract icon
if ($element['type'] == 'category' && $this->get_pref('aggregationview') == GRADE_REPORT_AGGREGATION_VIEW_COMPACT) {
if ($element['type'] == 'category' && $this->get_pref('aggregationview', $element['object']->id) == GRADE_REPORT_AGGREGATION_VIEW_COMPACT) {
// Load language strings
$strswitch_minus = $this->get_lang_string('contract', 'grades');
$strswitch_plus = $this->get_lang_string('expand', 'grades');
Expand Down
2 changes: 1 addition & 1 deletion grade/report/lib.php
Expand Up @@ -135,7 +135,7 @@ function get_pref($pref, $objectid=null) {

$retval = null;

if (!isset($this)) {
if (!isset($this) OR get_class($this) != 'grade_report') {
if (!empty($objectid)) {
$retval = get_user_preferences($fullprefname . $objectid, grade_report::get_pref($pref));
} else {
Expand Down
54 changes: 48 additions & 6 deletions lib/grade/grade_category.php
Expand Up @@ -628,14 +628,41 @@ function has_children() {
*/
function fetch_course_tree($courseid, $include_category_items=false) {
$course_category = grade_category::fetch_course_category($courseid);
$category_array = array('object'=>$course_category, 'type'=>'category', 'depth'=>1,
$categorystate = grade_category::get_categorystate($course_category);
if ($categorystate == GRADE_CATEGORY_EXPANDED) {
$include_category_items = false;
}

$category_array = array('object'=>$course_category,
'type'=>'category',
'depth'=>1,
'categorystate' => $categorystate,
'children'=>$course_category->get_children($include_category_items));

$sortorder = 1;
$course_category->set_sortorder($sortorder);
$course_category->sortorder = $sortorder;
return grade_category::_fetch_course_tree_recursion($category_array, $sortorder);
}

/**
* Checks the user preferences and returns the state of the category, for display purposes. This only
* applies when aggregationview is set to COMPACT.
* @param object $category_element
* @return int null, GRADE_CATEGORY_EXPANDED or GRADE_CATEGORY_CONTRACTED
*/
function get_categorystate($category_element) {
global $CFG;
require_once($CFG->dirroot . '/grade/report/lib.php');
$aggregationview = grade_report::get_pref('aggregationview', $category_element->id);

$categorystate = null;
if ($aggregationview == GRADE_REPORT_AGGREGATION_VIEW_COMPACT) {
$categorystate = get_user_preferences('grade_report_categorystate' . $category_element->id, GRADE_CATEGORY_EXPANDED);
}
return $categorystate;
}

function _fetch_course_tree_recursion($category_array, &$sortorder) {
// update the sortorder in db if needed
if ($category_array['object']->sortorder != $sortorder) {
Expand Down Expand Up @@ -742,25 +769,40 @@ function get_children($include_category_items=false) {
function _get_children_recursion($category) {

$children_array = array();
$categorystate = grade_category::get_categorystate($category);

foreach($category->children as $sortorder=>$child) {
if (array_key_exists('itemtype', $child)) {
$grade_item = new grade_item($child, false);
if (in_array($grade_item->itemtype, array('course', 'category'))) {
$type = $grade_item->itemtype.'item';
$depth = $category->depth;
if (in_array($grade_item->itemtype, array('course', 'category'))) { // Child is a course or categoryitem
if ($categorystate == GRADE_CATEGORY_EXPANDED) {
continue;
} else {
$type = $grade_item->itemtype.'item';
$depth = $category->depth;
}
} else {
if ($categorystate == GRADE_CATEGORY_CONTRACTED) {
continue;
}
$type = 'item';
$depth = $category->depth; // we use this to set the same colour
}
$children_array[$sortorder] = array('object'=>$grade_item, 'type'=>$type, 'depth'=>$depth);
$children_array[$sortorder] = array('object'=>$grade_item,
'type'=>$type,
'depth'=>$depth);

} else {
$children = grade_category::_get_children_recursion($child);
$grade_category = new grade_category($child, false);
if (empty($children)) {
$children = array();
}
$children_array[$sortorder] = array('object'=>$grade_category, 'type'=>'category', 'depth'=>$grade_category->depth, 'children'=>$children);
$children_array[$sortorder] = array('object'=>$grade_category,
'type'=>'category',
'depth'=>$grade_category->depth,
'categorystate' => $categorystate,
'children'=>$children);
}
}

Expand Down

0 comments on commit 438a5aa

Please sign in to comment.