From ba92364c8b577f36be607e8b0df959a9bf7a62d8 Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Mon, 23 Jul 2007 14:33:02 +0000 Subject: [PATCH] MDL-10550 --- grade/report/outcomes/editoutcomes.php | 22 +++++---- grade/report/outcomes/index.php | 44 +++++++++++++++++ grade/report/outcomes/settings.php | 23 +++++---- grade/report/outcomes/tabs.php | 19 +++++++ lib/grade/grade_outcome.php | 68 ++++++++++++++++++++++++++ 5 files changed, 157 insertions(+), 19 deletions(-) create mode 100644 grade/report/outcomes/index.php create mode 100644 grade/report/outcomes/tabs.php diff --git a/grade/report/outcomes/editoutcomes.php b/grade/report/outcomes/editoutcomes.php index 8732016b1c..8f995a4b32 100755 --- a/grade/report/outcomes/editoutcomes.php +++ b/grade/report/outcomes/editoutcomes.php @@ -9,19 +9,19 @@ class edit_outcomes_form extends moodleform { $mform =& $this->_form; $mform->addElement('header', 'general', get_string('outcomes')); - + $mform->addElement('text', 'shortname', get_string('shortname')); $mform->addRule('shortname', get_string('required'), 'required'); $mform->setType('id', PARAM_TEXT); - + $mform->addElement('text', 'fullname', get_string('fullname')); $mform->addRule('fullname', get_string('required'), 'required'); $mform->setType('id', PARAM_TEXT); - + $scalearr = array(); if ($scales = get_records('scale')) { foreach ($scales as $scale) { - $scalearr[$scale->id] = $scale->name; + $scalearr[$scale->id] = $scale->name; } } @@ -37,7 +37,7 @@ class edit_outcomes_form extends moodleform { } $id = optional_param('id', 0, PARAM_INT); // id of the outcome -if ($courseid = optional_param('courseid', 0, PARAM_INT)) { +if ($courseid = optional_param('courseid', 0, PARAM_INT)) { // optional course id, if set, editting from course } else { // admin editting site level outcomes @@ -47,12 +47,12 @@ if ($courseid = optional_param('courseid', 0, PARAM_INT)) { $mform = new edit_outcomes_form(); if ($id) { - // form set data - $mform->set_data(get_record('grade_outcomes', 'id', $id)); + // form set data + $mform->set_data(get_record('grade_outcomes', 'id', $id)); } if ($mform->is_cancelled()) { - redirect($returnurl); + redirect($returnurl); } if ($data = $mform->get_data()) { if ($data->id) { @@ -63,7 +63,11 @@ if ($data = $mform->get_data()) { redirect($returnurl); } +// Add tabs +$currenttab = 'editoutcomes'; +include('tabs.php'); + print_header(); $mform->display(); print_footer(); -?> \ No newline at end of file +?> diff --git a/grade/report/outcomes/index.php b/grade/report/outcomes/index.php new file mode 100644 index 0000000000..4e51060db3 --- /dev/null +++ b/grade/report/outcomes/index.php @@ -0,0 +1,44 @@ +libdir . '/gradelib.php'); + +$courseid = required_param('id'); // course id + +if (!$course = get_record('course', 'id', $courseid)) { + print_error('nocourseid'); +} + +require_login($course->id); + +$context = get_context_instance(CONTEXT_COURSE, $course->id); + +// Build navigation +$strgrades = get_string('grades'); +$stroutcomes = get_string('outcomes', 'grades'); +$navlinks = array(); +$navlinks[] = array('name' => $strgrades, 'link' => $CFG->wwwroot . '/grade/index.php?id='.$courseid, 'type' => 'misc'); +$navlinks[] = array('name' => $stroutcomes, 'link' => '', 'type' => 'misc'); + +$navigation = build_navigation($navlinks); + +/// Print header +print_header_simple($strgrades.':'.$stroutcomes, ':'.$strgrades, $navigation, '', '', true); + +// Add tabs +$currenttab = 'outcomereport'; +include('tabs.php'); + +// Grab outcomes in use for this course +$outcomes = grade_outcome::fetch_all(array('courseid' => $courseid)); +foreach ($outcomes as $outcome) { + print_object($outcome->get_grade_info($courseid, true, true)); +} +// Grab activities that are grading against each outcome (with links to activities) + +// Compute average grade across all activities and users for each outcome. + + +print_footer($course); + +?> diff --git a/grade/report/outcomes/settings.php b/grade/report/outcomes/settings.php index 7e9f8b74d6..ccb4aa2305 100755 --- a/grade/report/outcomes/settings.php +++ b/grade/report/outcomes/settings.php @@ -27,45 +27,48 @@ admin_externalpage_setup('gradereportoutcomes'); admin_externalpage_print_header(); /******************* ADD TABS HERE LATER ****************************/ +// Add tabs +$currenttab = 'outcomesettings'; +include('tabs.php'); $totalcount = count_records('grade_outcomes'); $baseurl = "settings.php"; print_paging_bar($totalcount, $page, $perpage, $baseurl); if ($outcomes = get_recordset('grade_outcomes', '', '', '', '*', $page * $perpage, $perpage)) { - + $tablecolumns = array('outcome', 'edit', 'usedgradeitems', 'usedcourses'); $tableheaders = array(get_string('outcomes'), get_string('operations'), get_string('usedgradeitem'), get_string('usedcourses')); - + $table = new flexible_table('outcomes'); $table->define_columns($tablecolumns); $table->define_headers($tableheaders); $table->define_baseurl($baseurl); $table->set_attribute('cellspacing', '0'); $table->set_attribute('id', 'user-grade'); - $table->set_attribute('class', 'boxaligncenter generaltable'); - + $table->set_attribute('class', 'boxaligncenter generaltable'); + $table->setup(); - + foreach ($outcomes as $outcome) { $data = array(); $data[] = $outcome['fullname']; - + // add operations $data[] = 'Update Delete'; // icons and links - + // num of gradeitems using this $num = count_records('grade_outcomes_courses', 'outcomeid' ,$outcome['id']); $data[] = (int) $num; - + // num of courses using this outcome $num = count_records('grade_items', 'outcomeid', $outcome['id']); $data[] = (int) $num; $table->add_data($data); } - + $table->print_html(); } @@ -73,4 +76,4 @@ echo 'Add a new outcome'; // print the footer, end of page admin_externalpage_print_footer(); -?> \ No newline at end of file +?> diff --git a/grade/report/outcomes/tabs.php b/grade/report/outcomes/tabs.php new file mode 100644 index 0000000000..b3edd542ef --- /dev/null +++ b/grade/report/outcomes/tabs.php @@ -0,0 +1,19 @@ +wwwroot.'/grade/report/outcomes/index.php?id='.$courseid, + get_string('outcomereport', 'grades')); + + $row[] = new tabobject('outcomesettings', + $CFG->wwwroot.'/grade/report/outcomes/settings.php?id='.$courseid, + get_string('settings')); + + $row[] = new tabobject('editoutcomes', + $CFG->wwwroot.'/grade/report/outcomes/editoutcomes.php?courseid='.$courseid, + get_string('editoutcomes', 'grades')); + + $tabs[] = $row; + echo '
'; + print_tabs($tabs, $currenttab); + echo '
'; +?> diff --git a/lib/grade/grade_outcome.php b/lib/grade/grade_outcome.php index 6eff9d27e2..b49cea09fa 100644 --- a/lib/grade/grade_outcome.php +++ b/lib/grade/grade_outcome.php @@ -128,5 +128,73 @@ class grade_outcome extends grade_object { function get_name() { return $this->shortname; } + + /** + * Computes then returns extra information about this outcome and other objects that are linked to it. + * The average of all grades that use this outcome, for all courses (or 1 course if courseid is given) can + * be requested, and is returned as a float if requested alone. If the list of items that use this outcome + * is also requested, then a single array is returned, which contains the grade_items AND the average grade + * if such is still requested (array('items' => array(...), 'avg' => 2.30)). This combining of two + * methods into one is to save on DB queries, since both queries are similar and can be performed together. + * @param int $courseid An optional courseid to narrow down the average to 1 course only + * @param bool $average Whether or not to return the average grade for this outcome + * @param bool $items Whether or not to return the list of items using this outcome + * @return float + */ + function get_grade_info($courseid=null, $average=true, $items=false) { + if (!isset($this->id)) { + debugging("You must setup the outcome's id before calling its get_grade_info() method!"); + return false; // id must be defined for this to work + } + + if ($average === false && $items === false) { + debugging('Either the 1st or 2nd param of grade_outcome::get_grade_info() must be true, or both, but not both false!'); + return false; + } + + $wheresql = ''; + if (!is_null($courseid)) { + $wheresql = " AND mdl_grade_items.courseid = $courseid "; + } + + $selectadd = ''; + if ($items !== false) { + $selectadd = ', mdl_grade_items.* '; + } + + $sql = "SELECT finalgrade $selectadd + FROM mdl_grade_grades, mdl_grade_items, mdl_grade_outcomes + WHERE mdl_grade_outcomes.id = mdl_grade_items.outcomeid + AND mdl_grade_items.id = mdl_grade_grades.itemid + AND mdl_grade_outcomes.id = $this->id + $wheresql"; + + $grades = get_records_sql($sql); + $retval = array(); + + if ($average !== false && count($grades) > 0) { + $count = 0; + $total = 0; + + foreach ($grades as $k => $grade) { + // Skip null finalgrades + if (!is_null($grade->finalgrade)) { + $total += $grade->finalgrade; + $count++; + } + unset($grades[$k]->finalgrade); + } + + $retval['avg'] = $total / $count; + } + + if ($items !== false) { + foreach ($grades as $grade) { + $retval['items'][$grade->id] = new grade_item($grade); + } + } + + return $retval; + } } ?> -- 2.39.5