original_string: public static function user_enrolment_changed($courseid, $userid,
              $status, $timestart = null, $timeend = null) {
          $cache = cache::make('core', 'coursecontacts');
          $contacts = $cache->get($courseid);
          if ($contacts === false) {
              // The contacts for the affected course were not cached anyway.
              return;
          }
          $enrolmentactive = ($status == 0) &&
                  (!$timestart || $timestart < time()) &&
                  (!$timeend || $timeend > time());
          if (!$enrolmentactive) {
              $isincontacts = false;
              foreach ($contacts as $contact) {
                  if ($contact->id == $userid) {
                      $isincontacts = true;
                  }
              }
              if (!$isincontacts) {
                  // Changed user's enrolment does not exist or is not active,
                  // and he is not in cached course contacts, no changes to be made.
                  return;
              }
          }
          // Either enrolment of manager was deleted/suspended
          // or user enrolment was added or activated.
          // In order to see if the course contacts for this course need
          // changing we would need to make additional queries, they will
          // slow down bulk enrolment changes. It is better just to remove
          // course contacts cache for this course.
          $cache->delete($courseid);
      }
code: public static function user_enrolment_changed($courseid, $userid,
              $status, $timestart = null, $timeend = null) {
          $cache = cache::make('core', 'coursecontacts');
          $contacts = $cache->get($courseid);
          if ($contacts === false) {
              // The contacts for the affected course were not cached anyway.
              return;
          }
          $enrolmentactive = ($status == 0) &&
                  (!$timestart || $timestart < time()) &&
                  (!$timeend || $timeend > time());
          if (!$enrolmentactive) {
              $isincontacts = false;
              foreach ($contacts as $contact) {
                  if ($contact->id == $userid) {
                      $isincontacts = true;
                  }
              }
              if (!$isincontacts) {
                  // Changed user's enrolment does not exist or is not active,
                  // and he is not in cached course contacts, no changes to be made.
                  return;
              }
          }
          // Either enrolment of manager was deleted/suspended
          // or user enrolment was added or activated.
          // In order to see if the course contacts for this course need
          // changing we would need to make additional queries, they will
          // slow down bulk enrolment changes. It is better just to remove
          // course contacts cache for this course.
          $cache->delete($courseid);
      }
code_tokens: public static function user_enrolment_changed ( $ courseid , $ userid , $ status , $ timestart = null , $ timeend = null ) { $ cache = cache :: make ( 'core' , 'coursecontacts' ) ; $ contacts = $ cache -> get ( $ courseid ) ; if ( $ contacts === false ) { // The contacts for the affected course were not cached anyway. return ; } $ enrolmentactive = ( $ status == 0 ) && ( ! $ timestart || $ timestart < time ( ) ) && ( ! $ timeend || $ timeend > time ( ) ) ; if ( ! $ enrolmentactive ) { $ isincontacts = false ; foreach ( $ contacts as $ contact ) { if ( $ contact -> id == $ userid ) { $ isincontacts = true ; } } if ( ! $ isincontacts ) { // Changed user's enrolment does not exist or is not active, // and he is not in cached course contacts, no changes to be made. return ; } } // Either enrolment of manager was deleted/suspended // or user enrolment was added or activated. // In order to see if the course contacts for this course need // changing we would need to make additional queries, they will // slow down bulk enrolment changes. It is better just to remove // course contacts cache for this course. $ cache -> delete ( $ courseid ) ; }
docstring: Executed when user enrolment was changed to check if course
  contacts cache needs to be cleared
  
  @param int $courseid course id
  @param int $userid user id
  @param int $status new enrolment status (0 - active, 1 - suspended)
  @param int $timestart new enrolment time start
  @param int $timeend new enrolment time end
docstring_tokens: Executed when user enrolment was changed to check if course contacts cache needs to be cleared