original_string: public function get_users_enrolments(array $userids) {
          global $DB;
  
          $instances = $this->get_enrolment_instances();
          $plugins = $this->get_enrolment_plugins(false);
  
          if  (!empty($this->instancefilter)) {
              $instancesql = ' = :instanceid';
              $instanceparams = array('instanceid' => $this->instancefilter);
          } else {
              list($instancesql, $instanceparams) = $DB->get_in_or_equal(array_keys($instances), SQL_PARAMS_NAMED, 'instanceid0000');
          }
  
          $userfields = user_picture::fields('u');
          list($idsql, $idparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED, 'userid0000');
  
          list($sort, $sortparams) = users_order_by_sql('u');
  
          $sql = "SELECT ue.id AS ueid, ue.status, ue.enrolid, ue.userid, ue.timestart, ue.timeend, ue.modifierid, ue.timecreated, ue.timemodified, $userfields
                    FROM {user_enrolments} ue
               LEFT JOIN {user} u ON u.id = ue.userid
                   WHERE ue.enrolid $instancesql AND
                         u.id $idsql
                ORDER BY $sort";
  
          $rs = $DB->get_recordset_sql($sql, $idparams + $instanceparams + $sortparams);
          $users = array();
          foreach ($rs as $ue) {
              $user = user_picture::unalias($ue);
              $ue->id = $ue->ueid;
              unset($ue->ueid);
              if (!array_key_exists($user->id, $users)) {
                  $user->enrolments = array();
                  $users[$user->id] = $user;
              }
              $ue->enrolmentinstance = $instances[$ue->enrolid];
              $ue->enrolmentplugin = $plugins[$ue->enrolmentinstance->enrol];
              $users[$user->id]->enrolments[$ue->id] = $ue;
          }
          $rs->close();
          return $users;
      }
code: public function get_users_enrolments(array $userids) {
          global $DB;
  
          $instances = $this->get_enrolment_instances();
          $plugins = $this->get_enrolment_plugins(false);
  
          if  (!empty($this->instancefilter)) {
              $instancesql = ' = :instanceid';
              $instanceparams = array('instanceid' => $this->instancefilter);
          } else {
              list($instancesql, $instanceparams) = $DB->get_in_or_equal(array_keys($instances), SQL_PARAMS_NAMED, 'instanceid0000');
          }
  
          $userfields = user_picture::fields('u');
          list($idsql, $idparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED, 'userid0000');
  
          list($sort, $sortparams) = users_order_by_sql('u');
  
          $sql = "SELECT ue.id AS ueid, ue.status, ue.enrolid, ue.userid, ue.timestart, ue.timeend, ue.modifierid, ue.timecreated, ue.timemodified, $userfields
                    FROM {user_enrolments} ue
               LEFT JOIN {user} u ON u.id = ue.userid
                   WHERE ue.enrolid $instancesql AND
                         u.id $idsql
                ORDER BY $sort";
  
          $rs = $DB->get_recordset_sql($sql, $idparams + $instanceparams + $sortparams);
          $users = array();
          foreach ($rs as $ue) {
              $user = user_picture::unalias($ue);
              $ue->id = $ue->ueid;
              unset($ue->ueid);
              if (!array_key_exists($user->id, $users)) {
                  $user->enrolments = array();
                  $users[$user->id] = $user;
              }
              $ue->enrolmentinstance = $instances[$ue->enrolid];
              $ue->enrolmentplugin = $plugins[$ue->enrolmentinstance->enrol];
              $users[$user->id]->enrolments[$ue->id] = $ue;
          }
          $rs->close();
          return $users;
      }
code_tokens: public function get_users_enrolments ( array $ userids ) { global $ DB ; $ instances = $ this -> get_enrolment_instances ( ) ; $ plugins = $ this -> get_enrolment_plugins ( false ) ; if ( ! empty ( $ this -> instancefilter ) ) { $ instancesql = ' = :instanceid' ; $ instanceparams = array ( 'instanceid' => $ this -> instancefilter ) ; } else { list ( $ instancesql , $ instanceparams ) = $ DB -> get_in_or_equal ( array_keys ( $ instances ) , SQL_PARAMS_NAMED , 'instanceid0000' ) ; } $ userfields = user_picture :: fields ( 'u' ) ; list ( $ idsql , $ idparams ) = $ DB -> get_in_or_equal ( $ userids , SQL_PARAMS_NAMED , 'userid0000' ) ; list ( $ sort , $ sortparams ) = users_order_by_sql ( 'u' ) ; $ sql = "SELECT ue.id AS ueid, ue.status, ue.enrolid, ue.userid, ue.timestart, ue.timeend, ue.modifierid, ue.timecreated, ue.timemodified, $userfields
                    FROM {user_enrolments} ue
               LEFT JOIN {user} u ON u.id = ue.userid
                   WHERE ue.enrolid $instancesql AND
                         u.id $idsql
                ORDER BY $sort" ; $ rs = $ DB -> get_recordset_sql ( $ sql , $ idparams + $ instanceparams + $ sortparams ) ; $ users = array ( ) ; foreach ( $ rs as $ ue ) { $ user = user_picture :: unalias ( $ ue ) ; $ ue -> id = $ ue -> ueid ; unset ( $ ue -> ueid ) ; if ( ! array_key_exists ( $ user -> id , $ users ) ) { $ user -> enrolments = array ( ) ; $ users [ $ user -> id ] = $ user ; } $ ue -> enrolmentinstance = $ instances [ $ ue -> enrolid ] ; $ ue -> enrolmentplugin = $ plugins [ $ ue -> enrolmentinstance -> enrol ] ; $ users [ $ user -> id ] -> enrolments [ $ ue -> id ] = $ ue ; } $ rs -> close ( ) ; return $ users ; }
docstring: Returns and array of users + enrolment details.
  
  Given an array of user id's this function returns and array of user enrolments for those users
  as well as enough user information to display the users name and picture for each enrolment.
  
  @global moodle_database $DB
  @param array $userids
  @return array
docstring_tokens: Returns and array of users + enrolment details .