original_string: public static function course_module_criteria_review(\core\event\course_module_completion_updated $event) {
          global $DB, $CFG;
  
          if (!empty($CFG->enablebadges)) {
              require_once($CFG->dirroot.'/lib/badgeslib.php');
  
              $eventdata = $event->get_record_snapshot('course_modules_completion', $event->objectid);
              $userid = $event->relateduserid;
              $mod = $event->contextinstanceid;
  
              if ($eventdata->completionstate == COMPLETION_COMPLETE
                  || $eventdata->completionstate == COMPLETION_COMPLETE_PASS
                  || $eventdata->completionstate == COMPLETION_COMPLETE_FAIL) {
                  // Need to take into account that there can be more than one badge with the same activity in its criteria.
                  if ($rs = $DB->get_records('badge_criteria_param', array('name' => 'module_' . $mod, 'value' => $mod))) {
                      foreach ($rs as $r) {
                          $bid = $DB->get_field('badge_criteria', 'badgeid', array('id' => $r->critid), MUST_EXIST);
                          $badge = new badge($bid);
                          if (!$badge->is_active() || $badge->is_issued($userid)) {
                              continue;
                          }
  
                          if ($badge->criteria[BADGE_CRITERIA_TYPE_ACTIVITY]->review($userid)) {
                              $badge->criteria[BADGE_CRITERIA_TYPE_ACTIVITY]->mark_complete($userid);
  
                              if ($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->review($userid)) {
                                  $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->mark_complete($userid);
                                  $badge->issue($userid);
                              }
                          }
                      }
                  }
              }
          }
      }
code: public static function course_module_criteria_review(\core\event\course_module_completion_updated $event) {
          global $DB, $CFG;
  
          if (!empty($CFG->enablebadges)) {
              require_once($CFG->dirroot.'/lib/badgeslib.php');
  
              $eventdata = $event->get_record_snapshot('course_modules_completion', $event->objectid);
              $userid = $event->relateduserid;
              $mod = $event->contextinstanceid;
  
              if ($eventdata->completionstate == COMPLETION_COMPLETE
                  || $eventdata->completionstate == COMPLETION_COMPLETE_PASS
                  || $eventdata->completionstate == COMPLETION_COMPLETE_FAIL) {
                  // Need to take into account that there can be more than one badge with the same activity in its criteria.
                  if ($rs = $DB->get_records('badge_criteria_param', array('name' => 'module_' . $mod, 'value' => $mod))) {
                      foreach ($rs as $r) {
                          $bid = $DB->get_field('badge_criteria', 'badgeid', array('id' => $r->critid), MUST_EXIST);
                          $badge = new badge($bid);
                          if (!$badge->is_active() || $badge->is_issued($userid)) {
                              continue;
                          }
  
                          if ($badge->criteria[BADGE_CRITERIA_TYPE_ACTIVITY]->review($userid)) {
                              $badge->criteria[BADGE_CRITERIA_TYPE_ACTIVITY]->mark_complete($userid);
  
                              if ($badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->review($userid)) {
                                  $badge->criteria[BADGE_CRITERIA_TYPE_OVERALL]->mark_complete($userid);
                                  $badge->issue($userid);
                              }
                          }
                      }
                  }
              }
          }
      }
code_tokens: public static function course_module_criteria_review ( \ core \ event \ course_module_completion_updated $ event ) { global $ DB , $ CFG ; if ( ! empty ( $ CFG -> enablebadges ) ) { require_once ( $ CFG -> dirroot . '/lib/badgeslib.php' ) ; $ eventdata = $ event -> get_record_snapshot ( 'course_modules_completion' , $ event -> objectid ) ; $ userid = $ event -> relateduserid ; $ mod = $ event -> contextinstanceid ; if ( $ eventdata -> completionstate == COMPLETION_COMPLETE || $ eventdata -> completionstate == COMPLETION_COMPLETE_PASS || $ eventdata -> completionstate == COMPLETION_COMPLETE_FAIL ) { // Need to take into account that there can be more than one badge with the same activity in its criteria. if ( $ rs = $ DB -> get_records ( 'badge_criteria_param' , array ( 'name' => 'module_' . $ mod , 'value' => $ mod ) ) ) { foreach ( $ rs as $ r ) { $ bid = $ DB -> get_field ( 'badge_criteria' , 'badgeid' , array ( 'id' => $ r -> critid ) , MUST_EXIST ) ; $ badge = new badge ( $ bid ) ; if ( ! $ badge -> is_active ( ) || $ badge -> is_issued ( $ userid ) ) { continue ; } if ( $ badge -> criteria [ BADGE_CRITERIA_TYPE_ACTIVITY ] -> review ( $ userid ) ) { $ badge -> criteria [ BADGE_CRITERIA_TYPE_ACTIVITY ] -> mark_complete ( $ userid ) ; if ( $ badge -> criteria [ BADGE_CRITERIA_TYPE_OVERALL ] -> review ( $ userid ) ) { $ badge -> criteria [ BADGE_CRITERIA_TYPE_OVERALL ] -> mark_complete ( $ userid ) ; $ badge -> issue ( $ userid ) ; } } } } } } }
docstring: Triggered when 'course_module_completion_updated' event is triggered.
  
  @param \core\event\course_module_completion_updated $event
docstring_tokens: Triggered when course_module_completion_updated event is triggered .