more Edit/Outcomes improvements - new course column for standard outcomes; outcomes_course consistency checks; removed debug delays
This commit is contained in:
@@ -45,10 +45,10 @@ foreach ($courseused as $oid) {
|
||||
foreach($co_custom as $oid=>$outcome) {
|
||||
if (!in_array($oid, $courseused)) {
|
||||
$courseused[$oid] = $oid;
|
||||
$obj = new object();
|
||||
$obj->courseid = $courseid;
|
||||
$obj->outcomeid = $oid;
|
||||
insert_record('grade_outcomes_courses', $obj);
|
||||
$goc = new object();
|
||||
$goc->courseid = $courseid;
|
||||
$goc->outcomeid = $oid;
|
||||
insert_record('grade_outcomes_courses', $goc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,10 +63,10 @@ if ($realused = get_records_select('grade_items', "courseid=$courseid and outcom
|
||||
|
||||
if (!in_array($oid, $courseused)) {
|
||||
$courseused[$oid] = $oid;
|
||||
$obj = new object();
|
||||
$obj->courseid = $courseid;
|
||||
$obj->outcomeid = $oid;
|
||||
insert_record('grade_outcomes_courses', $obj);
|
||||
$goc = new object();
|
||||
$goc->courseid = $courseid;
|
||||
$goc->outcomeid = $oid;
|
||||
insert_record('grade_outcomes_courses', $goc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ if ($mform->is_cancelled()) {
|
||||
$outcome->update();
|
||||
}
|
||||
|
||||
redirect($returnurl, 'temp debug delay', 3);
|
||||
redirect($returnurl);
|
||||
}
|
||||
|
||||
$strgrades = get_string('grades');
|
||||
|
||||
@@ -80,9 +80,10 @@ class edit_outcome_form extends moodleform {
|
||||
|
||||
if ($id = $mform->getElementValue('id')) {
|
||||
$outcome = grade_outcome::fetch(array('id'=>$id));
|
||||
$count = $outcome->get_uses_count();
|
||||
$itemcount = $outcome->get_item_uses_count();
|
||||
$coursecount = $outcome->get_course_uses_count();
|
||||
|
||||
if ($count) {
|
||||
if ($itemcount) {
|
||||
$mform->hardFreeze('scaleid');
|
||||
}
|
||||
|
||||
@@ -92,7 +93,7 @@ class edit_outcome_form extends moodleform {
|
||||
} else if (empty($outcome->courseid) and !has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
$mform->hardFreeze('standard');
|
||||
|
||||
} else if ($count and !empty($outcome->courseid)) {
|
||||
} else if ($coursecount and empty($outcome->courseid)) {
|
||||
$mform->hardFreeze('standard');
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,8 @@ $strcustomoutcomes = get_string('outcomescustom', 'grades');
|
||||
$strdelete = get_string('delete');
|
||||
$stredit = get_string('edit');
|
||||
$srtcreatenewoutcome = get_string('outcomecreate', 'grades');
|
||||
$stractivities = get_string('activities');
|
||||
$stritems = get_string('items', 'grades');
|
||||
$strcourses = get_string('courses');
|
||||
$stredit = get_string('edit');
|
||||
|
||||
switch ($action) {
|
||||
@@ -121,13 +122,12 @@ if ($courseid and $outcomes = grade_outcome::fetch_all_local($courseid)) {
|
||||
}
|
||||
}
|
||||
|
||||
$outcomes_uses = $outcome->get_uses_count();
|
||||
$line[] = $outcomes_uses;
|
||||
$line[] = $outcome->get_item_uses_count();
|
||||
|
||||
$buttons = "";
|
||||
$buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$courseid&id=$outcome->id\"><img".
|
||||
" src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
|
||||
if (empty($outcomes_uses)) {
|
||||
if ($outcome->can_delete()) {
|
||||
$buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$courseid&outcomeid=$outcome->id&action=delete&sesskey=$USER->sesskey\"><img".
|
||||
" src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
|
||||
}
|
||||
@@ -135,7 +135,7 @@ if ($courseid and $outcomes = grade_outcome::fetch_all_local($courseid)) {
|
||||
$data[] = $line;
|
||||
}
|
||||
$table = new object();
|
||||
$table->head = array($strfullname, $strshortname, $strscale, $stractivities, $stredit);
|
||||
$table->head = array($strfullname, $strshortname, $strscale, $stritems, $stredit);
|
||||
$table->size = array('30%', '20%', '20%', '20%', '10%');
|
||||
$table->align = array('left', 'left', 'left', 'center', 'center');
|
||||
$table->width = '90%';
|
||||
@@ -172,15 +172,15 @@ if ($outcomes = grade_outcome::fetch_all_global()) {
|
||||
}
|
||||
}
|
||||
|
||||
$outcomes_uses = $outcome->get_uses_count();
|
||||
$line[] = $outcomes_uses;
|
||||
$line[] = $outcome->get_course_uses_count();
|
||||
$line[] = $outcome->get_item_uses_count();
|
||||
|
||||
$buttons = "";
|
||||
if (has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
$buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$courseid&id=$outcome->id\"><img".
|
||||
" src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
|
||||
}
|
||||
if (empty($outcomes_uses) and has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM))) {
|
||||
if (has_capability('moodle/grade:manage', get_context_instance(CONTEXT_SYSTEM)) and $outcome->can_delete()) {
|
||||
$buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$courseid&outcomeid=$outcome->id&action=delete&sesskey=$USER->sesskey\"><img".
|
||||
" src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
|
||||
}
|
||||
@@ -188,9 +188,9 @@ if ($outcomes = grade_outcome::fetch_all_global()) {
|
||||
$data[] = $line;
|
||||
}
|
||||
$table = new object();
|
||||
$table->head = array($strfullname, $strshortname, $strscale, $stractivities, $stredit);
|
||||
$table->size = array('30%', '20%', '20%', '20%', '10%');
|
||||
$table->align = array('left', 'left', 'left', 'center', 'center');
|
||||
$table->head = array($strfullname, $strshortname, $strscale, $strcourses, $stritems, $stredit);
|
||||
$table->size = array('30%', '20%', '20%', '10%', '10%', '10%');
|
||||
$table->align = array('left', 'left', 'left', 'center', 'center', 'center');
|
||||
$table->width = '90%';
|
||||
$table->data = $data;
|
||||
print_table($table);
|
||||
|
||||
@@ -90,7 +90,7 @@ if ($mform->is_cancelled()) {
|
||||
$scale->update();
|
||||
}
|
||||
|
||||
redirect($returnurl, 'temp debug delay', 3);
|
||||
redirect($returnurl);
|
||||
}
|
||||
|
||||
$strgrades = get_string('grades');
|
||||
|
||||
+50
-10
@@ -78,6 +78,35 @@ class grade_outcome extends grade_object {
|
||||
*/
|
||||
var $usermodified;
|
||||
|
||||
/**
|
||||
* Deletes this outcome from the database.
|
||||
* @param string $source from where was the object deleted (mod/forum, manual, etc.)
|
||||
* @return boolean success
|
||||
*/
|
||||
function delete($source=null) {
|
||||
if (!empty($this->courseid)) {
|
||||
delete_records('grade_outcomes_courses', 'outcomeid', $this->id, 'courseid', $this->courseid);
|
||||
}
|
||||
return parent::delete($source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Records this object in the Database, sets its id to the returned value, and returns that value.
|
||||
* If successful this function also fetches the new object data from database and stores it
|
||||
* in object properties.
|
||||
* @param string $source from where was the object inserted (mod/forum, manual, etc.)
|
||||
* @return int PK ID if successful, false otherwise
|
||||
*/
|
||||
function insert($source=null) {
|
||||
if ($result = parent::insert($source)) {
|
||||
$goc = new object();
|
||||
$goc->courseid = $this->courseid;
|
||||
$goc->outcomeid = $this->id;
|
||||
insert_record('grade_outcomes_courses', $goc);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds and returns a grade_outcome instance based on params.
|
||||
* @static
|
||||
@@ -150,26 +179,37 @@ class grade_outcome extends grade_object {
|
||||
* @return boolean
|
||||
*/
|
||||
function can_delete() {
|
||||
$count = $this->get_uses_count();
|
||||
return empty($count);
|
||||
if ($this->get_item_uses_count()) {
|
||||
return false;
|
||||
}
|
||||
if (empty($this->courseid)) {
|
||||
if ($this->get_course_uses_count()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of places where outcome is used.
|
||||
* @return int
|
||||
*/
|
||||
function get_uses_count() {
|
||||
function get_course_uses_count() {
|
||||
global $CFG;
|
||||
|
||||
$count = 0;
|
||||
|
||||
// count grade items
|
||||
$sql = "SELECT COUNT(id) FROM {$CFG->prefix}grade_items WHERE outcomeid = {$this->id}";
|
||||
if ($scales_uses = count_records_sql($sql)) {
|
||||
$count += $scales_uses;
|
||||
if (!empty($this->courseid)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return $count;
|
||||
return count_records('grade_outcomes_courses', 'outcomeid', $this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of places where outcome is used.
|
||||
* @return int
|
||||
*/
|
||||
function get_item_uses_count() {
|
||||
return count_records('grade_items', 'outcomeid', $this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user