Skip to content

Commit

Permalink
edit/outcomeitem.php - fixed selection of outcomes to show only avail…
Browse files Browse the repository at this point in the history
…able course outcomes
  • Loading branch information
skodak committed Jul 31, 2007
1 parent 4c2402b commit 2fa3ea1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
10 changes: 3 additions & 7 deletions grade/edit/outcome/course.php
Expand Up @@ -19,13 +19,9 @@
$gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'outcomes', 'courseid'=>$courseid));

// first of all fix the state of outcomes_course table
if (!$standardoutcomes = grade_outcome::fetch_all_global()) {
$standardoutcomes = array();
}
if (!$co_custom = grade_outcome::fetch_all_local($courseid)) {
$co_custom = array();
}
$co_standard_used = array();
$standardoutcomes = grade_outcome::fetch_all_global();
$co_custom = grade_outcome::fetch_all_local($courseid);
$co_standard_used = array();
$co_standard_notused = array();

if ($courseused = get_records('grade_outcomes_courses', 'courseid', $courseid, '', 'outcomeid')) {
Expand Down
2 changes: 1 addition & 1 deletion grade/edit/tree/outcomeitem_form.php
Expand Up @@ -20,7 +20,7 @@ function definition() {

// allow setting of outcomes on module items too
$options = array();
if ($outcomes = grade_outcome::fetch_all(array('courseid'=>$COURSE->id), true)) {
if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) {
foreach ($outcomes as $outcome) {
$options[$outcome->id] = $outcome->get_name();
}
Expand Down
39 changes: 37 additions & 2 deletions lib/grade/grade_outcome.php
Expand Up @@ -162,20 +162,55 @@ function load_scale() {

/**
* Static function returning all global outcomes
* @static
* @return object
*/
function fetch_all_global() {
return grade_outcome::fetch_all(array('courseid'=>null));
if (!$outcomes = grade_outcome::fetch_all(array('courseid'=>null))) {
$outcomes = array();
}
return $outcomes;
}

/**
* Static function returning all local course outcomes
* @static
* @param int $courseid
* @return object
*/
function fetch_all_local($courseid) {
return grade_outcome::fetch_all(array('courseid'=>$courseid));
if (!$outcomes =grade_outcome::fetch_all(array('courseid'=>$courseid))) {
$outcomes = array();
}
return $outcomes;
}

/**
* Static method - returns all outcomes available in course
* @static
* @param int $courseid
* @return array
*/
function fetch_all_available($courseid) {
global $CFG;

$result = array();
$sql = "SELECT go.*
FROM {$CFG->prefix}grade_outcomes go, {$CFG->prefix}grade_outcomes_courses goc
WHERE go.id = goc.outcomeid AND goc.courseid = {$courseid}
ORDER BY go.id ASC";

if ($datas = get_records_sql($sql)) {
foreach($datas as $data) {
$instance = new grade_outcome();
grade_object::set_properties($instance, $data);
$result[$instance->id] = $instance;
}
}
return $result;
}


/**
* Returns the most descriptive field for this object. This is a standard method used
* when we do not know the exact type of an object.
Expand Down

0 comments on commit 2fa3ea1

Please sign in to comment.