@@ -227,11 +227,11 @@ function definition() {
227227 $ mform ->addHelpButton ('gradetype ' , 'gradetype ' , 'hsuforum ' );
228228
229229 $ mform ->insertElementBefore ($ mform ->removeElement ('gradetype ' ), 'grade ' );
230- // $scale = $mform->insertElementBefore($mform->removeElement('scale'), 'grade');
231- // $scale->setLabel(get_string('grade'));
232- //
233- // // Done abusing this poor fellow...
234- // $mform->removeElement('grade');
230+ $ scale = $ mform ->insertElementBefore ($ mform ->removeElement ('scale ' ), 'grade ' );
231+ $ scale ->setLabel (get_string ('grade ' ));
232+
233+ // Done abusing this poor fellow...
234+ $ mform ->removeElement ('grade ' );
235235
236236 if ($ this ->_features ->advancedgrading ) {
237237 foreach ($ this ->current ->_advancedgradingdata ['areas ' ] as $ areaname => $ areadata ) {
@@ -266,10 +266,100 @@ function definition() {
266266
267267 function standard_grading_coursemodule_elements () {
268268 $ this ->_features ->rating = false ;
269- parent :: standard_grading_coursemodule_elements ();
269+ $ this -> standard_hsuforum_grading_coursemodule_elements ();
270270 $ this ->_features ->rating = true ;
271271 }
272272
273+ public function standard_hsuforum_grading_coursemodule_elements () {
274+ global $ COURSE , $ CFG ;
275+ $ mform =& $ this ->_form ;
276+ $ isupdate = !empty ($ this ->_cm );
277+ $ gradeoptions = array ('isupdate ' => $ isupdate ,
278+ 'currentgrade ' => false ,
279+ 'hasgrades ' => false ,
280+ 'canrescale ' => $ this ->_features ->canrescale ,
281+ 'useratings ' => $ this ->_features ->rating );
282+
283+ if ($ this ->_features ->hasgrades ) {
284+
285+ if (!$ this ->_features ->rating || $ this ->_features ->gradecat ) {
286+ $ mform ->addElement ('header ' , 'modstandardgrade ' , get_string ('grade ' ));
287+ }
288+
289+ //if supports grades and grades arent being handled via ratings
290+ if (!$ this ->_features ->rating ) {
291+
292+ if ($ isupdate ) {
293+ $ gradeitem = grade_item::fetch (array ('itemtype ' => 'mod ' ,
294+ 'itemmodule ' => $ this ->_cm ->modname ,
295+ 'iteminstance ' => $ this ->_cm ->instance ,
296+ 'itemnumber ' => 0 ,
297+ 'courseid ' => $ COURSE ->id ));
298+ if ($ gradeitem ) {
299+ $ gradeoptions ['currentgrade ' ] = $ gradeitem ->grademax ;
300+ $ gradeoptions ['currentgradetype ' ] = $ gradeitem ->gradetype ;
301+ $ gradeoptions ['currentscaleid ' ] = $ gradeitem ->scaleid ;
302+ $ gradeoptions ['hasgrades ' ] = $ gradeitem ->has_grades ();
303+ }
304+ }
305+ $ mform ->addElement ('modgrade ' , 'grade ' , get_string ('grade ' ), $ gradeoptions );
306+ $ mform ->addHelpButton ('grade ' , 'modgrade ' , 'grades ' );
307+ $ mform ->setDefault ('grade ' , $ CFG ->gradepointdefault );
308+ }
309+
310+ if ($ this ->_features ->advancedgrading
311+ and !empty ($ this ->current ->_advancedgradingdata ['methods ' ])
312+ and !empty ($ this ->current ->_advancedgradingdata ['areas ' ])) {
313+
314+ if (count ($ this ->current ->_advancedgradingdata ['areas ' ]) == 1 ) {
315+ // if there is just one gradable area (most cases), display just the selector
316+ // without its name to make UI simplier
317+ $ areadata = reset ($ this ->current ->_advancedgradingdata ['areas ' ]);
318+ $ areaname = key ($ this ->current ->_advancedgradingdata ['areas ' ]);
319+ $ mform ->addElement ('select ' , 'advancedgradingmethod_ ' .$ areaname ,
320+ get_string ('gradingmethod ' , 'core_grading ' ), $ this ->current ->_advancedgradingdata ['methods ' ]);
321+ $ mform ->addHelpButton ('advancedgradingmethod_ ' .$ areaname , 'gradingmethod ' , 'core_grading ' );
322+ if (!$ this ->_features ->rating ) {
323+ $ mform ->hideIf ('advancedgradingmethod_ ' .$ areaname , 'grade[modgrade_type] ' , 'eq ' , 'none ' );
324+ }
325+
326+ } else {
327+ // the module defines multiple gradable areas, display a selector
328+ // for each of them together with a name of the area
329+ $ areasgroup = array ();
330+ foreach ($ this ->current ->_advancedgradingdata ['areas ' ] as $ areaname => $ areadata ) {
331+ $ areasgroup [] = $ mform ->createElement ('select ' , 'advancedgradingmethod_ ' .$ areaname ,
332+ $ areadata ['title ' ], $ this ->current ->_advancedgradingdata ['methods ' ]);
333+ $ areasgroup [] = $ mform ->createElement ('static ' , 'advancedgradingareaname_ ' .$ areaname , '' , $ areadata ['title ' ]);
334+ }
335+ $ mform ->addGroup ($ areasgroup , 'advancedgradingmethodsgroup ' , get_string ('gradingmethods ' , 'core_grading ' ),
336+ array (' ' , '<br /> ' ), false );
337+ }
338+ }
339+
340+ if ($ this ->_features ->gradecat ) {
341+ $ mform ->addElement ('select ' , 'gradecat ' ,
342+ get_string ('gradecategoryonmodform ' , 'grades ' ),
343+ grade_get_categories_menu ($ COURSE ->id , $ this ->_outcomesused ));
344+ $ mform ->addHelpButton ('gradecat ' , 'gradecategoryonmodform ' , 'grades ' );
345+ if (!$ this ->_features ->rating ) {
346+ $ mform ->hideIf ('gradecat ' , 'grade[modgrade_type] ' , 'eq ' , 'none ' );
347+ }
348+ }
349+
350+ // Grade to pass.
351+ $ mform ->addElement ('text ' , 'gradepass ' , get_string ('gradepass ' , 'grades ' ));
352+ $ mform ->addHelpButton ('gradepass ' , 'gradepass ' , 'grades ' );
353+ $ mform ->setDefault ('gradepass ' , '' );
354+ $ mform ->setType ('gradepass ' , PARAM_RAW );
355+ if (!$ this ->_features ->rating ) {
356+ $ mform ->hideIf ('gradepass ' , 'grade[modgrade_type] ' , 'eq ' , 'none ' );
357+ } else {
358+ $ mform ->hideIf ('gradepass ' , 'assessed ' , 'eq ' , '0 ' );
359+ }
360+ }
361+ }
362+
273363 function definition_after_data () {
274364 $ this ->_features ->rating = false ;
275365 parent ::definition_after_data ();
0 commit comments