mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
MDL-10544 basic UI for outcome item adding/editing implemented - todo: calculation support, lang strings, bugfixing...
whitespace cleanup
This commit is contained in:
parent
4faf5f99be
commit
f10fac9669
14 changed files with 298 additions and 50 deletions
|
@ -12,9 +12,8 @@ if (!$course = get_record('course', 'id', $courseid)) {
|
|||
}
|
||||
|
||||
require_login($course);
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
//require_capability() here!!
|
||||
require_capability('moodle/grade:manage', $context);
|
||||
|
||||
// default return url
|
||||
$gpr = new grade_plugin_return();
|
||||
|
|
|
@ -13,9 +13,8 @@ if (!$course = get_record('course', 'id', $courseid)) {
|
|||
}
|
||||
|
||||
require_login($course);
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
//require_capability() here!!
|
||||
require_capability('moodle/grade:manage', $context);
|
||||
|
||||
// default return url
|
||||
$gpr = new grade_plugin_return();
|
||||
|
|
|
@ -17,7 +17,7 @@ if (!$course = get_record('course', 'id', $courseid)) {
|
|||
// TODO: add proper check that grade is editable
|
||||
require_login($course);
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
require_capability('gradereport/grader:manage', $context);
|
||||
require_capability('moodle/grade:override', $context);
|
||||
|
||||
// default return url
|
||||
$gpr = new grade_plugin_return();
|
||||
|
|
|
@ -13,9 +13,8 @@ if (!$course = get_record('course', 'id', $courseid)) {
|
|||
}
|
||||
|
||||
require_login($course);
|
||||
|
||||
$context = get_context_instance(CONTEXT_COURSE, $course->id);
|
||||
//require_capability() here!!
|
||||
require_capability('moodle/grade:manage', $context);
|
||||
|
||||
// default return url
|
||||
$gpr = new grade_plugin_return();
|
||||
|
@ -28,6 +27,12 @@ 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.'&courseid='.$courseid;
|
||||
redirect($gpr->add_url_params($url));
|
||||
}
|
||||
|
||||
// Get Item preferences
|
||||
$item->pref_gradedisplaytype = grade_report::get_pref('gradedisplaytype', $id);
|
||||
$item->pref_decimalpoints = grade_report::get_pref('decimalpoints', $id);
|
||||
|
@ -41,7 +46,7 @@ if ($data = $mform->get_data()) {
|
|||
$data->calculation = grade_item::normalize_formula($data->calculation, $course->id);
|
||||
}
|
||||
|
||||
$grade_item = new grade_item(array('id'=>$id, 'courseid'=>$course->id));
|
||||
$grade_item = new grade_item(array('id'=>$id, 'courseid'=>$courseid));
|
||||
grade_item::set_properties($grade_item, $data);
|
||||
|
||||
if (empty($grade_item->id)) {
|
||||
|
|
|
@ -15,17 +15,6 @@ class edit_item_form extends moodleform {
|
|||
$mform->addElement('text', 'iteminfo', get_string('iteminfo', 'grades'));
|
||||
$mform->addElement('text', 'idnumber', get_string('idnumber'));
|
||||
|
||||
// allow setting of outcomes on module items too
|
||||
$options = array(0=>get_string('usenooutcome', 'grades'));
|
||||
|
||||
if ($outcomes = grade_outcome::fetch_all(array('courseid'=>$COURSE->id), true)) {
|
||||
foreach ($outcomes as $outcome) {
|
||||
$options[$outcome->id] = $outcome->get_name();
|
||||
}
|
||||
}
|
||||
|
||||
$mform->addElement('select', 'outcomeid', get_string('outcome', 'grades'), $options);
|
||||
|
||||
$options = array(GRADE_TYPE_NONE=>get_string('typenone', 'grades'),
|
||||
GRADE_TYPE_VALUE=>get_string('typevalue', 'grades'),
|
||||
GRADE_TYPE_SCALE=>get_string('typescale', 'grades'),
|
||||
|
|
130
grade/edit/outcomeitem.php
Normal file
130
grade/edit/outcomeitem.php
Normal file
|
@ -0,0 +1,130 @@
|
|||
<?php //$Id$
|
||||
|
||||
require_once '../../config.php';
|
||||
require_once $CFG->dirroot.'/grade/lib.php';
|
||||
require_once $CFG->dirroot.'/grade/report/lib.php';
|
||||
require_once 'outcomeitem_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);
|
||||
require_capability('moodle/grade:manage', $context);
|
||||
|
||||
// default return url
|
||||
$gpr = new grade_plugin_return();
|
||||
$returnurl = $gpr->get_return_url('tree.php?id='.$course->id);
|
||||
|
||||
$mform = new edit_outcomeitem_form(null, array('gpr'=>$gpr));
|
||||
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect($returnurl);
|
||||
}
|
||||
|
||||
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.'&courseid='.$courseid;
|
||||
redirect($gpr->add_url_params($url));
|
||||
}
|
||||
|
||||
// $item->calculation = grade_item::denormalize_formula($item->calculation, $course->id);
|
||||
|
||||
if ($item->itemtype == 'mod') {
|
||||
$cm = get_coursemodule_from_instance($item->itemmodule, $item->iteminstance, $item->courseid);
|
||||
$item->cmid = $cm->id;
|
||||
} else {
|
||||
$item->cmid = 0;
|
||||
}
|
||||
|
||||
$mform->set_data($item);
|
||||
}
|
||||
|
||||
if ($data = $mform->get_data(false)) {
|
||||
if (array_key_exists('calculation', $data)) {
|
||||
// $data->calculation = grade_item::normalize_formula($data->calculation, $course->id);
|
||||
}
|
||||
|
||||
$grade_item = new grade_item(array('id'=>$id, 'courseid'=>$courseid));
|
||||
grade_item::set_properties($grade_item, $data);
|
||||
|
||||
// fix activity links
|
||||
if (empty($data->cmid)) {
|
||||
// manual item
|
||||
$grade_item->itemtype = 'manual';
|
||||
$grade_item->itemmodule = null;
|
||||
$grade_item->iteminstance = null;
|
||||
$grade_item->itemnumber = 0;
|
||||
|
||||
} else {
|
||||
$module = get_record_sql("SELECT cm.*, m.name as modname
|
||||
FROM {$CFG->prefix}modules m, {$CFG->prefix}course_modules cm
|
||||
WHERE cm.id = {$data->cmid} AND cm.module = m.id ");
|
||||
$grade_item->itemtype = 'mod';
|
||||
$grade_item->itemmodule = $module->modname;
|
||||
$grade_item->iteminstance = $module->instance;
|
||||
|
||||
if ($items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$grade_item->itemmodule,
|
||||
'iteminstance'=>$grade_item->iteminstance, 'courseid'=>$COURSE->id))) {
|
||||
if (!empty($grade_item->id) and in_array($grade_item, $items)) {
|
||||
//no change needed
|
||||
} else {
|
||||
$max = 999;
|
||||
foreach($items as $item) {
|
||||
if (empty($item->outcomeid)) {
|
||||
continue;
|
||||
}
|
||||
if ($item->itemnumber > $max) {
|
||||
$max = $item->itemnumber;
|
||||
}
|
||||
}
|
||||
$grade_item->itemnumber = $max + 1;
|
||||
}
|
||||
} else {
|
||||
$grade_item->itemnumber = 1000;
|
||||
}
|
||||
}
|
||||
|
||||
// fix scale used
|
||||
$outcome = grade_outcome::fetch(array('id'=>$data->outcomeid));
|
||||
$grade_item->gradetype = GRADE_TYPE_SCALE;
|
||||
$grade_item->scaleid = $outcome->scaleid; //TODO: we might recalculate existing outcome grades when changing scale
|
||||
|
||||
if (empty($grade_item->id)) {
|
||||
$grade_item->insert();
|
||||
// move next to activity if adding linked outcome
|
||||
if ($grade_item->itemtype == 'mod') {
|
||||
if ($item = grade_item::fetch(array('itemtype'=>'mod', 'itemmodule'=>$grade_item->itemmodule,
|
||||
'iteminstance'=>$grade_item->iteminstance, 'itemnumber'=>0, 'courseid'=>$COURSE->id))) {
|
||||
$grade_item->set_parent($item->categoryid);
|
||||
$grade_item->move_after_sortorder($item->sortorder);
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$grade_item->update();
|
||||
}
|
||||
|
||||
redirect($returnurl, 'temporary debug delay', 5);
|
||||
}
|
||||
|
||||
$strgrades = get_string('grades');
|
||||
$strgraderreport = get_string('graderreport', 'grades');
|
||||
$stroutcomesedit = get_string('outcomeitemsedit', 'grades');
|
||||
|
||||
$nav = array(array('name'=>$strgrades,'link'=>$CFG->wwwroot.'/grade/index.php?id='.$courseid, 'type'=>'misc'),
|
||||
array('name'=>$stroutcomesedit, 'link'=>'', 'type'=>'misc'));
|
||||
|
||||
$navigation = build_navigation($nav);
|
||||
|
||||
|
||||
print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $stroutcomesedit, $navigation, '', '', true, '', navmenu($course));
|
||||
|
||||
$mform->display();
|
||||
|
||||
print_footer($course);
|
115
grade/edit/outcomeitem_form.php
Normal file
115
grade/edit/outcomeitem_form.php
Normal file
|
@ -0,0 +1,115 @@
|
|||
<?php //$Id$
|
||||
|
||||
require_once $CFG->libdir.'/formslib.php';
|
||||
|
||||
class edit_outcomeitem_form extends moodleform {
|
||||
function definition() {
|
||||
global $COURSE, $CFG;
|
||||
|
||||
$mform =& $this->_form;
|
||||
|
||||
/// visible elements
|
||||
$mform->addElement('header', 'general', get_string('gradeoutcomeitem', 'grades'));
|
||||
|
||||
$mform->addElement('text', 'itemname', get_string('itemname', 'grades'));
|
||||
$mform->addRule('itemname', get_string('required'), 'required', null, 'client');
|
||||
|
||||
$mform->addElement('text', 'iteminfo', get_string('iteminfo', 'grades'));
|
||||
|
||||
$mform->addElement('text', 'idnumber', get_string('idnumber'));
|
||||
|
||||
// allow setting of outcomes on module items too
|
||||
$options = array();
|
||||
if ($outcomes = grade_outcome::fetch_all(array('courseid'=>$COURSE->id), true)) {
|
||||
foreach ($outcomes as $outcome) {
|
||||
$options[$outcome->id] = $outcome->get_name();
|
||||
}
|
||||
}
|
||||
$mform->addElement('select', 'outcomeid', get_string('outcome', 'grades'), $options);
|
||||
|
||||
$options = array(0=>get_string('none'));
|
||||
if ($coursemods = get_course_mods($COURSE->id)) {
|
||||
foreach ($coursemods as $coursemod) {
|
||||
$mod = get_coursemodule_from_id($coursemod->modname, $coursemod->id);
|
||||
$options[$coursemod->id] = format_string($mod->name);
|
||||
}
|
||||
}
|
||||
$mform->addElement('select', 'cmid', get_string('linkedactivity', 'grades'), $options);
|
||||
$mform->setDefault('cmid', 0);
|
||||
|
||||
|
||||
// $mform->addElement('text', 'calculation', get_string('calculation', 'grades'));
|
||||
|
||||
$mform->addElement('text', 'aggregationcoef', get_string('aggregationcoef', 'grades'));
|
||||
$mform->setDefault('aggregationcoef', 0.0);
|
||||
|
||||
$mform->addElement('advcheckbox', 'locked', get_string('locked', 'grades'));
|
||||
|
||||
$mform->addElement('date_time_selector', 'locktime', get_string('locktime', 'grades'), array('optional'=>true));
|
||||
|
||||
/// hidden params
|
||||
$mform->addElement('hidden', 'id', 0);
|
||||
$mform->setType('id', PARAM_INT);
|
||||
|
||||
$mform->addElement('hidden', 'courseid', $COURSE->id);
|
||||
$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, $COURSE;
|
||||
|
||||
$mform =& $this->_form;
|
||||
|
||||
if ($id = $mform->getElementValue('id')) {
|
||||
$grade_item = grade_item::fetch(array('id'=>$id));
|
||||
|
||||
//remove the aggregation coef element if not needed
|
||||
if ($grade_item->is_course_item()) {
|
||||
$mform->removeElement('aggregationcoef');
|
||||
|
||||
} else if ($grade_item->is_category_item()) {
|
||||
$category = $grade_item->get_item_category();
|
||||
$parent_category = $category->get_parent_category();
|
||||
if (!$parent_category->is_aggregationcoef_used()) {
|
||||
$mform->removeElement('aggregationcoef');
|
||||
}
|
||||
|
||||
} else {
|
||||
$parent_category = $grade_item->get_parent_category();
|
||||
if (!$parent_category->is_aggregationcoef_used()) {
|
||||
$mform->removeElement('aggregationcoef');
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$course_category = grade_category::fetch_course_category($COURSE->id);
|
||||
if (!$course_category->is_aggregationcoef_used()) {
|
||||
$mform->removeElement('aggregationcoef');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// perform extra validation before submission
|
||||
function validation($data){
|
||||
$errors= array();
|
||||
|
||||
if (0 == count($errors)){
|
||||
return true;
|
||||
} else {
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
|
@ -150,6 +150,7 @@ if ($moving) {
|
|||
} else {
|
||||
print_single_button('category.php', array('courseid'=>$course->id), get_string('addcategory', 'grades'), 'get');
|
||||
print_single_button('item.php', array('courseid'=>$course->id), get_string('additem', 'grades'), 'get');
|
||||
print_single_button('outcomeitem.php', array('courseid'=>$course->id), get_string('addoutcomeitem', 'grades'), 'get');
|
||||
print_single_button('tree.php', array('id'=>$course->id, 'action'=>'autosort'), get_string('autosort', 'grades'), 'get');
|
||||
print_single_button('tree.php', array('id'=>$course->id, 'action'=>'synclegacy'), get_string('synclegacygrades', 'grades'), 'get');
|
||||
}
|
||||
|
@ -182,6 +183,12 @@ function print_grade_tree(&$gtree, $element, $moving, &$gpr) {
|
|||
$actions .= $gtree->get_locking_icon($element, $gpr);
|
||||
|
||||
$name = $object->get_name();
|
||||
|
||||
//TODO: improve outcome visulisation
|
||||
if ($element['type'] == 'item' and !empty($object->outcomeid)) {
|
||||
$name = $name.' ('.get_string('outcome', 'grades').')';
|
||||
}
|
||||
|
||||
if ($object->is_hidden()) {
|
||||
$name = '<span class="dimmed_text">'.$name.'</span>';
|
||||
}
|
||||
|
|
|
@ -580,7 +580,11 @@ class grade_tree {
|
|||
case 'item':
|
||||
case 'categoryitem':
|
||||
case 'courseitem':
|
||||
if (empty($object->outcomeid)) {
|
||||
$url = $CFG->wwwroot.'/grade/edit/item.php?courseid='.$this->courseid.'&id='.$object->id;
|
||||
} else {
|
||||
$url = $CFG->wwwroot.'/grade/edit/outcomeitem.php?courseid='.$this->courseid.'&id='.$object->id;
|
||||
}
|
||||
$url = $gpr->add_url_params($url);
|
||||
break;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue