MDL-10829 Added get_grade_item() to the grade_item class, for cases when we don't whether an object is a category or a grade_item. The new interface for viewing and adding idnumbers (no editing) is 99% finished. Help strings still to do.
This commit is contained in:
@@ -5,8 +5,10 @@ require_once $CFG->dirroot.'/grade/lib.php';
|
||||
require_once $CFG->libdir.'/mathslib.php';
|
||||
require_once 'calculation_form.php';
|
||||
|
||||
$courseid = required_param('courseid', PARAM_INT);
|
||||
$id = required_param('id', PARAM_INT);
|
||||
$courseid = required_param('courseid', PARAM_INT);
|
||||
$id = required_param('id', PARAM_INT);
|
||||
$section = optional_param('section', 'calculation', PARAM_ALPHA);
|
||||
$idnumbers = optional_param('idnumbers', null, PARAM_RAW);
|
||||
|
||||
if (!$course = get_record('course', 'id', $courseid)) {
|
||||
print_error('nocourseid');
|
||||
@@ -27,10 +29,10 @@ if (!$grade_item = grade_item::fetch(array('id'=>$id, 'courseid'=>$course->id)))
|
||||
// module items and items without grade can not have calculation
|
||||
if (($grade_item->is_normal_item() and !$grade_item->is_outcome_item())
|
||||
or ($grade_item->gradetype != GRADE_TYPE_VALUE and $grade_item->gradetype != GRADE_TYPE_SCALE)) {
|
||||
redirect($returnurl, get_string('erornocalculationallowed', 'grades')); //TODO: localize
|
||||
redirect($returnurl, get_string('errornocalculationallowed', 'grades')); //TODO: localize
|
||||
}
|
||||
|
||||
$mform = new edit_calculation_form(null, array('gpr'=>$gpr));
|
||||
$mform = new edit_calculation_form(null, array('gpr'=>$gpr, 'itemid' => $grade_item->id));
|
||||
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect($returnurl);
|
||||
@@ -41,12 +43,41 @@ $calculation = calc_formula::localize($grade_item->calculation);
|
||||
$calculation = grade_item::denormalize_formula($calculation, $grade_item->courseid);
|
||||
$mform->set_data(array('courseid'=>$grade_item->courseid, 'calculation'=>$calculation, 'id'=>$grade_item->id, 'itemname'=>$grade_item->itemname));
|
||||
|
||||
$errors = array();
|
||||
|
||||
if ($data = $mform->get_data(false)) {
|
||||
$calculation = calc_formula::unlocalize($data->calculation);
|
||||
$grade_item->set_calculation($calculation);
|
||||
|
||||
redirect($returnurl);
|
||||
|
||||
} elseif (!empty($section) AND $section='idnumbers' AND !empty($idnumbers)) { // Handle idnumbers separately (non-mform)
|
||||
//first validate and store the new idnumbers
|
||||
foreach ($idnumbers as $giid => $value) {
|
||||
if ($gi = grade_item::fetch(array('id' => $giid))) {
|
||||
if ($gi->itemtype == 'mod') {
|
||||
$cm = get_coursemodule_from_instance($gi->itemmodule, $gi->iteminstance, $gi->courseid);
|
||||
} else {
|
||||
$cm = null;
|
||||
}
|
||||
|
||||
if (!grade_verify_idnumber($value, $gi, $cm)) {
|
||||
$errors[$giid] = get_string('idnumbertaken');
|
||||
continue;
|
||||
}
|
||||
|
||||
if (empty($gi->idnumber) and !$gi->add_idnumber(stripslashes($idnumbers[$gi->id]))) {
|
||||
$errors[$giid] = get_string('error');
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
$errors[$giid] = 'Could not fetch the grade_item with id=' . $giid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$gtree = new grade_tree($course->id, false, false);
|
||||
|
||||
$strgrades = get_string('grades');
|
||||
$strgraderreport = get_string('graderreport', 'grades');
|
||||
$strcalculationedit = get_string('editcalculation', 'grades');
|
||||
@@ -56,5 +87,129 @@ $navigation = grade_build_nav(__FILE__, $strcalculationedit, array('courseid' =>
|
||||
print_header_simple($strgrades . ': ' . $strgraderreport, ': ' . $strcalculationedit, $navigation, '', '', true, '', navmenu($course));
|
||||
|
||||
$mform->display();
|
||||
// Now show the gradetree with the idnumbers add/edit form
|
||||
echo '
|
||||
<form class="mform" id="mform2" method="post" action="' . $CFG->wwwroot . '/grade/edit/tree/calculation.php?courseid='.$courseid.'&id='.$id.'">
|
||||
<div style="display: none;">
|
||||
<input type="hidden" value="'.$id.'" name="id"/>
|
||||
<input type="hidden" value="'.$courseid.'" name="courseid"/>
|
||||
<input type="hidden" value="'.$gpr->type.'" name="gpr_type"/>
|
||||
<input type="hidden" value="'.$gpr->plugin.'" name="gpr_plugin"/>
|
||||
<input type="hidden" value="'.$gpr->courseid.'" name="gpr_courseid"/>
|
||||
<input type="hidden" value="'.sesskey().'" name="sesskey"/>
|
||||
<input type="hidden" value="idnumbers" name="section"/>
|
||||
</div>
|
||||
|
||||
<fieldset id="idnumbers" class="clearfix">
|
||||
<legend class="ftoggler">'.get_string('idnumbers', 'grades').'</legend>
|
||||
<div class="fcontainer clearfix">
|
||||
<ul>
|
||||
' . get_grade_tree($gtree, $gtree->top_element, $id, $errors) . '
|
||||
</ul>
|
||||
</div>
|
||||
</fieldset>
|
||||
<div class="fitem" style="text-align: center;">
|
||||
<input id="id_addidnumbers" type="submit" value="'.get_string('addidnumbers', 'grades').'" name="addidnumbers" />
|
||||
</div>
|
||||
</form>';
|
||||
|
||||
print_footer($course);
|
||||
die();
|
||||
|
||||
|
||||
/**
|
||||
* Simplified version of the print_grade_tree() recursive function found in grade/edit/tree/index.php
|
||||
* Only prints a tree with a basic icon for each element, and an edit field for
|
||||
* items without an idnumber.
|
||||
* @param object $gtree
|
||||
* @param object $element
|
||||
* @param int $current_itemid The itemid of this page: should be excluded from the tree
|
||||
* @param array $errors An array of idnumbers => error
|
||||
* @return string
|
||||
*/
|
||||
function get_grade_tree(&$gtree, $element, $current_itemid=null, $errors=null) {
|
||||
global $CFG;
|
||||
|
||||
$object = $element['object'];
|
||||
$eid = $element['eid'];
|
||||
$type = $element['type'];
|
||||
$grade_item = $object->get_grade_item();
|
||||
|
||||
$name = $object->get_name();
|
||||
$return_string = '';
|
||||
|
||||
//TODO: improve outcome visualisation
|
||||
if ($type == 'item' and !empty($object->outcomeid)) {
|
||||
$name = $name.' ('.get_string('outcome', 'grades').')';
|
||||
}
|
||||
|
||||
$idnumber = $object->get_idnumber();
|
||||
|
||||
// Don't show idnumber or input field for current item if given to function. Highlight the item instead.
|
||||
if ($type != 'category') {
|
||||
if (is_null($current_itemid) OR $grade_item->id != $current_itemid) {
|
||||
if ($idnumber) {
|
||||
$name .= ": [[$idnumber]]";
|
||||
} else {
|
||||
$closingdiv = '';
|
||||
if (!empty($errors[$grade_item->id])) {
|
||||
$name .= '<div class="error"><span class="error">' . $errors[$grade_item->id].'</span><br />'."\n";
|
||||
$closingdiv = "</div>\n";
|
||||
}
|
||||
$name .= '<input class="idnumber" id="id_idnumber_'.$grade_item->id.'" type="text" name="idnumbers['.$grade_item->id.']" />' . "\n";
|
||||
$name .= $closingdiv;
|
||||
}
|
||||
} else {
|
||||
$name = "<strong>$name</strong>";
|
||||
}
|
||||
}
|
||||
|
||||
$icon = '<img src="'.$CFG->wwwroot.'/pix/spacer.gif" class="icon" alt=""/>' . "\n";
|
||||
$last = '';
|
||||
$catcourseitem = false;
|
||||
|
||||
switch ($type) {
|
||||
case 'item':
|
||||
if ($object->itemtype == 'mod') {
|
||||
$icon = '<img src="'.$CFG->modpixpath.'/'.$object->itemmodule.'/icon.gif" class="icon" alt="'
|
||||
. get_string('modulename', $object->itemmodule).'"/>' . "\n";
|
||||
} else if ($object->itemtype == 'manual') {
|
||||
//TODO: add manual grading icon
|
||||
if (empty($object->outcomeid)) {
|
||||
$icon = '<img src="'.$CFG->pixpath.'/t/edit.gif" class="icon" alt="'
|
||||
. get_string('manualgrade', 'grades').'"/>' . "\n"; // TODO: localize
|
||||
} else {
|
||||
$icon = '<img src="'.$CFG->pixpath.'/i/outcomes.gif" class="icon" alt="'
|
||||
. get_string('outcome', 'grades').'"/>' . "\n";
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'courseitem':
|
||||
case 'categoryitem':
|
||||
$icon = '<img src="'.$CFG->pixpath.'/i/category_grade.gif" class="icon" alt="'.get_string('categorygrade').'"/>' . "\n"; // TODO: localize
|
||||
$catcourseitem = true;
|
||||
break;
|
||||
case 'category':
|
||||
$icon = '<img src="'.$CFG->pixpath.'/f/folder.gif" class="icon" alt="'.get_string('category').'"/>' . "\n";
|
||||
break;
|
||||
}
|
||||
|
||||
if ($type != 'category') {
|
||||
$return_string .= '<li class="'.$type.'">'.$icon.$name.'</li>' . "\n";
|
||||
} else {
|
||||
$return_string .= '<li class="'.$type.'">'.$icon.$name . "\n";
|
||||
$return_string .= '<ul class="catlevel'.$element['depth'].'">'."\n";
|
||||
$last = null;
|
||||
foreach($element['children'] as $child_el) {
|
||||
$return_string .= get_grade_tree($gtree, $child_el, $current_itemid, $errors);
|
||||
}
|
||||
if ($last) {
|
||||
$return_string .= get_grade_tree($gtree, $last, $current_itemid, $errors);
|
||||
}
|
||||
$return_string .= '</ul></li>'."\n";
|
||||
}
|
||||
|
||||
return $return_string;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -5,45 +5,34 @@ require_once $CFG->libdir.'/formslib.php';
|
||||
class edit_calculation_form extends moodleform {
|
||||
var $available;
|
||||
var $noidnumbers;
|
||||
var $showing;
|
||||
|
||||
function definition() {
|
||||
global $COURSE;
|
||||
|
||||
$mform =& $this->_form;
|
||||
|
||||
$itemid = $this->_customdata['itemid'];
|
||||
|
||||
$this->available = grade_item::fetch_all(array('courseid'=>$COURSE->id));
|
||||
$this->noidnumbers = array();
|
||||
|
||||
// All items that have no idnumbers are added to a separate section of the form (hidden by default),
|
||||
// enabling the user to assign idnumbers to these grade_items.
|
||||
foreach ($this->available as $item) {
|
||||
if (empty($item->idnumber)) {
|
||||
$this->noidnumbers[$item->id] = $item;
|
||||
unset($this->available[$item->id]);
|
||||
}
|
||||
if ($item->id == $itemid) { // Do not include the current grade_item in the available section
|
||||
unset($this->available[$item->id]);
|
||||
}
|
||||
}
|
||||
|
||||
/// visible elements
|
||||
$mform->addElement('header', 'general', get_string('gradeitem', 'grades'));
|
||||
|
||||
$mform->addElement('static', 'itemname', get_string('itemname', 'grades'));
|
||||
$mform->addElement('textarea', 'calculation', get_string('calculation', 'grades'), 'cols="60" rows="5"');
|
||||
|
||||
/// idnumbers
|
||||
$mform->addElement('header', 'availableheader', get_string('availableidnumbers', 'grades'));
|
||||
foreach ($this->available as $item) {
|
||||
$mform->addElement('static', 'idnumber_'.$item->id, $item->get_name());
|
||||
$mform->setDefault('idnumber_'.$item->id, '[['.$item->idnumber.']]');
|
||||
}
|
||||
|
||||
|
||||
/// set idnumbers
|
||||
if ($this->noidnumbers) {
|
||||
$mform->addElement('header', 'addidnumbersheader', get_string('addidnumbers', 'grades'));
|
||||
foreach ($this->noidnumbers as $item) {
|
||||
$mform->addElement('text', 'idnumber_'.$item->id, $item->get_name(), 'size="30"');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// hidden params
|
||||
$mform->addElement('hidden', 'id', 0);
|
||||
$mform->setType('id', PARAM_INT);
|
||||
@@ -51,19 +40,14 @@ class edit_calculation_form extends moodleform {
|
||||
$mform->addElement('hidden', 'courseid', 0);
|
||||
$mform->setType('courseid', PARAM_INT);
|
||||
|
||||
$mform->addElement('hidden', 'showingadding', 0);
|
||||
|
||||
$mform->addElement('hidden', 'section', 0);
|
||||
$mform->setType('section', PARAM_ALPHA);
|
||||
$mform->setDefault('section', 'calculation');
|
||||
|
||||
/// add return tracking info
|
||||
$gpr = $this->_customdata['gpr'];
|
||||
$gpr->add_mform_elements($mform);
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
// buttons
|
||||
if ($this->noidnumbers) {
|
||||
$mform->addElement('submit', 'addidnumbers', get_string('addidnumbers', 'grades'));
|
||||
$mform->registerNoSubmitButton('addidnumbers');
|
||||
}
|
||||
$this->add_action_buttons();
|
||||
}
|
||||
|
||||
@@ -71,23 +55,6 @@ class edit_calculation_form extends moodleform {
|
||||
global $CFG, $COURSE;
|
||||
|
||||
$mform =& $this->_form;
|
||||
|
||||
if ($this->noidnumbers) {
|
||||
if (optional_param('addidnumbers', 0, PARAM_RAW)) {
|
||||
$el =& $mform->getElement('showingadding');
|
||||
$el->setValue(1);
|
||||
}
|
||||
|
||||
$this->showing = $mform->getElementValue('showingadding');
|
||||
if (!$this->showing) {
|
||||
foreach ($this->noidnumbers as $item) {
|
||||
$mform->removeElement('idnumber_'.$item->id);
|
||||
}
|
||||
$mform->removeElement('addidnumbersheader');
|
||||
} else {
|
||||
$mform->removeElement('addidnumbers');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// perform extra validation before submission
|
||||
@@ -96,37 +63,6 @@ class edit_calculation_form extends moodleform {
|
||||
|
||||
$mform =& $this->_form;
|
||||
|
||||
//first validate and store the new idnumbers
|
||||
if ($this->noidnumbers and $this->showing) {
|
||||
foreach ($this->noidnumbers as $grade_item) {
|
||||
$idnumber = 'idnumber_'.$grade_item->id;
|
||||
if (!empty($data[$idnumber])) {
|
||||
if ($grade_item->itemtype == 'mod') {
|
||||
$cm = get_coursemodule_from_instance($grade_item->itemmodule, $grade_item->iteminstance, $grade_item->courseid);
|
||||
} else {
|
||||
$cm = null;
|
||||
}
|
||||
|
||||
if (!grade_verify_idnumber($data[$idnumber], $grade_item, $cm)) {
|
||||
$errors[$idnumber] = get_string('idnumbertaken');
|
||||
continue;
|
||||
}
|
||||
|
||||
if (empty($grade_item->idnumber) and !$grade_item->add_idnumber(stripslashes($data['idnumber_'.$grade_item->id]))) {
|
||||
$errors[$idnumber] = get_string('error');
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// lock the adding field if idnumber already present or just changed
|
||||
if (!empty($grade_item->idnumber)) {
|
||||
$el =& $mform->getElement($idnumber);
|
||||
$el->setValue($grade_item->idnumber);
|
||||
$mform->hardFreeze($idnumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check the calculation formula
|
||||
if ($data['calculation'] != '') {
|
||||
$grade_item = grade_item::fetch(array('id'=>$data['id'], 'courseid'=>$data['courseid']));
|
||||
|
||||
@@ -1027,6 +1027,15 @@ class grade_item extends grade_object {
|
||||
return $this->idnumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns this grade_item. This method is also available in
|
||||
* grade_category, for cases where the object type is not know.
|
||||
* @return string idnumber
|
||||
*/
|
||||
function get_grade_item() {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the sortorder of this grade_item. This method is also available in
|
||||
* grade_category, for cases where the object type is not know.
|
||||
|
||||
@@ -2207,6 +2207,10 @@ body#doc-contents ul {
|
||||
text-align:center;
|
||||
}
|
||||
|
||||
.grade-edit-tree .idnumber {
|
||||
margin-left: 15px;
|
||||
}
|
||||
|
||||
.grade-edit-tree .buttons .singlebutton {
|
||||
display: inline;
|
||||
padding: 5px;
|
||||
@@ -2775,10 +2779,10 @@ h2.tag-heading {
|
||||
text-align:center;
|
||||
margin-left:auto;
|
||||
margin-right:auto;
|
||||
display:block;
|
||||
display:block;
|
||||
width:95%;
|
||||
padding: 5px 5px 5px 5px;
|
||||
|
||||
|
||||
}
|
||||
|
||||
div#tag-description {
|
||||
@@ -2796,13 +2800,13 @@ div#tag-management-box {
|
||||
display:block;
|
||||
font-size:12px;
|
||||
}
|
||||
|
||||
|
||||
div#tag-user-table {
|
||||
padding:3px;
|
||||
width:95%;
|
||||
clear: both;
|
||||
margin-left:auto;
|
||||
margin-right:auto;
|
||||
margin-right:auto;
|
||||
display:block;
|
||||
}
|
||||
|
||||
@@ -2821,9 +2825,9 @@ div.user-box {
|
||||
margin-left:8px;
|
||||
margin-right:8px;
|
||||
margin-top:8px;
|
||||
margin-bottom:8px;
|
||||
margin-bottom:8px;
|
||||
width:115px;
|
||||
height:160px;
|
||||
height:160px;
|
||||
text-align:center;
|
||||
display:block;
|
||||
float:left;
|
||||
@@ -2864,14 +2868,14 @@ ul#tag-cloud-list li {
|
||||
display:inline;
|
||||
}
|
||||
|
||||
/* search start*/
|
||||
/* search start*/
|
||||
|
||||
div#tag-search-box {
|
||||
text-align:center;
|
||||
margin-left:auto;
|
||||
margin-right:auto;
|
||||
margin-top:10px;
|
||||
margin-bottom:10px;
|
||||
margin-bottom:10px;
|
||||
}
|
||||
|
||||
div#tag-search-results-container {
|
||||
@@ -2884,7 +2888,7 @@ ul#tag-search-results {
|
||||
margin-left:20%;
|
||||
margin-right:20%;
|
||||
margin-top:15px;
|
||||
margin-bottom:0px;
|
||||
margin-bottom:0px;
|
||||
float:left;
|
||||
width:60%;
|
||||
display:block;
|
||||
@@ -2906,11 +2910,11 @@ div#tags-management-links {
|
||||
text-align:right;
|
||||
display:block;
|
||||
font-size:12px;
|
||||
|
||||
}
|
||||
/* search end*/
|
||||
|
||||
/* tag management start*/
|
||||
}
|
||||
/* search end*/
|
||||
|
||||
/* tag management start*/
|
||||
span.flagged-tag {
|
||||
color:#FF0000;
|
||||
}
|
||||
@@ -2926,15 +2930,15 @@ table#tag-management-list {
|
||||
|
||||
table#tag-management-list tr td{
|
||||
padding-left:4px;
|
||||
padding-right :4px;
|
||||
padding-right :4px;
|
||||
}
|
||||
|
||||
form#tag-management-form {
|
||||
text-align:center;
|
||||
}
|
||||
/* tag management end*/
|
||||
/* tag management end*/
|
||||
|
||||
/* autocomplete start*/
|
||||
/* autocomplete start*/
|
||||
#relatedtags-autocomplete-container
|
||||
{
|
||||
margin-left::auto;
|
||||
@@ -2948,11 +2952,11 @@ form#tag-management-form {
|
||||
display:block;
|
||||
width:60%;
|
||||
margin-left::auto;
|
||||
margin-right:auto;
|
||||
margin-right:auto;
|
||||
}
|
||||
#relatedtags-autocomplete .yui-ac-content
|
||||
{
|
||||
position:absolute;
|
||||
position:absolute;
|
||||
width:420px;
|
||||
left:53%;
|
||||
border:1px solid #404040;
|
||||
|
||||
Reference in New Issue
Block a user