Skip to content

Commit

Permalink
gradebook MDL-19133 shifted around some code to move module grade set…
Browse files Browse the repository at this point in the history
…tings into common code
  • Loading branch information
Andrew Davis committed Aug 13, 2010
1 parent aeda42f commit 1630662
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 26 deletions.
39 changes: 29 additions & 10 deletions course/moodleform_mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ protected function init_features() {
$this->_features->idnumber = plugin_supports('mod', $this->_modname, FEATURE_IDNUMBER, true);
$this->_features->introeditor = plugin_supports('mod', $this->_modname, FEATURE_MOD_INTRO, true);
$this->_features->defaultcompletion = plugin_supports('mod', $this->_modname, FEATURE_MODEDIT_DEFAULT_COMPLETION, true);
$this->_features->rating = plugin_supports('mod', $this->_modname, FEATURE_RATE, false);

$this->_features->gradecat = ($this->_features->outcomes or $this->_features->hasgrades);
}
Expand Down Expand Up @@ -121,12 +122,15 @@ function definition_after_data() {
if ($this->_features->gradecat) {
$gradecat = false;
if (!empty($CFG->enableoutcomes) and $this->_features->outcomes) {
if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) {
$outcomes = grade_outcome::fetch_all_available($COURSE->id);
if (!empty($outcomes)) {
$gradecat = true;
}
}
if ($items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$modulename,
'iteminstance'=>$instance, 'courseid'=>$COURSE->id))) {

$items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$modulename,'iteminstance'=>$instance, 'courseid'=>$COURSE->id));
//will be no items if, for example, this activity supports ratings but rating aggregate type == no ratings
if (!empty($items)) {
foreach ($items as $item) {
if (!empty($item->outcomeid)) {
$elname = 'outcome_'.$item->outcomeid;
Expand All @@ -135,6 +139,7 @@ function definition_after_data() {
}
}
}

foreach ($items as $item) {
if (is_bool($gradecat)) {
$gradecat = $item->categoryid;
Expand All @@ -150,9 +155,13 @@ function definition_after_data() {

if ($gradecat === false) {
// items and outcomes in different categories - remove the option
// TODO: it might be better to add a "Mixed categories" text instead
// TODO: add a "Mixed categories" text instead of removing elements with no explanation
if ($mform->elementExists('gradecat')) {
$mform->removeElement('gradecat');
if ($this->_features->rating) {
//if supports ratings then the max grade dropdown wasnt added so the grade box can be removed entirely
$mform->removeElement('modstandardgrade');
}
}
}
}
Expand Down Expand Up @@ -337,7 +346,8 @@ function standard_coursemodule_elements(){
}
}

if (plugin_supports('mod', $this->_modname, FEATURE_RATE, false)) {

if ($this->_features->rating) {
require_once($CFG->dirroot.'/rating/lib.php');
$rm = new rating_manager();

Expand All @@ -364,6 +374,9 @@ function standard_coursemodule_elements(){
$mform->disabledIf('assesstimefinish', 'ratingtime');
}

//doing this here means splitting up the grade related settings on the lesson settings page
//$this->standard_grading_coursemodule_elements();

$mform->addElement('header', 'modstandardelshdr', get_string('modstandardels', 'form'));
if ($this->_features->groups) {
$options = array(NOGROUPS => get_string('groupsnone'),
Expand Down Expand Up @@ -611,14 +624,20 @@ function standard_hidden_coursemodule_elements(){
}

public function standard_grading_coursemodule_elements() {
global $COURSE;
global $COURSE, $CFG;
$mform =& $this->_form;

if (plugin_supports('mod', $this->_modname, FEATURE_GRADE_HAS_GRADE, false)) {
$mform->addElement('header', 'modstandardgrade', get_string('grade'));
if ($this->_features->hasgrades) {

$mform->addElement('modgrade', 'grade', get_string('grade'));
$mform->setDefault('grade', 100);
if (!$this->_features->rating || $this->_features->gradecat) {
$mform->addElement('header', 'modstandardgrade', get_string('grade'));
}

//if supports grades and grades arent being handled via ratings
if (!$this->_features->rating) {
$mform->addElement('modgrade', 'grade', get_string('grade'));
$mform->setDefault('grade', 100);
}

if ($this->_features->gradecat) {
$categories = grade_get_categories_menu($COURSE->id, $this->_outcomesused);
Expand Down
4 changes: 2 additions & 2 deletions mod/assignment/mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ function definition() {
$mform->addElement('select', 'preventlate', get_string('preventlate', 'assignment'), $ynoptions);
$mform->setDefault('preventlate', 0);

$this->standard_grading_coursemodule_elements();

$typetitle = get_string('type'.$type, 'assignment');

// hack to support pluggable assignment type titles
if ($typetitle === '[[type'.$type.']]') {
$typetitle = get_string('type'.$type, 'assignment_'.$type);
}

$this->standard_grading_coursemodule_elements();

$mform->addElement('header', 'typedesc', $typetitle);

$assignmentinstance->setup_elements($mform);
Expand Down
6 changes: 1 addition & 5 deletions mod/data/mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ function definition() {
$mform->addElement('select', 'rssarticles', get_string('numberrssarticles', 'data') , $countoptions);
}

//$mform->addElement('checkbox', 'assessed', get_string('allowratings', 'data') , get_string('ratingsuse', 'data'));

//$mform->addElement('modgrade', 'scale', get_string('grade'), false);
//$mform->disabledIf('scale', 'assessed');

$this->standard_grading_coursemodule_elements();

$this->standard_coursemodule_elements();

Expand Down
3 changes: 3 additions & 0 deletions mod/forum/mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ function definition() {
$mform->disabledIf('warnafter', 'blockperiod', 'eq', 0);

//-------------------------------------------------------------------------------

$this->standard_grading_coursemodule_elements();

$this->standard_coursemodule_elements();
//-------------------------------------------------------------------------------
// buttons
Expand Down
2 changes: 2 additions & 0 deletions mod/glossary/mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ function definition() {
}

//-------------------------------------------------------------------------------

$this->standard_grading_coursemodule_elements();

$this->standard_coursemodule_elements();

Expand Down
11 changes: 2 additions & 9 deletions mod/lesson/mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ function definition() {
$mform->setAdvanced('password');
$mform->disabledIf('password', 'usepassword', 'eq', 0);

$this->standard_grading_coursemodule_elements();

//-------------------------------------------------------------------------------
$mform->addElement('header', 'gradeoptions', get_string('gradeoptions', 'lesson'));

Expand All @@ -145,15 +147,6 @@ function definition() {
$mform->addHelpButton('custom', 'customscoring', 'lesson');
$mform->setDefault('custom', 1);

$grades = array();
for ($i=100; $i>=0; $i--) {
$grades[$i] = $i;
}
$mform->addElement('select', 'grade', get_string('maxgrade', 'lesson'), $grades);
$mform->setDefault('grade', 0);
$mform->addHelpButton('grade', 'maxgrade', 'lesson');
$mform->disabledIf('grade', 'practice', 'eq', '1');

$mform->addElement('selectyesno', 'retake', get_string('retakesallowed', 'lesson'));
$mform->addHelpButton('retake', 'retakesallowed', 'lesson');
$mform->setDefault('retake', 0);
Expand Down

0 comments on commit 1630662

Please sign in to comment.