Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-29501

Conditional activities that are not available still show as links in gradebook

    Details

    • Testing Instructions:
      Hide

      0. Ensure conditional availability and completion are enabled at site level and for a test course.
      1. On the test course, create a Page activity set so that user can manually mark complete.
      2. Create a Quiz activity set so that it is only available when the Page activity has been completed.
      3. Enrol a test account as a Student on the test course.
      4. Log in as the student.
      5. Go to the course and click on Grades to see the gradebook.

      • Note that the grade for the test quiz (currently no grade) is displayed.
      • The test quiz should not be a link as it is not available yet.
        6. Return to the main page. Click on the tick box to mark the Page as completed. The quiz on main page should now turn into a link.
        7. Go to gradebook again
      • The test quiz should now be a link.
      Show
      0. Ensure conditional availability and completion are enabled at site level and for a test course. 1. On the test course, create a Page activity set so that user can manually mark complete. 2. Create a Quiz activity set so that it is only available when the Page activity has been completed. 3. Enrol a test account as a Student on the test course. 4. Log in as the student. 5. Go to the course and click on Grades to see the gradebook. Note that the grade for the test quiz (currently no grade) is displayed. The test quiz should not be a link as it is not available yet. 6. Return to the main page. Click on the tick box to mark the Page as completed. The quiz on main page should now turn into a link. 7. Go to gradebook again The test quiz should now be a link.
    • Affected Branches:
      MOODLE_20_STABLE, MOODLE_21_STABLE
    • Fixed Branches:
      MOODLE_21_STABLE
    • Pull Master Branch:
      MDL-29501-master

      Description

      A student can not perform an activity because it is conditioned can be accessed through the gradebook.

      In addition, once the activity is accessed an error and return to home page and not to course view page.

        Gliffy Diagrams

          Attachments

          1. courseview.PNG
            courseview.PNG
            31 kB
          2. gradeview.PNG
            gradeview.PNG
            21 kB
          3. quizview.PNG
            quizview.PNG
            23 kB
          4. screenshot-1.jpg
            screenshot-1.jpg
            18 kB
          5. screenshot-2.jpg
            screenshot-2.jpg
            23 kB
          6. screenshot-3.jpg
            screenshot-3.jpg
            5 kB

            Issue Links

              Activity

              Hide
              salvetore Michael de Raadt added a comment -

              Hi, Carlos.

              I'm having trouble understanding exactly what problem you are describing. Could you add some screenshots and possibly more explanation using other words.

              Show
              salvetore Michael de Raadt added a comment - Hi, Carlos. I'm having trouble understanding exactly what problem you are describing. Could you add some screenshots and possibly more explanation using other words.
              Hide
              cescobedo Carlos Escobedo Orea added a comment -

              Hi Michael,

              I attach two captures. The first, is the course view for a student in there you can see in the topic two the quiz (Quiz conditioned by assignment I) with no link. Perfect. But in the second capture, on the gradebook, you can see the quiz with link and the student can try to access it. When this happen, you can see the third capture the error message thats redirects to the home page.

              Show
              cescobedo Carlos Escobedo Orea added a comment - Hi Michael, I attach two captures. The first, is the course view for a student in there you can see in the topic two the quiz (Quiz conditioned by assignment I) with no link. Perfect. But in the second capture, on the gradebook, you can see the quiz with link and the student can try to access it. When this happen, you can see the third capture the error message thats redirects to the home page.
              Hide
              cescobedo Carlos Escobedo Orea added a comment -

              Topic two, quiz conditioned with no link. OK.

              Show
              cescobedo Carlos Escobedo Orea added a comment - Topic two, quiz conditioned with no link. OK.
              Hide
              cescobedo Carlos Escobedo Orea added a comment -

              Gradebook student, the quiz conditioned with link when the student didn't pass the condition.

              Show
              cescobedo Carlos Escobedo Orea added a comment - Gradebook student, the quiz conditioned with link when the student didn't pass the condition.
              Hide
              cescobedo Carlos Escobedo Orea added a comment -

              The error message when the studen go to quiz from gradebook and after that the student isr edirected to the home rather than the course.

              Show
              cescobedo Carlos Escobedo Orea added a comment - The error message when the studen go to quiz from gradebook and after that the student isr edirected to the home rather than the course.
              Hide
              cescobedo Carlos Escobedo Orea added a comment -

              Meanwhile, we have modified this file grader/lib.php on functionget_element_header function adding the following lines in the code:
              $course = $DB->get_record('course', array('id' => $this->courseid));
              $modinfo = get_fast_modinfo($course);
              $cm = $modinfo->get_cm($cm->id);
              if ($cm->uservisible)

              { //original code to create a link }

              Also, we have modified in the file lib/moodlelib.php on function require_login at the end:
              if ($cm && !$cm->uservisible) {
              if ($preventredirect)

              { throw new require_login_exception('Activity is hidden'); }

              //add to redirecto to course
              if ($course)

              { redirect($CFG->wwwroot.'/course/view.php?id='.$course->id, get_string('activityiscurrentlyhidden')); }

              else

              { redirect($CFG->wwwroot, get_string('activityiscurrentlyhidden')); }

              }

              Show
              cescobedo Carlos Escobedo Orea added a comment - Meanwhile, we have modified this file grader/lib.php on functionget_element_header function adding the following lines in the code: $course = $DB->get_record('course', array('id' => $this->courseid)); $modinfo = get_fast_modinfo($course); $cm = $modinfo->get_cm($cm->id); if ($cm->uservisible) { //original code to create a link } Also, we have modified in the file lib/moodlelib.php on function require_login at the end: if ($cm && !$cm->uservisible) { if ($preventredirect) { throw new require_login_exception('Activity is hidden'); } //add to redirecto to course if ($course) { redirect($CFG->wwwroot.'/course/view.php?id='.$course->id, get_string('activityiscurrentlyhidden')); } else { redirect($CFG->wwwroot, get_string('activityiscurrentlyhidden')); } }
              Hide
              quen Sam Marshall added a comment -

              Thanks Carlos. I understand the issue and have changed subject to reflect it. Hopefully I will get a chance to actually fix it soon...

              Show
              quen Sam Marshall added a comment - Thanks Carlos. I understand the issue and have changed subject to reflect it. Hopefully I will get a chance to actually fix it soon...
              Hide
              quen Sam Marshall added a comment -

              I have updated the testing instructions to give a more specific test (which I've just done - obviously, it currently fails).

              Show
              quen Sam Marshall added a comment - I have updated the testing instructions to give a more specific test (which I've just done - obviously, it currently fails).
              Hide
              quen Sam Marshall added a comment -

              The suggested fix was not very efficient - I guess this was only intended as temporary patch. I created a new fix that works as follows:

              • When constructing a grade_tree, it calls get_fast_modinfo for the course. (This can result in either 1 or 2 extra db queries.)
              • When displaying each item, it uses the $cm from get_fast_modinfo. (This requires 0 db queries.)
              • It checks ->uservisible as per your fix.

              As a result, on my test course with 5 quizzes, it used to take 80 queries to show the page and now takes 76. Basically, it costs 1 extra query but then saves 1 query per activity grade, so should scale better.

              Following suggestions from Tim I refactored the code slightly (only the function I was changing anyway) because he's right, it was pretty hard to follow before. The new version with a separate function is simpler.

              I did the fix for master and cherry-picked to 2.1, however not sure this is important enough to include in 2.1 branch, that's up to somebody else.

              Show
              quen Sam Marshall added a comment - The suggested fix was not very efficient - I guess this was only intended as temporary patch. I created a new fix that works as follows: When constructing a grade_tree, it calls get_fast_modinfo for the course. (This can result in either 1 or 2 extra db queries.) When displaying each item, it uses the $cm from get_fast_modinfo. (This requires 0 db queries.) It checks ->uservisible as per your fix. As a result, on my test course with 5 quizzes, it used to take 80 queries to show the page and now takes 76. Basically, it costs 1 extra query but then saves 1 query per activity grade, so should scale better. Following suggestions from Tim I refactored the code slightly (only the function I was changing anyway) because he's right, it was pretty hard to follow before. The new version with a separate function is simpler. I did the fix for master and cherry-picked to 2.1, however not sure this is important enough to include in 2.1 branch, that's up to somebody else.
              Hide
              stronk7 Eloy Lafuente (stronk7) added a comment -

              The main moodle.git repository has just been updated with latest weekly modifications. You may wish to rebase your PULL branches to simplify history and avoid any possible merge conflicts. This would also make integrator's life easier next week.

              TIA and ciao

              Show
              stronk7 Eloy Lafuente (stronk7) added a comment - The main moodle.git repository has just been updated with latest weekly modifications. You may wish to rebase your PULL branches to simplify history and avoid any possible merge conflicts. This would also make integrator's life easier next week. TIA and ciao
              Hide
              quen Sam Marshall added a comment -

              Rebased, new version pushed

              Show
              quen Sam Marshall added a comment - Rebased, new version pushed
              Hide
              cescobedo Carlos Escobedo Orea added a comment -

              Thanks a lot Sam and Eloy.

              Show
              cescobedo Carlos Escobedo Orea added a comment - Thanks a lot Sam and Eloy.
              Hide
              samhemelryk Sam Hemelryk added a comment -

              Thanks Sam - this has been integrated now

              Show
              samhemelryk Sam Hemelryk added a comment - Thanks Sam - this has been integrated now
              Hide
              ankit_frenz Ankit Agarwal added a comment - - edited

              Hi,
              Sorry but doesn't work for me.
              Even if the required condition is met, the quiz is not converted to a link and stays hidden.
              Attaching screens.
              Edit: - Just realized link became active once the student user is logged out and than logs back in.
              Waiting for Sam to have a re-look into this.
              Thanks

              Show
              ankit_frenz Ankit Agarwal added a comment - - edited Hi, Sorry but doesn't work for me. Even if the required condition is met, the quiz is not converted to a link and stays hidden. Attaching screens. Edit: - Just realized link became active once the student user is logged out and than logs back in. Waiting for Sam to have a re-look into this. Thanks
              Hide
              quen Sam Marshall added a comment -

              Hi Ankit,

              This is a general problem with conditional activity information; it is cached in user session meaning that any change that is not made by the user themself is delayed.

              E.g. if you (a student) get a grade in the quiz, that takes effect immediately because it happened as a result of your actions. But if a teacher edits your grade in the quiz, that doesn't take effect until your next login (or maybe also some delay, not sure).

              Normally this is not too bad because in most cases it doesn't mean you get access to something you shouldn't, instead you don't get access to something you should until a little later.

              We ought to do something about it but I'm not sure of the best approach - I think it would be good to handle this at a wider level than conditional activities. (I am happy to develop it for conditional activities if required but that will cause a slight performance drop, one extra query for pretty much every page.)

              MDL-28463

              Show
              quen Sam Marshall added a comment - Hi Ankit, This is a general problem with conditional activity information; it is cached in user session meaning that any change that is not made by the user themself is delayed. E.g. if you (a student) get a grade in the quiz, that takes effect immediately because it happened as a result of your actions. But if a teacher edits your grade in the quiz, that doesn't take effect until your next login (or maybe also some delay, not sure). Normally this is not too bad because in most cases it doesn't mean you get access to something you shouldn't, instead you don't get access to something you should until a little later. We ought to do something about it but I'm not sure of the best approach - I think it would be good to handle this at a wider level than conditional activities. (I am happy to develop it for conditional activities if required but that will cause a slight performance drop, one extra query for pretty much every page.) MDL-28463
              Hide
              stronk7 Eloy Lafuente (stronk7) added a comment -

              restarted testing phase...

              Show
              stronk7 Eloy Lafuente (stronk7) added a comment - restarted testing phase...
              Hide
              ankit_frenz Ankit Agarwal added a comment -

              Beside the issue that will be fixed by MDL-28463, Everything else works like a charm!
              Test passed.
              Thanks

              Show
              ankit_frenz Ankit Agarwal added a comment - Beside the issue that will be fixed by MDL-28463 , Everything else works like a charm! Test passed. Thanks
              Hide
              stronk7 Eloy Lafuente (stronk7) added a comment -

              Many thanks for all the hard work. This is now part of Moodle, your favorite LMS.

              Closing as fixed, ciao

              Show
              stronk7 Eloy Lafuente (stronk7) added a comment - Many thanks for all the hard work. This is now part of Moodle, your favorite LMS. Closing as fixed, ciao

                People

                • Votes:
                  1 Vote for this issue
                  Watchers:
                  3 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Fix Release Date:
                    28/Nov/11