Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

You have declared one of ouwiki_grade_item_update and ouwiki_update_grades but not both. This will cause broken behaviour. #82

Open
dsoini opened this issue Feb 4, 2019 · 1 comment

Comments

@dsoini
Copy link

dsoini commented Feb 4, 2019

Saw broken gradebook behavior in moodle 3.5 in a course. Steps to produce the broken behavior:

A course with multiple kinds of activities.

  1. Delete an Ouwiki activity.
  2. Note that gradebook displays a warning "Warning: Activity deletion in progress! Some grades are about to be removed. " and next to the item [Deletion in progress].
  3. Try to delete other types of activites. Notes that they, too, display [Deletion in progress'.
  4. Add the missing function (ouwiki_update_grades) to its lib.php.
  5. The broken gradebook behavior in the existing course does not go away, but if you start over with a duplicate of the course, the issue is not reproduced.
@dsoini
Copy link
Author

dsoini commented Feb 5, 2019

Hello, here is code we have used to fix the broken behavior described above.

`
/**

  • Update activity grades.

  • @param stdClass $ouwiki database record

  • @param int $userid specific user only, 0 means all

  • @param bool $nullifnone - not used
    */
    function ouwiki_update_grades($ouwiki, $userid=0, $nullifnone=true) {
    global $CFG;
    require_once($CFG->libdir.'/gradelib.php');

    if ($ouwiki->grade == 0) {
    ouwiki_grade_item_update($ouwiki);

    } else if ($grades = ouwiki_get_user_grades($ouwiki, $userid)) {
    foreach ($grades as $k => $v) {
    if ($v->rawgrade == -1) {
    $grades[$k]->rawgrade = null;
    }
    }
    ouwiki_grade_item_update($ouwiki, $grades);

    } else {
    ouwiki_grade_item_update($ouwiki);
    }
    }

/**

  • Return grade for given user or all users.

  • @global object

  • @global object

  • @param object $ouwiki

  • @param int $userid optional user id, 0 means all users

  • @return array array of grades, false if none
    */
    function ouwiki_get_user_grades($ouwiki, $userid = 0) {
    global $CFG;

    require_once($CFG->libdir.'/gradelib.php');

    $grading_info = grade_get_grades($ouwiki->course, 'mod', 'ouwiki', $ouwiki->id, $userid);

    $grade_item_grademax = $grading_info->items[0]->grademax;
    $user_final_grade = $grading_info->items[0]->grades[$userid];
    }
    `

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant