]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10544 placeholder for outcome edit forms grade/edit/outcome/
authorskodak <skodak>
Sun, 29 Jul 2007 23:02:03 +0000 (23:02 +0000)
committerskodak <skodak>
Sun, 29 Jul 2007 23:02:03 +0000 (23:02 +0000)
MDL-10650 scales code moved to grade/edit/scale/
refactoring in grade/edit/

24 files changed:
blocks/admin/block_admin.php
course/scales.php
grade/edit/outcome/index.php [new file with mode: 0644]
grade/edit/scale/edit.php [new file with mode: 0644]
grade/edit/scale/edit_form.php [new file with mode: 0644]
grade/edit/scale/index.php [new file with mode: 0644]
grade/edit/tree/action.php [moved from grade/edit/action.php with 96% similarity]
grade/edit/tree/calculation.php [moved from grade/edit/calculation.php with 98% similarity]
grade/edit/tree/calculation_form.php [moved from grade/edit/calculation_form.php with 100% similarity]
grade/edit/tree/category.php [moved from grade/edit/category.php with 95% similarity]
grade/edit/tree/category_form.php [moved from grade/edit/category_form.php with 100% similarity]
grade/edit/tree/grade.php [moved from grade/edit/grade.php with 99% similarity]
grade/edit/tree/grade_form.php [moved from grade/edit/grade_form.php with 100% similarity]
grade/edit/tree/index.php [moved from grade/edit/tree.php with 98% similarity]
grade/edit/tree/item.php [moved from grade/edit/item.php with 92% similarity]
grade/edit/tree/item_form.php [moved from grade/edit/item_form.php with 100% similarity]
grade/edit/tree/outcomeitem.php [moved from grade/edit/outcomeitem.php with 95% similarity]
grade/edit/tree/outcomeitem_form.php [moved from grade/edit/outcomeitem_form.php with 100% similarity]
grade/lib.php
lang/en_utf8/gradereport_outcomes.php
lang/en_utf8/grades.php
lib/grade/grade_scale.php
theme/standard/styles_fonts.css
theme/standard/styles_layout.css

index 66d3787def5612efc2d3eb35e368faca7d77bb08..60e4b5c4a91a5c1a287b8b937063ea7e47719339 100644 (file)
@@ -131,7 +131,7 @@ class block_admin extends block_list {
 
     /// Manage scales
         if (has_capability('moodle/course:managescales', $context) && ($course->id!==SITEID)) {
-            $this->content->items[]='<a href="scales.php?id='.$this->instance->pageid.'">'.get_string('scales').'</a>';
+            $this->content->items[]='<a href="'.$CFG->wwwroot.'/grade/edit/scale/index.php?id='.$this->instance->pageid.'">'.get_string('scales').'</a>';
             $this->content->icons[]='<img src="'.$CFG->pixpath.'/i/scales.gif" class="icon" alt="" />';      
         }
         
index efbe8cf763cd83449d9c49666aee8556f15d15fc..3759a1f45e47eac92030a60208507c7a5da98fdf 100644 (file)
@@ -4,19 +4,15 @@
     require_once("../config.php");
     require_once("lib.php");
 
-    $id          = required_param('id', PARAM_INT);               // course id
-    $scaleid     = optional_param('scaleid', 0, PARAM_INT);       // scale id
-    $action      = optional_param('action', 'undefined', PARAM_ALPHA); // action to execute
-    $name        = optional_param('name', '', PARAM_CLEAN);       // scale name
-    $description = optional_param('description', '', PARAM_CLEAN);// scale description
-    $list        = optional_param('list', 0, PARAM_BOOL);         // show listing in help window
+    $id   = required_param('id', PARAM_INT);               // course id
 
     if (! $course = get_record("course", "id", $id)) {
         error("Course ID was incorrect");
     }
 
-    require_login($course->id);
+    require_login($course);
     $context = get_context_instance(CONTEXT_COURSE, $course->id);
+    require_capability('moodle/course:viewscales', $context);
 
     $strscale = get_string("scale");
     $strscales = get_string("scales");
     $strstandardscales = get_string("scalesstandard");
     $strname = get_string("name");
     $strdescription = get_string("description");
-    $strsavechanges = get_string("savechanges");
-    $strchangessaved = get_string("changessaved");
-    $strdeleted = get_string("deleted");
-    $strdelete = get_string("delete");
-    $stredit = get_string("edit");
-    $strdown = get_string("movedown");
-    $strup = get_string("moveup");
-    $strmoved = get_string("changessaved");
-    $srtcreatenewscale = get_string("scalescustomcreate");
     $strhelptext = get_string("helptext");
     $stractivities = get_string("activities");
-    $stroptions = get_string("action");
-    $strtype = get_string("group");
 
-    /// init this here so we can pass it by reference to every call to site_scale_used to avoid getting the courses out of the db over and over again
-    $courses = array();
 
-    /// If scale data is being submitted, then save it and continue
-    $focus = "";
-    $errors = NULL;
+    print_header($strscales);
 
-    if ($action == 'sendform' and confirm_sesskey()) {
-        if ($form = data_submitted()) {
-            if (empty($form->name)) {
-                $errors[$scaleid]->name = true;
-                $focus = "form$scaleid.save";
-            }
-            if (empty($form->scalescale)) {
-                $errors[$scaleid]->scalescale = true;
-                $focus = "form$scaleid.save";
-            }
+    if ($scales = get_records("scale", "courseid", "$course->id", "name ASC")) {
+        print_heading($strcustomscales);
 
-            if (!$errors) {
-                $newscale=NULL;
-                $newscale->name = $form->name;
-                $newscale->scale = $form->scalescale;
-                $newscale->description = $form->description;
-                $newscale->courseid = $form->courseid;
-                $newscale->userid = $USER->id;
-                $newscale->timemodified = time();
-
-                if (empty($scaleid)) {
-                    $newscale->courseid = $course->id;
-                    if (!insert_record("scale", $newscale)) {
-                        error("Could not insert the new scale!");
-                    }
-                } else {
-                    $newscale->id = $scaleid;
-                    if (!update_record("scale", $newscale)) {
-                        error("Could not update that scale!");
-                    }
-                }
-
-                $notify = "$newscale->name: $strchangessaved";
-                $focus = "form$scaleid.save";
-            } else {
-                if (!empty($scaleid)) {
-                    $action = "edit";
-                } else {
-                    $action = "new";
-                }
-            }
-        }
-    }
-
-    //If action is details, show the popup info
-    if ($action == "details") {
-        //Check for teacher edit
-           require_capability('moodle/course:managescales', $context);
-       
-        //Check for scale
-        if (! $scale = get_record("scale", "id", $scaleid)) {
-            error("Scale ID was incorrect");
+        if (has_capability('moodle/course:managescales', $context)) {
+            echo "<p align=\"center\">(";
+            print_string("scalestip");
+            echo ")</p>";
         }
 
-        //        $scales_course_uses = course_scale_used($course->id,$scale->id);
-        //        $scales_site_uses = site_scale_used($scale->id,$courses);
-        $scalemenu = make_menu_from_list($scale->scale);
-
-        print_header("$course->shortname: $strscales", $course->fullname,
-                 "$course->shortname -> $strscales -> $scale->name", "", "", true, "&nbsp;", "&nbsp;");
-
-        close_window_button();
-
-        echo "<p/>";
-        print_simple_box_start("center");
-        print_heading($scale->name);
-        echo "<center>";
-        choose_from_menu($scalemenu, "", "", "");
-        echo "</center>";
-        echo text_to_html($scale->description);
-        print_simple_box_end();
-        echo "<p/>";
-
-        close_window_button();
-        print_footer();
-        exit;
-    }
-
-    //If action is edit or new, show the form
-    if ($action == "edit" || $action == "new") {
+        foreach ($scales as $scale) {
+            $scalemenu = make_menu_from_list($scale->scale);
 
-        $sesskey = !empty($USER->id) ? $USER->sesskey : '';
-
-           require_capability('moodle/course:managescales', $context);
-           
-        //Check for scale if action = edit
-        if ($action == "edit") {
-            if (! $scale = get_record("scale", "id", $scaleid)) {
-                error("Scale ID was incorrect");
-            }
-        } else {
-            $scale = new object();
-            $scale->id = 0;
-            $scale->courseid = $course->id;
-            $scale->name = "";
-            $scale->scale = "";
-            $scale->description = "";
-        }
-
-        //Calculate the uses
-        if ($scale->courseid == 0) {
-            $scale_uses = site_scale_used($scale->id,$courses);
-        } else {
-            $scale_uses = course_scale_used($course->id,$scale->id);
-        }
-
-        //Check for scale_uses
-        if (!empty($scale_uses)) {
-            error("Scale is in use and cannot be modified",$CFG->wwwroot.'/course/scales.php?id='.$course->id);
+            print_simple_box_start("center");
+            print_heading($scale->name);
+            echo "<center>";
+            choose_from_menu($scalemenu, "", "", "");
+            echo "</center>";
+            echo text_to_html($scale->description);
+            print_simple_box_end();
+            echo "<hr />";
         }
 
-        //Check for standard scales
-        if ($scale->courseid == 0 and !has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
-            error("Only administrators can edit this scale",$CFG->wwwroot.'/course/scales.php?id='.$course->id);
-        }
-
-        //Print out the headers
-        print_header("$course->shortname: $strscales", $course->fullname,
-                 "<a href=\"view.php?id=$course->id\">$course->shortname</a>".
-                 " -> <a href=\"scales.php?id=$course->id\">$strscales</a>".
-                 " -> ".get_string("editinga","",$strscale), $focus);
-
-        //Title
-        print_heading_with_help($strscales, "scales");
-
-        if (!empty($errors) and ($form->scaleid == $scale->id)) {
-            $scale->name = $form->name;
-            $scale->scale = $form->scalescale;
-            $scale->description = $form->description;
-        }
-        echo "<form method=\"post\" action=\"scales.php\" id=\"form$scale->id\">";
-        echo "<table cellpadding=\"9\" cellspacing=\"0\" align=\"center\" class=\"generalbox\">";
-        echo "<tr valign=\"top\">";
-        if (!empty($errors[$scale->id]->name)) {
-            $class = "class=\"highlight\"";
-        } else {
-            $class = "";
+    } else {
+        if (has_capability('moodle/course:managescales', $context)) {
+            echo "<p align=\"center\">(";
+            print_string("scalestip");
+            echo ")</p>";
         }
-        echo "<td align=\"right\"><b>$strname:</b></td>";
-        echo "<td $class><input type=\"text\" name=\"name\" size=\"50\" value=\"".s($scale->name)."\" />";
-        echo "</td>";
-        echo "</tr>";
-        echo "<tr valign=\"top\">";
-        if (!empty($errors[$scale->id]->scalescale)) {
-            $class = "class=\"highlight\"";
-        } else {
-            $class = "";
-        }
-        echo "<td align=\"right\"><b>$strscale:</b></td>";
-        echo "<td $class><textarea name=\"scalescale\" cols=\"50\" rows=\"2\" wrap=\"virtual\">".s($scale->scale)."</textarea>";
-        echo "</td>";
-        echo "</tr>";
-        echo "<tr valign=\"top\">";
-        echo "<td align=\"right\"><b>$strdescription:</b>";
-        helpbutton("text", $strhelptext);
-        echo "</td>";
-        echo "<td><textarea name=\"description\" cols=\"50\" rows=\"8\" wrap=\"virtual\">".s($scale->description)."</textarea>";
-        echo "</td>";
-        echo "</tr>";
-        if ($scale->id) {
-            echo "<tr valign=\"top\">";
-            echo "<td align=\"right\">";
-            echo "</td>";
-            echo "<td>".get_string("usedinnplaces","",$scale_uses);
-            echo "</td>";
-            echo "</tr>";
-        }
-        echo "<tr>";
-        echo "<td colspan=\"2\" align=\"center\">";
-        echo "<input type=\"hidden\" name=\"id\" value=\"$course->id\" />";
-        echo "<input type=\"hidden\" name=\"sesskey\" value=\"$sesskey\" />";
-        echo "<input type=\"hidden\" name=\"courseid\" value=\"$scale->courseid\" />";
-        echo "<input type=\"hidden\" name=\"scaleid\" value=\"$scale->id\" />";
-        echo "<input type=\"hidden\" name=\"action\" value=\"sendform\" />";
-        echo "<input type=\"submit\" name=\"save\" value=\"$strsavechanges\" />";
-        echo "</td></tr></table>";
-        echo "</form>";
-        echo "<br />";
-
-        print_footer($course);
-
-        exit;
     }
 
-    //If action is delete, do it
-    if ($action == "delete" and confirm_sesskey()) {
-        //Check for teacher edit
-           require_capability('moodle/course:managescales', $context);
-        //Check for scale if action = edit
-        if (! $scale = get_record("scale", "id", $scaleid)) {
-            error("Scale ID was incorrect");
-        }
-
-        //Calculate the uses
-        if ($scale->courseid == 0) {
-            $scale_uses = site_scale_used($scale->id,$courses);
-        } else {
-            $scale_uses = course_scale_used($course->id,$scale->id);
-        }
-
-        //Check for scale_uses
-        if (!empty($scale_uses)) {
-            error("Scale is in use and cannot be deleted",$CFG->wwwroot.'/course/scales.php?id='.$course->id);
-        }
-
-        //Check for standard scales
-        if ($scale->courseid == 0 and !has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
-            error("Only administrators can delete this scale",$CFG->wwwroot.'/course/scales.php?id='.$course->id);
-        }
+    if ($scales = get_records("scale", "courseid", "0", "name ASC")) {
+        print_heading($strstandardscales);
+        foreach ($scales as $scale) {
+            $scalemenu = make_menu_from_list($scale->scale);
 
-        if (delete_records("scale", "id", $scaleid)) {
-            $notify = "$scale->name: $strdeleted";
+            print_simple_box_start("center");
+            print_heading($scale->name);
+            echo "<center>";
+            choose_from_menu($scalemenu, "", "", "");
+            echo "</center>";
+            echo text_to_html($scale->description);
+            print_simple_box_end();
+            echo "<hr />";
         }
     }
 
-    //If action is down or up, do it
-    if (($action == "down" || $action == "up") and confirm_sesskey()) {
-        //Check for teacher edit
-           require_capability('moodle/course:managescales', $context);
-        //Check for scale if action = edit
-        if (! $scale = get_record("scale", "id", $scaleid)) {
-            error("Scale ID was incorrect");
-        }
-
-        //Calculate the uses
-        if ($scale->courseid == 0) {
-            $scale_uses = site_scale_used($scale->id,$courses);
-        } else {
-            $scale_uses = course_scale_used($course->id,$scale->id);
-        }
-
-        //Check for scale_uses
-        if (!empty($scale_uses)) {
-            error("Scale is in use and cannot be moved",$CFG->wwwroot.'/course/scales.php?id='.$course->id);
-        }
-
-        if ($action == "down") {
-            $scale->courseid = 0;
-        } else {
-            $scale->courseid = $course->id;
-        }
-
-        if (set_field("scale", "courseid", $scale->courseid, "id", $scale->id)) {
-            $notify = "$scale->name: $strmoved";
-        }
-    }
-
-    if ($list) {       /// Just list the scales (in a helpwindow)
-           require_capability('moodle/course:viewscales', $context);
-        print_header($strscales);
-
-        if (!empty($scaleid)) {
-            if ($scale = get_record("scale", "id", "$scaleid")) {
-                $scalemenu = make_menu_from_list($scale->scale);
-
-                print_simple_box_start("center");
-                print_heading($scale->name);
-                echo "<center>";
-                choose_from_menu($scalemenu, "", "", "");
-                echo "</center>";
-                echo text_to_html($scale->description);
-                print_simple_box_end();
-            }
-            echo "<br />";
-            close_window_button();
-            exit;
-        }
-
-        if ($scales = get_records("scale", "courseid", "$course->id", "name ASC")) {
-            print_heading($strcustomscales);
-
-            if (has_capability('moodle/course:managescales', get_context_instance(CONTEXT_COURSE, $course->id))) {
-                echo "<p align=\"center\">(";
-                print_string("scalestip");
-                echo ")</p>";
-            }
-
-            foreach ($scales as $scale) {
-                $scalemenu = make_menu_from_list($scale->scale);
-
-                print_simple_box_start("center");
-                print_heading($scale->name);
-                echo "<center>";
-                choose_from_menu($scalemenu, "", "", "");
-                echo "</center>";
-                echo text_to_html($scale->description);
-                print_simple_box_end();
-                echo "<hr />";
-            }
-
-        } else {
-            if (has_capability('moodle/course:managescales', $context)) {
-                echo "<p align=\"center\">(";
-                print_string("scalestip");
-                echo ")</p>";
-            }
-        }
-
-        if ($scales = get_records("scale", "courseid", "0", "name ASC")) {
-            print_heading($strstandardscales);
-            foreach ($scales as $scale) {
-                $scalemenu = make_menu_from_list($scale->scale);
-
-                print_simple_box_start("center");
-                print_heading($scale->name);
-                echo "<center>";
-                choose_from_menu($scalemenu, "", "", "");
-                echo "</center>";
-                echo text_to_html($scale->description);
-                print_simple_box_end();
-                echo "<hr />";
-            }
-        }
-
-        close_window_button();
-        exit;
-    }
-
-
-/// The rest is all about editing the scales
-
-    require_capability('moodle/course:managescales', $context);
-
-/// Print out the main page
-
-    print_header("$course->shortname: $strscales", $course->fullname, 
-                 "<a href=\"view.php?id=$course->id\">$course->shortname</a> 
-                  -> $strscales");
-
-    print_heading_with_help($strscales, "scales");
-
-    $options = array();
-    $options['id'] = $course->id;
-    $options['scaleid'] = 0;
-    $options['action'] = 'new';
-
-    print_simple_box_start('center');
-    print_single_button($CFG->wwwroot.'/course/scales.php',$options,$srtcreatenewscale,'POST');
-    print_simple_box_end();
-    echo "<p />";
-
-    if (!empty($notify)) {
-        notify($notify, "green");
-    }
-
-    $scales = array();
-    $customscales = get_records("scale", "courseid", "$course->id", "name ASC");
-    $standardscales = get_records("scale", "courseid", "0", "name ASC");
-
-    if ($customscales) {
-        foreach($customscales as $scale) {
-            $scales[] = $scale;
-        }
-    }
-
-    if ($standardscales) {
-        foreach($standardscales as $scale) {
-            $scales[] = $scale;
-        }
-    }
-
-    if ($scales) {
-        //Calculate the base path
-        $path = "$CFG->wwwroot/course";
-
-        $data = array();
-        $incustom = true;
-        foreach($scales as $scale) {
-            //Check the separator
-            if (empty($scale->courseid) && $incustom) {
-                $incustom = false;
-                $line = "hr";
-                $data[] = $line;
-            }
-            $line = array();
-            $line[] = "<a target=\"scale\" title=\"$scale->name\" href=\"$CFG->wwwroot/course/scales.php?id=$course->id&amp;scaleid=$scale->id&amp;action=details\" "."onclick=\"return openpopup('/course/scales.php?id=$course->id\&amp;scaleid=$scale->id&amp;action=details', 'scale', 'menubar=0,location=0,scrollbars,resizable,width=600,height=450', 0);\">".$scale->name."</a><br /><font size=\"-1\">".str_replace(",",", ",$scale->scale)."</font>";
-            if (!empty($scale->courseid)) {
-                $scales_uses = course_scale_used($course->id,$scale->id);
-            } else {
-                $scales_uses = site_scale_used($scale->id,$courses);
-            }
-            $line[] = $scales_uses;
-            if ($incustom) {
-                $line[] = $strcustomscale;
-            } else {
-                $line[] = $strstandardscale;
-            }
-            $buttons = "";
-            if (empty($scales_uses) && ($incustom || has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM, SITEID)))) {
-                $buttons .= "<a title=\"$stredit\" href=\"$path/scales.php?id=$course->id&amp;scaleid=$scale->id&amp;action=edit\"><img".
-                            " src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
-                if ($incustom && has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
-                    $buttons .= "<a title=\"$strdown\" href=\"$path/scales.php?id=$course->id&amp;scaleid=$scale->id&amp;action=down&amp;sesskey=$USER->sesskey\"><img".
-                                " src=\"$CFG->pixpath/t/down.gif\" class=\"iconsmall\" alt=\"$strdown\" /></a> ";
-                }
-                if (!$incustom && has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
-                    $buttons .= "<a title=\"$strup\" href=\"$path/scales.php?id=$course->id&amp;scaleid=$scale->id&amp;action=up&amp;sesskey=$USER->sesskey\"><img".
-                                " src=\"$CFG->pixpath/t/up.gif\" class=\"iconsmall\" alt=\"$strup\" /></a> ";
-                }
-                $buttons .= "<a title=\"$strdelete\" href=\"$path/scales.php?id=$course->id&amp;scaleid=$scale->id&amp;action=delete&amp;sesskey=$USER->sesskey\"><img".
-                            " src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
-            }
-            $line[] = $buttons;
-
-            $data[] = $line;
-        }
-        $head = $strscale.",".$stractivities.",".$strtype.",".$stroptions;
-        $table->head = explode(",",$head);
-        $size = "50%,20%,20%,10%";
-        $table->size = explode(",",$size);
-        $align = "left,center,center,center";
-        $table->align = explode(",",$align);
-        $wrap = ",nowrap,nowrap,nowrap";
-        $table->wrap = explode(",",$wrap);
-        $table->width = "90%";
-        $table->data = $data;
-        print_table ($table);
-    }
-
-    print_footer($course);
-
+    close_window_button();
+    exit;
 
 ?>
diff --git a/grade/edit/outcome/index.php b/grade/edit/outcome/index.php
new file mode 100644 (file)
index 0000000..30404ce
--- /dev/null
@@ -0,0 +1 @@
+TODO
\ No newline at end of file
diff --git a/grade/edit/scale/edit.php b/grade/edit/scale/edit.php
new file mode 100644 (file)
index 0000000..38b08bc
--- /dev/null
@@ -0,0 +1,84 @@
+<?php  //$Id$
+
+require_once '../../../config.php';
+require_once $CFG->dirroot.'/grade/lib.php';
+require_once $CFG->dirroot.'/grade/report/lib.php';
+require_once 'edit_form.php';
+
+$courseid = required_param('courseid', PARAM_INT);
+$id       = optional_param('id', 0, PARAM_INT);
+
+if (!$course = get_record('course', 'id', $courseid)) {
+    print_error('nocourseid');
+}
+
+require_login($course);
+$context       = get_context_instance(CONTEXT_COURSE, $course->id);
+$systemcontext = get_context_instance(CONTEXT_SYSTEM);
+require_capability('moodle/course:managescales', $context);
+
+// default return url
+$gpr = new grade_plugin_return();
+$returnurl = $gpr->get_return_url('index.php?id='.$course->id);
+
+$mform = new edit_scale_form(null, array('gpr'=>$gpr));
+if ($scale = get_record('scale', 'id', $id)) {
+    $scale->custom = (int)(!empty($scale->courseid));
+    if (!empty($scale->courseid)) {
+        require_capability('moodle/course:managescales', $systemcontext);
+    }
+    $scale->courseid = $courseid;
+    $options = new object();
+    $options->smiley  = false;
+    $options->filter  = false;
+    $options->noclean = false;
+    $scale->description = format_text($scale->description, FORMAT_MOODLE, $options);
+    $mform->set_data($scale);
+
+} else {
+    $mform->set_data(array('courseid'=>$courseid, 'custom'=>1));
+}
+
+if ($mform->is_cancelled()) {
+    redirect($returnurl);
+
+} else if ($data = $mform->get_data(false)) {
+    $scale = new grade_scale(array('id'=>$id));
+    $data->userid = $USER->id;
+    grade_scale::set_properties($scale, $data);
+
+    if (empty($scale->id)) {
+        $scale->courseid = $courseid;
+        if (empty($data->custom) and has_capability('moodle/course:managescales', $systemcontext)) {
+            $scale->courseid = 0;
+        }
+        $scale->insert();
+
+    } else {
+        if (isset($data->custom)) {
+            $scale->courseid = $data->custom ? $courseid : 0;
+        } else {
+            unset($scale->couseid);
+        }
+        $scale->update();
+    }
+
+    redirect($returnurl, 'temp debug delay', 3);
+}
+
+$strgrades       = get_string('grades');
+$strgraderreport = get_string('graderreport', 'grades');
+$strscaleedit    = get_string('scale');
+
+$nav = array(array('name'=>$strgrades,'link'=>$CFG->wwwroot.'/grade/index.php?id='.$courseid, 'type'=>'misc'),
+             array('name'=>$strscaleedit, 'link'=>'', 'type'=>'misc'));
+
+$navigation = build_navigation($nav);
+
+
+print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strscaleedit, $navigation, '', '', true, '', navmenu($course));
+
+$mform->display();
+
+print_footer($course);
+die;
diff --git a/grade/edit/scale/edit_form.php b/grade/edit/scale/edit_form.php
new file mode 100644 (file)
index 0000000..93b78dc
--- /dev/null
@@ -0,0 +1,89 @@
+<?php  //$Id$
+
+require_once $CFG->libdir.'/formslib.php';
+
+class edit_scale_form extends moodleform {
+    function definition() {
+        global $CFG;
+        $mform =& $this->_form;
+
+        // visible elements
+        $mform->addElement('header', 'general', get_string('scale'));
+
+        $mform->addElement('text', 'name', get_string('name'));
+        $mform->addRule('name', get_string('required'), 'required', null, 'client');
+        $mform->setType('name', PARAM_TEXT);
+
+        $mform->addElement('advcheckbox', 'custom', get_string('coursescale', 'grades'));
+
+        $mform->addElement('static', 'activities', get_string('activities'));
+
+        $mform->addElement('textarea', 'scale', get_string('scale'), array('cols'=>50, 'rows'=>2));
+        $mform->addRule('scale', get_string('required'), 'required', null, 'client');
+        $mform->setType('scale', PARAM_TEXT);
+
+        $mform->addElement('htmleditor', 'description', get_string('description'), array('cols'=>80, 'rows'=>20));
+
+
+        // hidden params
+        $mform->addElement('hidden', 'id', 0);
+        $mform->setType('id', PARAM_INT);
+
+        $mform->addElement('hidden', 'courseid', 0);
+        $mform->setType('courseid', PARAM_INT);
+
+/// add return tracking info
+        $gpr = $this->_customdata['gpr'];
+        $gpr->add_mform_elements($mform);
+
+//-------------------------------------------------------------------------------
+        // buttons
+        $this->add_action_buttons();
+    }
+
+
+/// tweak the form - depending on existing data
+    function definition_after_data() {
+        global $CFG;
+
+        $mform =& $this->_form;
+
+        if ($id = $mform->getElementValue('id')) {
+            $scale = grade_scale::fetch(array('id'=>$id));
+            if ($count = $scale->get_uses_count()) {
+                if (empty($scale->courseid)) {
+                    $mform->hardFreeze('custom');
+                }
+                $mform->hardFreeze('scale');
+            }
+            $activities_el =& $mform->getElement('activities');
+            $activities_el->setValue(get_string('usedinnplaces', '', $count));
+
+        } else {
+            $mform->removeElement('activities');
+            if (!has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
+                $mform->hardFreeze('custom');
+            }
+        }
+    }
+
+/// perform extra validation before submission
+    function validation($data){
+        $errors= array();
+
+        $options = explode(',', $data['scale']);
+        if (count($options) < 2) {
+            $errors['scale'] = get_string('error');
+        }
+
+        if (0 == count($errors)){
+            return true;
+        } else {
+            return $errors;
+        }
+    }
+
+
+}
+
+?>
diff --git a/grade/edit/scale/index.php b/grade/edit/scale/index.php
new file mode 100644 (file)
index 0000000..bf2e455
--- /dev/null
@@ -0,0 +1,136 @@
+<?php // $Id$
+      // Allows a creator to edit custom scales, and also display help about scales
+
+require_once '../../../config.php';
+require_once $CFG->dirroot.'/grade/lib.php';
+require_once $CFG->libdir.'/gradelib.php';
+
+$courseid = required_param('id', PARAM_INT);
+$action   = optional_param('action', '', PARAM_ALPHA);
+
+/// Make sure they can even access this course
+if (!$course = get_record('course', 'id', $courseid)) {
+    print_error('nocourseid');
+}
+require_login($course);
+$context = get_context_instance(CONTEXT_COURSE, $course->id);
+require_capability('moodle/course:managescales', $context);
+
+/// return tracking object
+$gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'scale', 'courseid'=>$courseid));
+
+
+$strgrades = get_string('grades');
+$pagename  = get_string('scales');
+
+$navlinks = array(array('name'=>$strgrades, 'link'=>$CFG->wwwroot.'/grade/index.php?id='.$courseid, 'type'=>'misc'),
+                  array('name'=>$pagename, 'link'=>'', 'type'=>'misc'));
+$navigation = build_navigation($navlinks);
+
+$strscale          = get_string('scale');
+$strstandardscale  = get_string('scalesstandard');
+$strcustomscales   = get_string('coursescales', 'grades');
+$strname           = get_string('name');
+$strdelete         = get_string('delete');
+$stredit           = get_string('edit');
+$srtcreatenewscale = get_string('scalescustomcreate');
+$stractivities     = get_string('activities');
+$stroptions        = get_string('action');
+
+switch ($action) {
+    case 'delete':
+        if (!confirm_sesskey()) {
+            break;
+        }
+        $scaleid = required_param('scaleid', PARAM_INT);
+        if (!$scale = grade_scale::fetch(array('id'=>$scaleid))) {
+            break;
+        }
+
+        if (empty($scale->courseid)) {
+            require_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM));
+        }
+
+        if (!$scale->can_delete()) {
+            break;
+        }
+
+        //TODO: add confirmation
+        $scale->delete();
+        break;
+}
+
+/// Print header
+print_header_simple($strgrades.': '.$pagename, ': '.$strgrades, $navigation,
+                        '', '', true, '', navmenu($course));
+
+/// Print the plugin selector at the top
+print_grade_plugin_selector($courseid, 'edit', 'scale');
+
+
+print_heading($strstandardscale);
+if ($scales = grade_scale::fetch_all(array('courseid'=>0))) {
+    $data = array();
+    foreach($scales as $scale) {
+        $line = array();
+        $line[] = format_string($scale->name).'<div class="scale_options">'.str_replace(",",", ",$scale->scale).'</div>';
+
+        $scales_uses = $scale->get_uses_count();
+        $line[] = $scales_uses;
+
+        $buttons = "";
+        if (has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
+            $buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$course->id&amp;id=$scale->id\"><img".
+                        " src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
+        }
+        if (empty($scales_uses) and has_capability('moodle/course:managescales', get_context_instance(CONTEXT_SYSTEM))) {
+            $buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$course->id&amp;scaleid=$scale->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->head  = array($strscale, $stractivities, $stroptions);
+    $table->size  = array('70%', '20%', '10%');
+    $table->align = array('left', 'center', 'center');
+    $table->width = '90%';
+    $table->data  = $data;
+    print_table($table);
+}
+
+print_heading($strcustomscales);
+if ($scales = grade_scale::fetch_all(array('courseid'=>$courseid))) {
+    $data = array();
+    foreach($scales as $scale) {
+        $line = array();
+        $line[] = format_string($scale->name).'<div class="scale_options">'.str_replace(",",", ",$scale->scale).'</div>';
+
+        $scales_uses = $scale->get_uses_count();
+        $line[] = $scales_uses;
+
+        $buttons = "";
+        $buttons .= "<a title=\"$stredit\" href=\"edit.php?courseid=$course->id&amp;id=$scale->id\"><img".
+                    " src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
+        if (empty($scales_uses)) {
+            $buttons .= "<a title=\"$strdelete\" href=\"index.php?id=$course->id&amp;scaleid=$scale->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->head  = array($strscale, $stractivities, $stroptions);
+    $table->size  = array('70%', '20%', '10%');
+    $table->align = array('left', 'center', 'center');
+    $table->width = '90%';
+    $table->data  = $data;
+    print_table($table);
+}
+
+echo '<div class="buttons">';
+print_single_button('edit.php', array('courseid'=>$courseid), $srtcreatenewscale);
+echo '</div>';
+
+print_footer($course);
+
+
+?>
similarity index 96%
rename from grade/edit/action.php
rename to grade/edit/tree/action.php
index f6b4eb2ec4628a67b63f8f146f4d55f4fcaf6090..90a870004ec89180f6ea23a7bed97b70a2cde60e 100644 (file)
@@ -1,6 +1,6 @@
 <?php  // $Id$
 
-require_once '../../config.php';
+require_once '../../../config.php';
 require_once $CFG->dirroot.'/grade/lib.php';
 
 $courseid = required_param('id', PARAM_INT);
@@ -16,7 +16,7 @@ $context = get_context_instance(CONTEXT_COURSE, $course->id);
 
 // default return url
 $gpr = new grade_plugin_return();
-$returnurl = $gpr->get_return_url($CFG->wwwroot.'/grade/edit/tree.php?id='.$course->id);
+$returnurl = $gpr->get_return_url($CFG->wwwroot.'/grade/edit/tree/index.php?id='.$course->id);
 
 // get the grading tree object
 $gtree = new grade_tree($courseid, false, false);
similarity index 98%
rename from grade/edit/calculation.php
rename to grade/edit/tree/calculation.php
index 727cc8e121c295734f72771d2185ce7adb120eb9..ccc66660f59345b7b5058ea92c6dc4c9bbee69cf 100644 (file)
@@ -1,6 +1,6 @@
 <?php  //$Id$
 
-require_once '../../config.php';
+require_once '../../../config.php';
 require_once $CFG->dirroot.'/grade/lib.php';
 require_once 'calculation_form.php';
 
similarity index 95%
rename from grade/edit/category.php
rename to grade/edit/tree/category.php
index 1a576da802afc9d92b074727df1c748e536f2f11..f110f8590628e1db4aca2926661ce47f4e2ff6b8 100644 (file)
@@ -1,6 +1,6 @@
 <?php  //$Id$
 
-require_once '../../config.php';
+require_once '../../../config.php';
 require_once $CFG->dirroot.'/grade/lib.php';
 require_once $CFG->dirroot.'/grade/report/lib.php';
 require_once 'category_form.php';
@@ -18,7 +18,7 @@ require_capability('moodle/grade:manage', $context);
 
 // default return url
 $gpr = new grade_plugin_return();
-$returnurl = $gpr->get_return_url('tree.php?id='.$course->id);
+$returnurl = $gpr->get_return_url('index.php?id='.$course->id);
 
 
 $mform = new edit_category_form(null, array('gpr'=>$gpr));
similarity index 99%
rename from grade/edit/grade.php
rename to grade/edit/tree/grade.php
index a176e9fda86d64947fced53f29df64fc2a4951b7..f1e1cfe3dcb10b46c09918654fa825ba1d76ce9b 100644 (file)
@@ -1,6 +1,6 @@
 <?php  //$Id$
 
-require_once '../../config.php';
+require_once '../../../config.php';
 require_once $CFG->dirroot.'/grade/lib.php';
 require_once 'grade_form.php';
 
similarity index 98%
rename from grade/edit/tree.php
rename to grade/edit/tree/index.php
index 68eaaae89a9c33519cf4a468bd3e9ae55c7d5ad6..9f07fe4f1d6e049e94c1188ccf765cfc9d97f123 100644 (file)
@@ -23,7 +23,7 @@
 //                                                                       //
 ///////////////////////////////////////////////////////////////////////////
 
-require_once '../../config.php';
+require_once '../../../config.php';
 require_once $CFG->dirroot.'/grade/lib.php';
 
 $courseid = required_param('id', PARAM_INT);
@@ -42,7 +42,7 @@ $context = get_context_instance(CONTEXT_COURSE, $course->id);
 require_capability('moodle/grade:manage', $context);
 
 /// return tracking object
-$gpr = new grade_plugin_return(array('type'=>'edit', 'courseid'=>$courseid));
+$gpr = new grade_plugin_return(array('type'=>'edit', 'plugin'=>'tree', 'courseid'=>$courseid));
 $returnurl = $gpr->get_return_url(null);
 
 //first make sure we have proper final grades - we need it for locking changes
similarity index 92%
rename from grade/edit/item.php
rename to grade/edit/tree/item.php
index 4865d23077696ea93836dbeba535c0e4fd93e443..0b74fbafb9f297dd4ddd0908817a6ed6816a3e68 100644 (file)
@@ -1,6 +1,6 @@
 <?php  //$Id$
 
-require_once '../../config.php';
+require_once '../../../config.php';
 require_once $CFG->dirroot.'/grade/lib.php';
 require_once $CFG->dirroot.'/grade/report/lib.php';
 require_once 'item_form.php';
@@ -18,7 +18,7 @@ require_capability('moodle/grade:manage', $context);
 
 // default return url
 $gpr = new grade_plugin_return();
-$returnurl = $gpr->get_return_url('tree.php?id='.$course->id);
+$returnurl = $gpr->get_return_url('index.php?id='.$course->id);
 
 $mform = new edit_item_form(null, array('gpr'=>$gpr));
 
@@ -29,7 +29,7 @@ if ($mform->is_cancelled()) {
 if ($item = get_record('grade_items', 'id', $id, 'courseid', $course->id)) {
     // redirect if outcomeid present
     if (!empty($item->outcomeid)) {
-        $url = $CFG->wwwroot.'/grade/edit/outcome.php?id='.$id.'&amp;courseid='.$courseid;
+        $url = $CFG->wwwroot.'/grade/edit/tree/outcome.php?id='.$id.'&amp;courseid='.$courseid;
         redirect($gpr->add_url_params($url));
     }
 
@@ -49,6 +49,8 @@ if ($data = $mform->get_data()) {
     $grade_item = new grade_item(array('id'=>$id, 'courseid'=>$courseid));
     grade_item::set_properties($grade_item, $data);
 
+    $grade_item->outcomeid = null;
+
     if (empty($grade_item->id)) {
         $grade_item->itemtype = 'manual'; // all new items to be manual only
         $grade_item->insert();
similarity index 95%
rename from grade/edit/outcomeitem.php
rename to grade/edit/tree/outcomeitem.php
index c5109d3f83d4532beb63526fe91b98c52d7384d0..4cc5b7e0fd08b82aa563639287db91fb920bde34 100644 (file)
@@ -1,6 +1,6 @@
 <?php  //$Id$
 
-require_once '../../config.php';
+require_once '../../../config.php';
 require_once $CFG->dirroot.'/grade/lib.php';
 require_once $CFG->dirroot.'/grade/report/lib.php';
 require_once 'outcomeitem_form.php';
@@ -18,7 +18,7 @@ require_capability('moodle/grade:manage', $context);
 
 // default return url
 $gpr = new grade_plugin_return();
-$returnurl = $gpr->get_return_url('tree.php?id='.$course->id);
+$returnurl = $gpr->get_return_url('index.php?id='.$course->id);
 
 $mform = new edit_outcomeitem_form(null, array('gpr'=>$gpr));
 
@@ -29,7 +29,7 @@ if ($mform->is_cancelled()) {
 if ($item = get_record('grade_items', 'id', $id, 'courseid', $course->id)) {
     // redirect if outcomeid present
     if (empty($item->outcomeid)) {
-        $url = $CFG->wwwroot.'/grade/edit/outcome.php?id='.$id.'&amp;courseid='.$courseid;
+        $url = $CFG->wwwroot.'/grade/edit/tree/outcome.php?id='.$id.'&amp;courseid='.$courseid;
         redirect($gpr->add_url_params($url));
     }
 
index 7e4f66f11f69f0840d0ef8d94eec74483c641f44..5ca2cfb583db0a96d8f134bb87b999044c36c930 100644 (file)
@@ -93,13 +93,33 @@ function print_grade_plugin_selector($courseid, $active_type, $active_plugin, $r
     }
 
 /// editing scripts - not real plugins
-    if (has_capability('moodle/grade:manage', $context)) {
+    if (has_capability('moodle/grade:manage', $context)
+      or has_capability('moodle/course:managescales', $context)) {
         $menu['edit']='--'.get_string('edit');
-        $url = 'edit/tree.php?id='.$courseid;
-        if ($active_type == 'edit' and $active_plugin == 'tree' ) {
-            $active = $url;
+
+        if (has_capability('moodle/grade:manage', $context)) {
+            $url = 'edit/tree/index.php?id='.$courseid;
+            if ($active_type == 'edit' and $active_plugin == 'tree' ) {
+                $active = $url;
+            }
+            $menu[$url] = get_string('edittree', 'grades');
+        }
+
+        if (has_capability('moodle/course:managescales', $context)) {
+            $url = 'edit/scale/index.php?id='.$courseid;
+            if ($active_type == 'edit' and $active_plugin == 'scale' ) {
+                $active = $url;
+            }
+            $menu[$url] = get_string('scales');
+        }
+
+        if (has_capability('moodle/grade:manage', $context)) { // TODO: add outcome cap
+            $url = 'edit/outcome/index.php?id='.$courseid;
+            if ($active_type == 'edit' and $active_plugin == 'outcome' ) {
+                $active = $url;
+            }
+            $menu[$url] = get_string('outcomes', 'grades');
         }
-        $menu[$url] = get_string('edittree', 'grades');
     }
 
 /// finally print/return the popup form
@@ -175,10 +195,6 @@ class grade_plugin_return {
     function get_return_url($default, $extras=null) {
         global $CFG;
 
-        if ($this->type == 'edit') {
-            return $CFG->wwwroot.'/grade/edit/tree.php?id='.$this->courseid;
-        }
-
         if (empty($this->type) or empty($this->plugin)) {
             return $default;
         }
@@ -581,21 +597,21 @@ class grade_tree {
             case 'categoryitem':
             case 'courseitem':
                 if (empty($object->outcomeid)) {
-                    $url = $CFG->wwwroot.'/grade/edit/item.php?courseid='.$this->courseid.'&amp;id='.$object->id;
+                    $url = $CFG->wwwroot.'/grade/edit/tree/item.php?courseid='.$this->courseid.'&amp;id='.$object->id;
                 } else {
-                    $url = $CFG->wwwroot.'/grade/edit/outcomeitem.php?courseid='.$this->courseid.'&amp;id='.$object->id;
+                    $url = $CFG->wwwroot.'/grade/edit/tree/outcomeitem.php?courseid='.$this->courseid.'&amp;id='.$object->id;
                 }
                 $url = $gpr->add_url_params($url);
                 break;
 
             case 'category':
-                $url = $CFG->wwwroot.'/grade/edit/category.php?courseid='.$this->courseid.'&amp;id='.$object->id;
+                $url = $CFG->wwwroot.'/grade/edit/tree/category.php?courseid='.$this->courseid.'&amp;id='.$object->id;
                 $url = $gpr->add_url_params($url);
                 break;
 
             case 'grade':
                 //TODO: improve dealing with new grades
-                $url = $CFG->wwwroot.'/grade/edit/grade.php?courseid='.$this->courseid.'&amp;id='.$object->id;
+                $url = $CFG->wwwroot.'/grade/edit/tree/grade.php?courseid='.$this->courseid.'&amp;id='.$object->id;
                 $url = $gpr->add_url_params($url);
                 if (!empty($object->feedback)) {
                     $feedback = format_text($object->feedback, $object->feedbackformat);
@@ -636,12 +652,12 @@ class grade_tree {
         }
 
         if ($element['object']->is_hidden()) {
-            $url     = $CFG->wwwroot.'/grade/edit/action.php?id='.$this->courseid.'&amp;action=show&amp;sesskey='.sesskey().'&amp;eid='.$element['eid'];
+            $url     = $CFG->wwwroot.'/grade/edit/tree/action.php?id='.$this->courseid.'&amp;action=show&amp;sesskey='.sesskey().'&amp;eid='.$element['eid'];
             $url     = $gpr->add_url_params($url);
             $action  = '<a href="'.$url.'"><img src="'.$CFG->pixpath.'/t/show.gif" class="iconsmall" alt="'.$strshow.'" title="'.$strshow.'"/></a>';
 
         } else {
-            $url     = $CFG->wwwroot.'/grade/edit/action.php?id='.$this->courseid.'&amp;action=hide&amp;sesskey='.sesskey().'&amp;eid='.$element['eid'];
+            $url     = $CFG->wwwroot.'/grade/edit/tree/action.php?id='.$this->courseid.'&amp;action=hide&amp;sesskey='.sesskey().'&amp;eid='.$element['eid'];
             $url     = $gpr->add_url_params($url);
             $action  = '<a href="'.$url.'"><img src="'.$CFG->pixpath.'/t/hide.gif" class="iconsmall" alt="'.$strhide.'" title="'.$strhide.'"/></a>';
         }
@@ -667,7 +683,7 @@ class grade_tree {
             if (!has_capability('moodle/grade:manage', $this->context) and !has_capability('moodle/grade:unlock', $this->context)) {
                 return '';
             }
-            $url     = $CFG->wwwroot.'/grade/edit/action.php?id='.$this->courseid.'&amp;action=unlock&amp;sesskey='.sesskey().'&amp;eid='.$element['eid'];
+            $url     = $CFG->wwwroot.'/grade/edit/tree/action.php?id='.$this->courseid.'&amp;action=unlock&amp;sesskey='.sesskey().'&amp;eid='.$element['eid'];
             $url     = $gpr->add_url_params($url);
             $action  = '<a href="'.$url.'"><img src="'.$CFG->pixpath.'/t/unlock.gif" class="iconsmall" alt="'.$strunlock.'" title="'.$strunlock.'"/></a>';
 
@@ -675,7 +691,7 @@ class grade_tree {
             if (!has_capability('moodle/grade:manage', $this->context) and !has_capability('moodle/grade:lock', $this->context)) {
                 return '';
             }
-            $url     = $CFG->wwwroot.'/grade/edit/action.php?id='.$this->courseid.'&amp;action=lock&amp;sesskey='.sesskey().'&amp;eid='.$element['eid'];
+            $url     = $CFG->wwwroot.'/grade/edit/tree/action.php?id='.$this->courseid.'&amp;action=lock&amp;sesskey='.sesskey().'&amp;eid='.$element['eid'];
             $url     = $gpr->add_url_params($url);
             $action  = '<a href="'.$url.'"><img src="'.$CFG->pixpath.'/t/lock.gif" class="iconsmall" alt="'.$strlock.'" title="'.$strlock.'"/></a>';
         }
@@ -703,7 +719,7 @@ class grade_tree {
 
             // show calculation icon only when calculation possible
             if (!$object->is_normal_item() and ($object->gradetype == GRADE_TYPE_SCALE or $object->gradetype == GRADE_TYPE_VALUE)) {
-                $url = $CFG->wwwroot.'/grade/edit/calculation.php?courseid='.$this->courseid.'&amp;id='.$object->id;
+                $url = $CFG->wwwroot.'/grade/edit/tree/calculation.php?courseid='.$this->courseid.'&amp;id='.$object->id;
                 $url = $gpr->add_url_params($url);
                 $calculation_icon = '<a href="'. $url.'"><img src="'.$CFG->pixpath.'/t/calc.gif" class="iconsmall" alt="'
                                        . $streditcalculation.'" title="'.$streditcalculation.'" /></a>'. "\n";
index a755444e228c8fd6da702ddfa2d190fda1250773..2df4002f6c5f97d3f29885122c0c63ecc655486b 100644 (file)
@@ -3,6 +3,6 @@
 $string['addoutcome'] = 'Add an outcome';
 $string['courseoutcomes'] = 'Course outcomes';
 $string['coursespecoutcome'] = 'Course outcomes';
-$string['modulename'] = 'Outcomes';
+$string['modulename'] = 'Outcomes report';
 $string['usedgradeitem'] = 'Number of grade items';
 ?>
index d4c19ce46b539489953c221bc510e74da84f00cc..a0bc9a7601dab575623ba89d9eaaf86f3bbf60a7 100644 (file)
@@ -91,7 +91,7 @@ $string['editcalculation'] = 'Edit Calculation';
 $string['editfeedback'] = 'Edit Feedback';
 $string['editgrade'] = 'Edit Grade';
 $string['editoutcomes'] = 'Edit outcomes';
-$string['edittree'] = 'Categories';
+$string['edittree'] = 'Categories and items';
 $string['enableajax'] = 'Enable AJAX';
 $string['enableoutcomes'] = 'Enable outcomes';
 $string['encoding'] = 'Encoding';
index 51ee8ca760ad71b7b1c43d2ea01ad4667f193189..3141fa5d592078f58448204ef1c77697a4d28d22 100644 (file)
@@ -169,5 +169,48 @@ class grade_scale extends grade_object {
 
         return $scales[$grade-1];
     }
+
+    /**
+     * Determines if scale can be deleted.
+     * @return boolean
+     */
+    function can_delete() {
+        $count = $this->get_uses_count();
+        return empty($count);
+    }
+
+    /**
+     * Returns the number of places where scale is used - activities, grade items, outcomes, etc.
+     * @return int
+     */
+    function get_uses_count() {
+        global $CFG;
+
+        $count = 0;
+        if (!empty($this->courseid)) {
+            if ($scales_uses = course_scale_used($this->courseid,$this->id)) {
+                $count += count($scales_uses);
+            }
+        } else {
+            $courses = array();
+            if ($scales_uses = site_scale_used($this->id,$courses)) {
+                $count += count($scales_uses);
+            }
+        }
+
+        // count grade items
+        $sql = "SELECT COUNT(id) FROM {$CFG->prefix}grade_items WHERE scaleid = {$this->id} AND outcomeid IS NULL";
+        if ($scales_uses = count_records_sql($sql)) {
+            $count += $scales_uses;
+        }
+
+        // count outcomes
+        $sql = "SELECT COUNT(id) FROM {$CFG->prefix}grade_outcomes WHERE scaleid = {$this->id}";
+        if ($scales_uses = count_records_sql($sql)) {
+            $count += $scales_uses;
+        }
+
+        return $count;
+    }
 }
 ?>
index f38f58e64b8935a1fcc6da50dc95906e0aca356b..8904b69b47ae5caac024cdcf21f577abb77f1265 100644 (file)
@@ -481,6 +481,10 @@ body#grade-index .grades .header {
   font-size: 0.7em;
 }
 
+.grade-edit-scale .scale_options {
+  font-size: 0.7em;
+}
+
 
 /***
  *** Login
index 1f2c3022ebec1bd8cee196f110a1e3b3167a07cd..6e26731f52221655a577d9427dc2291ded7eb70e 100644 (file)
@@ -2145,9 +2145,22 @@ body#doc-contents ul {
   display: inline;
   margin-right: 10px;
 }
+
+/* scales edit */
+
+.grade-edit-scale .buttons {
+  margin: 20px;
+  text-align:center;
+}
+
+.grade-edit-scale .buttons .singlebutton {
+  display: inline;
+  padding: 5px;
+}
+
 /* gradebook edit tree */
 
-#grade-edit-edit_tree .gradetreebox {
+.grade-edit-tree .gradetreebox {
   width:70%;
   margin-left:auto;
   margin-right:auto;
@@ -2155,40 +2168,39 @@ body#doc-contents ul {
   padding-bottom:15px;
 }
 
-#grade-edit-tree .buttons {
+.grade-edit-tree .buttons {
   margin: 20px;
   text-align:center;
 }
 
-#grade-edit-tree .buttons .singlebutton {
+.grade-edit-tree .buttons .singlebutton {
   display: inline;
   padding: 5px;
 }
 
-
-#grade-edit-tree .movetarget {
+.grade-edit-tree .movetarget {
   position: relative;
   width: 80px;
   height: 16px;
 }
 
-#grade-edit-tree ul#grade_tree {
+.grade-edit-tree ul#grade_tree {
   width: auto;
 }
 
-#grade-edit-tree ul#grade_tree li {
+.grade-edit-tree ul#grade_tree li {
   list-style: none;
 }
 
-#grade-edit-tree ul#grade_tree li.category {
+.grade-edit-tree ul#grade_tree li.category {
   margin-bottom: 6px;
 }
 
-#grade-edit-tree .moving {
+.grade-edit-tree .moving {
   background-color: #E8EEF7;
 }
 
-#grade-edit-tree .iconsmall {
+.grade-edit-tree .iconsmall {
   margin-left: 4px;
 }