Skip to content

Commit

Permalink
more Edit/Outcomes improvements - new course column for standard outc…
Browse files Browse the repository at this point in the history
…omes; outcomes_course consistency checks; removed debug delays
  • Loading branch information
skodak committed Jul 31, 2007
1 parent b4ff035 commit 3818937
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 34 deletions.
16 changes: 8 additions & 8 deletions grade/edit/outcome/course.php
Expand Up @@ -45,10 +45,10 @@
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);
}
}

Expand All @@ -63,10 +63,10 @@

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);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion grade/edit/outcome/edit.php
Expand Up @@ -93,7 +93,7 @@
$outcome->update();
}

redirect($returnurl, 'temp debug delay', 3);
redirect($returnurl);
}

$strgrades = get_string('grades');
Expand Down
7 changes: 4 additions & 3 deletions grade/edit/outcome/edit_form.php
Expand Up @@ -80,9 +80,10 @@ function definition_after_data() {

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');
}

Expand All @@ -92,7 +93,7 @@ function definition_after_data() {
} 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');
}

Expand Down
22 changes: 11 additions & 11 deletions grade/edit/outcome/index.php
Expand Up @@ -41,7 +41,8 @@
$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) {
Expand Down Expand Up @@ -121,21 +122,20 @@
}
}

$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&amp;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&amp;outcomeid=$outcome->id&amp;action=delete&amp;sesskey=$USER->sesskey\"><img".
" src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
}
$line[] = $buttons;
$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%';
Expand Down Expand Up @@ -172,25 +172,25 @@
}
}

$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&amp;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&amp;outcomeid=$outcome->id&amp;action=delete&amp;sesskey=$USER->sesskey\"><img".
" src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
}
$line[] = $buttons;
$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);
Expand Down
2 changes: 1 addition & 1 deletion grade/edit/scale/edit.php
Expand Up @@ -90,7 +90,7 @@
$scale->update();
}

redirect($returnurl, 'temp debug delay', 3);
redirect($returnurl);
}

$strgrades = get_string('grades');
Expand Down
60 changes: 50 additions & 10 deletions lib/grade/grade_outcome.php
Expand Up @@ -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
Expand Down Expand Up @@ -150,26 +179,37 @@ function get_shortname() {
* @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);
}

/**
Expand Down

0 comments on commit 3818937

Please sign in to comment.