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

Award criteria for ALL cohort - WHERE clause broken

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.5.12, 3.6.10, 3.7.6, 3.8.3, 3.9, 3.10.1, 3.11, 4.0
    • Fix Version/s: 3.9.7, 3.10.4
    • Component/s: Badges
    • Labels:

      Description

      The code to award a badge when the criteria requires being a member of multiple cohorts is broken.

      It appears that the WHERE clause that's generated when seeing if a person is a member of ALL required cohorts doesn't work.

      In criteria/award_criteria_cohort line 247ish reads:

      $where = ' AND cm.cohortid = :cohortid'.$i;

      When I believe it meant to read:

      $where .= ' AND cm.cohortid = :cohortid'.$i;

      How it's written means that anyone who is a member of the last cohort would be returned.

      The second option would always return an empty set (unless I'm mistaken), because no row can meet the requirement of being in more than one cohort. I'm no SQL expert, so I could be dead wrong about this.

      A solution chould use a GROUP BY and HAVING:

         WHERE ... AND (cm.cohortid = :cohortid1 OR cm.cohortid = :cohortid2)
      GROUP BY u.id, bi.badgeid
         HAVING COUNT(cm.cohortid) = 2;

       

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              martygilbert Marty Gilbert
              Reporter:
              martygilbert Marty Gilbert
              Peer reviewer:
              Ilya Tregubov Ilya Tregubov
              Integrator:
              Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
              Tester:
              CiBoT CiBoT
              Participants:
              Component watchers:
              Yuliya Bozhko, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                10/May/21

                  Time Tracking

                  Estimated:
                  Original Estimate - 0 minutes
                  0m
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 4 hours, 50 minutes
                  4h 50m