original_string: protected function sync_unenrol(stdClass $tool) {
          global $DB;
  
          $ltiplugin = enrol_get_plugin('lti');
  
          if (!$this->should_sync_unenrol($tool->membersyncmode)) {
              return 0;
          }
  
          if (empty($this->currentusers)) {
              return 0;
          }
  
          $unenrolcount = 0;
  
          $ltiusersrs = $DB->get_recordset('enrol_lti_users', array('toolid' => $tool->id), 'lastaccess DESC', 'userid');
          // Go through the users and check if any were never listed, if so, remove them.
          foreach ($ltiusersrs as $ltiuser) {
              if (!in_array($ltiuser->userid, $this->currentusers)) {
                  $instance = new stdClass();
                  $instance->id = $tool->enrolid;
                  $instance->courseid = $tool->courseid;
                  $instance->enrol = 'lti';
                  $ltiplugin->unenrol_user($instance, $ltiuser->userid);
                  // Increment unenrol count.
                  $unenrolcount++;
              }
          }
          $ltiusersrs->close();
  
          return $unenrolcount;
      }
code: protected function sync_unenrol(stdClass $tool) {
          global $DB;
  
          $ltiplugin = enrol_get_plugin('lti');
  
          if (!$this->should_sync_unenrol($tool->membersyncmode)) {
              return 0;
          }
  
          if (empty($this->currentusers)) {
              return 0;
          }
  
          $unenrolcount = 0;
  
          $ltiusersrs = $DB->get_recordset('enrol_lti_users', array('toolid' => $tool->id), 'lastaccess DESC', 'userid');
          // Go through the users and check if any were never listed, if so, remove them.
          foreach ($ltiusersrs as $ltiuser) {
              if (!in_array($ltiuser->userid, $this->currentusers)) {
                  $instance = new stdClass();
                  $instance->id = $tool->enrolid;
                  $instance->courseid = $tool->courseid;
                  $instance->enrol = 'lti';
                  $ltiplugin->unenrol_user($instance, $ltiuser->userid);
                  // Increment unenrol count.
                  $unenrolcount++;
              }
          }
          $ltiusersrs->close();
  
          return $unenrolcount;
      }
code_tokens: protected function sync_unenrol ( stdClass $ tool ) { global $ DB ; $ ltiplugin = enrol_get_plugin ( 'lti' ) ; if ( ! $ this -> should_sync_unenrol ( $ tool -> membersyncmode ) ) { return 0 ; } if ( empty ( $ this -> currentusers ) ) { return 0 ; } $ unenrolcount = 0 ; $ ltiusersrs = $ DB -> get_recordset ( 'enrol_lti_users' , array ( 'toolid' => $ tool -> id ) , 'lastaccess DESC' , 'userid' ) ; // Go through the users and check if any were never listed, if so, remove them. foreach ( $ ltiusersrs as $ ltiuser ) { if ( ! in_array ( $ ltiuser -> userid , $ this -> currentusers ) ) { $ instance = new stdClass ( ) ; $ instance -> id = $ tool -> enrolid ; $ instance -> courseid = $ tool -> courseid ; $ instance -> enrol = 'lti' ; $ ltiplugin -> unenrol_user ( $ instance , $ ltiuser -> userid ) ; // Increment unenrol count. $ unenrolcount ++ ; } } $ ltiusersrs -> close ( ) ; return $ unenrolcount ; }
docstring: Performs unenrolment of users that are no longer enrolled in the consumer side.
  
  @param stdClass $tool The tool record object.
  @return int The number of users that have been unenrolled.
docstring_tokens: Performs unenrolment of users that are no longer enrolled in the consumer side .