original_string: public static function observe_course_module_completion_updated(\core\event\course_module_completion_updated $event) {
          if (!static::is_enabled()) {
              return;
          }
  
          $eventdata = $event->get_record_snapshot('course_modules_completion', $event->objectid);
  
          if ($eventdata->completionstate == COMPLETION_COMPLETE
                  || $eventdata->completionstate == COMPLETION_COMPLETE_PASS) {
              $coursemodulecompetencies = course_module_competency::list_course_module_competencies($eventdata->coursemoduleid);
  
              $cm = get_coursemodule_from_id(null, $eventdata->coursemoduleid);
              $fastmodinfo = get_fast_modinfo($cm->course)->cms[$cm->id];
  
              $cmname = $fastmodinfo->name;
              $url = $fastmodinfo->url;
  
              foreach ($coursemodulecompetencies as $coursemodulecompetency) {
                  $outcome = $coursemodulecompetency->get('ruleoutcome');
                  $action = null;
                  $recommend = false;
                  $strdesc = 'evidence_coursemodulecompleted';
  
                  if ($outcome == course_module_competency::OUTCOME_EVIDENCE) {
                      $action = evidence::ACTION_LOG;
  
                  } else if ($outcome == course_module_competency::OUTCOME_RECOMMEND) {
                      $action = evidence::ACTION_LOG;
                      $recommend = true;
  
                  } else if ($outcome == course_module_competency::OUTCOME_COMPLETE) {
                      $action = evidence::ACTION_COMPLETE;
  
                  } else {
                      throw new moodle_exception('Unexpected rule outcome: ' + $outcome);
                  }
  
                  static::add_evidence(
                      $event->relateduserid,
                      $coursemodulecompetency->get('competencyid'),
                      $event->contextid,
                      $action,
                      $strdesc,
                      'core_competency',
                      $cmname,
                      $recommend,
                      $url
                  );
              }
          }
      }
code: public static function observe_course_module_completion_updated(\core\event\course_module_completion_updated $event) {
          if (!static::is_enabled()) {
              return;
          }
  
          $eventdata = $event->get_record_snapshot('course_modules_completion', $event->objectid);
  
          if ($eventdata->completionstate == COMPLETION_COMPLETE
                  || $eventdata->completionstate == COMPLETION_COMPLETE_PASS) {
              $coursemodulecompetencies = course_module_competency::list_course_module_competencies($eventdata->coursemoduleid);
  
              $cm = get_coursemodule_from_id(null, $eventdata->coursemoduleid);
              $fastmodinfo = get_fast_modinfo($cm->course)->cms[$cm->id];
  
              $cmname = $fastmodinfo->name;
              $url = $fastmodinfo->url;
  
              foreach ($coursemodulecompetencies as $coursemodulecompetency) {
                  $outcome = $coursemodulecompetency->get('ruleoutcome');
                  $action = null;
                  $recommend = false;
                  $strdesc = 'evidence_coursemodulecompleted';
  
                  if ($outcome == course_module_competency::OUTCOME_EVIDENCE) {
                      $action = evidence::ACTION_LOG;
  
                  } else if ($outcome == course_module_competency::OUTCOME_RECOMMEND) {
                      $action = evidence::ACTION_LOG;
                      $recommend = true;
  
                  } else if ($outcome == course_module_competency::OUTCOME_COMPLETE) {
                      $action = evidence::ACTION_COMPLETE;
  
                  } else {
                      throw new moodle_exception('Unexpected rule outcome: ' + $outcome);
                  }
  
                  static::add_evidence(
                      $event->relateduserid,
                      $coursemodulecompetency->get('competencyid'),
                      $event->contextid,
                      $action,
                      $strdesc,
                      'core_competency',
                      $cmname,
                      $recommend,
                      $url
                  );
              }
          }
      }
code_tokens: public static function observe_course_module_completion_updated ( \ core \ event \ course_module_completion_updated $ event ) { if ( ! static :: is_enabled ( ) ) { return ; } $ eventdata = $ event -> get_record_snapshot ( 'course_modules_completion' , $ event -> objectid ) ; if ( $ eventdata -> completionstate == COMPLETION_COMPLETE || $ eventdata -> completionstate == COMPLETION_COMPLETE_PASS ) { $ coursemodulecompetencies = course_module_competency :: list_course_module_competencies ( $ eventdata -> coursemoduleid ) ; $ cm = get_coursemodule_from_id ( null , $ eventdata -> coursemoduleid ) ; $ fastmodinfo = get_fast_modinfo ( $ cm -> course ) -> cms [ $ cm -> id ] ; $ cmname = $ fastmodinfo -> name ; $ url = $ fastmodinfo -> url ; foreach ( $ coursemodulecompetencies as $ coursemodulecompetency ) { $ outcome = $ coursemodulecompetency -> get ( 'ruleoutcome' ) ; $ action = null ; $ recommend = false ; $ strdesc = 'evidence_coursemodulecompleted' ; if ( $ outcome == course_module_competency :: OUTCOME_EVIDENCE ) { $ action = evidence :: ACTION_LOG ; } else if ( $ outcome == course_module_competency :: OUTCOME_RECOMMEND ) { $ action = evidence :: ACTION_LOG ; $ recommend = true ; } else if ( $ outcome == course_module_competency :: OUTCOME_COMPLETE ) { $ action = evidence :: ACTION_COMPLETE ; } else { throw new moodle_exception ( 'Unexpected rule outcome: ' + $ outcome ) ; } static :: add_evidence ( $ event -> relateduserid , $ coursemodulecompetency -> get ( 'competencyid' ) , $ event -> contextid , $ action , $ strdesc , 'core_competency' , $ cmname , $ recommend , $ url ) ; } } }
docstring: Observe when a course module is marked as completed.
  
  Note that the user being logged in while this happens may be anyone.
  Do not rely on capability checks here!
  
  @param  \core\event\course_module_completion_updated $event
  @return void
docstring_tokens: Observe when a course module is marked as completed .