Moodle

Sort some way to get grades from gradebook formatted as gradebook does.

Details

  • Type: Improvement Improvement
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: 1.9.4
  • Fix Version/s: STABLE backlog
  • Component/s: Gradebook
  • Labels:
    None
  • Difficulty:
    Easy
  • Affected Branches:
    MOODLE_19_STABLE

Description

Once more, the public/private discussion of the gradebook rises...

Until now I was using one combination like this:

$grade_item = grade_get_grades($courseid, 'mod', $module->name, $cm->instance, $userid))

and then, used various calls to:

grade_format_gradevalue($grade, $item, true, GRADE_DISPLAY_TYPE_XXXX, $decimals=2)

to get the grade in various formats (real, %, letter...).

It seems that the grade_format_gradevalue() is private API, so there isn't any way to format grades (in public API) in a consistent way with the gradebook.

After HQ chat, Petr commented the way was to implement that in grade_format_gradevalue() (official public API), so it will return current information + "printable" information.

Perhaps it will need the "localised" and "decimals" parameters (or will apply gradebook settings, not sure). But, in any case, it should return ALSO the formatted grade in the formats (real, percentage, letter...) supported by current grade_format_gradevalue()

Would be great to have that working asap if no complex. Ciao

Activity

Hide
Petr Škoda (skodak) added a comment -

it does return "printable" value using gradebook settings, in Certificate mod you wanted percentages too

Show
Petr Škoda (skodak) added a comment - it does return "printable" value using gradebook settings, in Certificate mod you wanted percentages too
Hide
Eloy Lafuente (stronk7) added a comment -

It needs to contain all the possible outputs of the grade, if you keep grade_format_gradevalue() private. So, at least real/percentage/letter should be available to perform any combination.

Ciao

Show
Eloy Lafuente (stronk7) added a comment - It needs to contain all the possible outputs of the grade, if you keep grade_format_gradevalue() private. So, at least real/percentage/letter should be available to perform any combination. Ciao
Hide
Petr Škoda (skodak) added a comment -

sorrry for delaying, I have to fix several more major gradebook issues before the release

Show
Petr Škoda (skodak) added a comment - sorrry for delaying, I have to fix several more major gradebook issues before the release
Hide
Eloy Lafuente (stronk7) added a comment -

np, I'm using one (private api) workaround for that and it seems to be working. So don't worry. Do the important stuff before. I'll modify de workaround once you implement it. NP at all!

Show
Eloy Lafuente (stronk7) added a comment - np, I'm using one (private api) workaround for that and it seems to be working. So don't worry. Do the important stuff before. I'll modify de workaround once you implement it. NP at all!
Hide
Chardelle Busch added a comment -

Any progress on this? Printing a grade on the certificate breaks in 1.9.5.

When using the grade_format_gradevalue code mentioned by Eloy above it throws this error:

Fatal error: Call to undefined method object::bounded_grade() in C:\moodle1.95\joodle\www\moodle\lib\gradelib.php on line 723

Thanks

Show
Chardelle Busch added a comment - Any progress on this? Printing a grade on the certificate breaks in 1.9.5. When using the grade_format_gradevalue code mentioned by Eloy above it throws this error: Fatal error: Call to undefined method object::bounded_grade() in C:\moodle1.95\joodle\www\moodle\lib\gradelib.php on line 723 Thanks
Hide
Eloy Lafuente (stronk7) added a comment -

Hi Chardelle,

just fyi it seems to continue broken (and the new proposal to make that info directly available in grade_get_grades() isn't available yet).

In my code, all I did was to insert one

$item = new grade_item($item, false); /// TODO: Take this out once grade_get_grades() returns proper data.

call before calling grade_format_gradevalue(). It seems that the difference in the API is that the format function requires now one proper grade_item object where it wasn't requiring it before. It's a nasty hack (because that object in also part of private API) but at least allows 1.9.5 cert to continue working.

Once grade_get_grades() - public API - will be providing that info we simply will have to use it and abandon grade_format_gradevalue() - private API.

Offtopic: Andrea sent to Mike C out latest version of the certificate, I think it includes that fix. Ciao

Show
Eloy Lafuente (stronk7) added a comment - Hi Chardelle, just fyi it seems to continue broken (and the new proposal to make that info directly available in grade_get_grades() isn't available yet). In my code, all I did was to insert one $item = new grade_item($item, false); /// TODO: Take this out once grade_get_grades() returns proper data. call before calling grade_format_gradevalue(). It seems that the difference in the API is that the format function requires now one proper grade_item object where it wasn't requiring it before. It's a nasty hack (because that object in also part of private API) but at least allows 1.9.5 cert to continue working. Once grade_get_grades() - public API - will be providing that info we simply will have to use it and abandon grade_format_gradevalue() - private API. Offtopic: Andrea sent to Mike C out latest version of the certificate, I think it includes that fix. Ciao
Hide
Petr Škoda (skodak) added a comment -

hmm,
$item = new grade_item($item, false);
looks like a correct solution

and no Eloy, it always required full grade_item object like the rest of all internal methods and functions - it was just pure luck the function did not use any methods

Show
Petr Škoda (skodak) added a comment - hmm, $item = new grade_item($item, false); looks like a correct solution and no Eloy, it always required full grade_item object like the rest of all internal methods and functions - it was just pure luck the function did not use any methods
Hide
Eloy Lafuente (stronk7) added a comment -

Pure luck or no... it became unlucky in 1.9.5, hehe :-P In any case, grade_item() instantiating (private API) for just formatting some numbers sounds like a nasty hack. Sure, the solution is to make grade_get_grades() (public API) to return also that formatted information as commented.

Ciao

Show
Eloy Lafuente (stronk7) added a comment - Pure luck or no... it became unlucky in 1.9.5, hehe :-P In any case, grade_item() instantiating (private API) for just formatting some numbers sounds like a nasty hack. Sure, the solution is to make grade_get_grades() (public API) to return also that formatted information as commented. Ciao
Hide
Chardelle Busch added a comment -

Okay, thanks Eloy. The certificate is hacked for 1.9.5. Maybe grade formatting is something that should be revisited for 2.0?

Show
Chardelle Busch added a comment - Okay, thanks Eloy. The certificate is hacked for 1.9.5. Maybe grade formatting is something that should be revisited for 2.0?
Hide
Jeffrey Silverman added a comment -

One of our developers suggested a graceful failure for the workaround, above.

if (!($item instanceof grade_grade)) {
$item = new grade_item($item, false); /// TODO: Take this out once grade_get_grades() returns proper data.
}

I think you get the idea, even if it has a typo in it (because it might).

Also, to clarify further on the comment that had the workaround, I put that block in place at approximately line 819 of mod/certificate/lib.php

Show
Jeffrey Silverman added a comment - One of our developers suggested a graceful failure for the workaround, above. if (!($item instanceof grade_grade)) { $item = new grade_item($item, false); /// TODO: Take this out once grade_get_grades() returns proper data. } I think you get the idea, even if it has a typo in it (because it might). Also, to clarify further on the comment that had the workaround, I put that block in place at approximately line 819 of mod/certificate/lib.php

Dates

  • Created:
    Updated: