}
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();
}
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();
// 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();
}
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();
}
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);
$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)) {
$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'),
--- /dev/null
+<?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);
--- /dev/null
+<?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;
+ }
+ }
+
+}
+?>
} 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');
}
$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>';
}
case 'item':
case 'categoryitem':
case 'courseitem':
- $url = $CFG->wwwroot.'/grade/edit/item.php?courseid='.$this->courseid.'&id='.$object->id;
+ 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;
<?php
foreach ($outcomes as $outcome) {
-
+
// do not include items already used in course
if (in_array($outcome->id, array_keys($courseoutcomes))) {
- continue;
+ continue;
}
-
+
echo '<option value="'.$outcome->id.'">'.truncate($outcome->fullname, 150).'</option>';
}
?>
</select>
</td>
<td>
- <?php
+ <?php
// only show arrows if user has privilages to manage
- if (has_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_COURSE, $courseid))) {
+ if (has_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_COURSE, $courseid))) {
?>
<p class="arrow_button">
<input name="add" id="add" type="submit" value="<?php echo ' '.$THEME->rarrow.' '.get_string('add'); ?>" title="<?php print_string('add'); ?>" />
$navigation = build_navigation($navlinks);
/// Print header
- print_header_simple($strgrades.':'.$stroutcomes, ':'.$strgrades, $navigation, '', '', true);
-
+ print_header_simple($strgrades.':'.$stroutcomes, ':'.$strgrades, $navigation, '', '', true);
+
$strdeleteoutcomecheck = get_string('deleteoutcomecheck', 'grades');
notice_yesno($strdeleteoutcomecheck,
'course.php?id='.$courseid.'&deleteid='.$deleteid.'&confirm=1&sesskey='.sesskey(),
if ($data = data_submitted()) {
require_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_COURSE, $courseid));
if (!empty($data->add) && !empty($data->addoutcomes)) {
- /// add all selected to course list
+ /// add all selected to course list
foreach ($data->addoutcomes as $add) {
$goc -> courseid = $courseid;
$goc -> outcomeid = $add;
insert_record('grade_outcomes_courses', $goc);
}
} else if (!empty($data->remove) && !empty($data->removeoutcomes)) {
- /// remove all selected from course outcomes list
+ /// remove all selected from course outcomes list
foreach ($data->removeoutcomes as $remove) {
delete_records('grade_outcomes_courses', 'courseid', $courseid, 'outcomeid', $remove);
- }
+ }
}
}
FROM '.$CFG->prefix.'grade_outcomes_courses goc,
'.$CFG->prefix.'grade_outcomes go
WHERE goc.courseid = '.$courseid.'
- AND goc.outcomeid = go.id');
-
+ AND goc.outcomeid = go.id');
+
if (empty($courseoutcomes)) {
- $courseoutcomes = get_records('grade_outcomes', 'courseid', $courseid);
+ $courseoutcomes = get_records('grade_outcomes', 'courseid', $courseid);
} elseif ($mcourseoutcomes = get_records('grade_outcomes', 'courseid', $courseid)) {
$courseoutcomes += $mcourseoutcomes;
}
check_theme_arrows();
include_once('course.html');
-
+
/// interface to add/edit/delete course specific outcomes
echo '<p/>';
print_string('coursespecoutcome', 'grades'); // course sepcific outcomes
$totalcount = count_records('grade_outcomes_courses', 'courseid', $courseid);
$baseurl = "course.php";
print_paging_bar($totalcount, $page, $perpage, $baseurl);
-
+
if ($outcomes = get_recordset('grade_outcomes', 'courseid', $courseid, '', '*', $page * $perpage, $perpage)) {
$tablecolumns = array('outcome', 'scale', 'edit', 'usedgradeitems');
// full name of the scale used by this outcomes
$scale= get_record('scale', 'id', $outcome->scaleid);
$data[] = $scale->name;
-
+
if (has_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_COURSE, $courseid))) {
// add operations
$data[] = '<a href="editoutcomes.php?id='.$outcome->id.'&courseid='.$courseid.'&sesskey='.sesskey().'"><img alt="Update" class="iconsmall" src="'.$CFG->wwwroot.'/pix/t/edit.gif"/></a>
<a href="course.php?deleteid='.$outcome->id.'&id='.$courseid.'&sesskey='.sesskey().'"><img alt="Delete" class="iconsmall" src="'.$CFG->wwwroot.'/pix/t/delete.gif"/></a>'; // icons and links
} else {
- $data[] = '';
+ $data[] = '';
}
// num of gradeitems using this
$num = count_records('grade_items', 'outcomeid' ,$outcome->id);
$table->print_html();
}
if (has_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_COURSE, $courseid))) {
- echo '<a href="editoutcomes.php?courseid='.$courseid.'">Add a new outcome</a>';
+ echo '<a href="editoutcomes.php?courseid='.$courseid.'">Add a new outcome</a>';
}
print_footer();
-
-/**
+
+/**
* truncates a string to a length of num
* @param string string
* @param int num
'gradereport/outcomes:manage' => array(
'riskbitmask' => RISK_CONFIG,
'captype' => 'write',
- 'contextlevel' => CONTEXT_COURSE,
+ 'contextlevel' => CONTEXT_COURSE,
'legacy' => array(
'editingteacher' => CAP_ALLOW,
'admin' => CAP_ALLOW
$returnurl = $CFG->wwwroot."/grade/report/outcomes/course.php?id=$courseid";
} else {
// admin editting site level outcomes
- require_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_SYSTEM));
+ require_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_SYSTEM));
$returnurl = $CFG->wwwroot."/grade/report/outcomes/site.php";
}
// form processing
}
if ($data = $mform->get_data()) {
if ($data->courseid == 0) {
- $data->courseid = NULL;
+ $data->courseid = NULL;
}
-
+
if ($data->id) {
update_record('grade_outcomes', $data);
} else {
// setting up params
$courseid = optional_param('id', SITEID, PARAM_INT); // course id
-require_capability('gradereport/outcomes:view', get_context_instance(CONTEXT_SYSTEM));
+require_capability('gradereport/outcomes:view', get_context_instance(CONTEXT_SYSTEM));
/// check capability
$page = optional_param('page', 0, PARAM_INT); // current page
// delete all outcomes used in grade items
delete_records('grade_outcomes_courses', 'outcomeid', $deleteid);
delete_records('grade_outcomes', 'id', $deleteid);
- } else {
+ } else {
$strgrades = get_string('grades');
$stroutcomes = get_string('outcomes', 'grades');
$navlinks = array();
$navigation = build_navigation($navlinks);
/// Print header
- print_header_simple($strgrades.':'.$stroutcomes, ':'.$strgrades, $navigation, '', '', true);
+ print_header_simple($strgrades.':'.$stroutcomes, ':'.$strgrades, $navigation, '', '', true);
// prints confirmation
$strdeleteoutcomecheck = get_string('deleteoutcomecheck', 'grades');
notice_yesno($strdeleteoutcomecheck,
// add operations
if (has_capability('gradereport/outcomes:manage', get_context_instance(CONTEXT_SYSTEM))) {
-
+
$data[] = '<a href="editoutcomes.php?id='.$outcome->id.'&sesskey='.sesskey().'"><img alt="Update" class="iconsmall" src="'.$CFG->wwwroot.'/pix/t/edit.gif"/></a>
<a href="site.php?deleteid='.$outcome->id.'&sesskey='.sesskey().'"><img alt="Delete" class="iconsmall" src="'.$CFG->wwwroot.'/pix/t/delete.gif"/></a>'; // icons and links
-
+
} else {
- $data[] = '';
+ $data[] = '';
}
// num of gradeitems using this
$num = count_records('grade_items', 'outcomeid' ,$outcome->id);