original_string: protected function get_users_with_capability_sql($capability, $musthavesubmission, $groupid) {
          global $CFG;
          /** @var int static counter used to generate unique parameter holders */
          static $inc = 0;
          $inc++;
  
          // If the caller requests all groups and we are using a selected grouping,
          // recursively call this function for each group in the grouping (this is
          // needed because get_enrolled_sql only supports a single group).
          if (empty($groupid) and $this->cm->groupingid) {
              $groupingid = $this->cm->groupingid;
              $groupinggroupids = array_keys(groups_get_all_groups($this->cm->course, 0, $this->cm->groupingid, 'g.id'));
              $sql = array();
              $params = array();
              foreach ($groupinggroupids as $groupinggroupid) {
                  if ($groupinggroupid > 0) { // just in case in order not to fall into the endless loop
                      list($gsql, $gparams) = $this->get_users_with_capability_sql($capability, $musthavesubmission, $groupinggroupid);
                      $sql[] = $gsql;
                      $params = array_merge($params, $gparams);
                  }
              }
              $sql = implode(PHP_EOL." UNION ".PHP_EOL, $sql);
              return array($sql, $params);
          }
  
          list($esql, $params) = get_enrolled_sql($this->context, $capability, $groupid, true);
  
          $userfields = user_picture::fields('u');
  
          $sql = "SELECT $userfields
                    FROM {user} u
                    JOIN ($esql) je ON (je.id = u.id AND u.deleted = 0) ";
  
          if ($musthavesubmission) {
              $sql .= " JOIN {workshop_submissions} ws ON (ws.authorid = u.id AND ws.example = 0 AND ws.workshopid = :workshopid{$inc}) ";
              $params['workshopid'.$inc] = $this->id;
          }
  
          // If the activity is restricted so that only certain users should appear
          // in user lists, integrate this into the same SQL.
          $info = new \core_availability\info_module($this->cm);
          list ($listsql, $listparams) = $info->get_user_list_sql(false);
          if ($listsql) {
              $sql .= " JOIN ($listsql) restricted ON restricted.id = u.id ";
              $params = array_merge($params, $listparams);
          }
  
          return array($sql, $params);
      }
code: protected function get_users_with_capability_sql($capability, $musthavesubmission, $groupid) {
          global $CFG;
          /** @var int static counter used to generate unique parameter holders */
          static $inc = 0;
          $inc++;
  
          // If the caller requests all groups and we are using a selected grouping,
          // recursively call this function for each group in the grouping (this is
          // needed because get_enrolled_sql only supports a single group).
          if (empty($groupid) and $this->cm->groupingid) {
              $groupingid = $this->cm->groupingid;
              $groupinggroupids = array_keys(groups_get_all_groups($this->cm->course, 0, $this->cm->groupingid, 'g.id'));
              $sql = array();
              $params = array();
              foreach ($groupinggroupids as $groupinggroupid) {
                  if ($groupinggroupid > 0) { // just in case in order not to fall into the endless loop
                      list($gsql, $gparams) = $this->get_users_with_capability_sql($capability, $musthavesubmission, $groupinggroupid);
                      $sql[] = $gsql;
                      $params = array_merge($params, $gparams);
                  }
              }
              $sql = implode(PHP_EOL." UNION ".PHP_EOL, $sql);
              return array($sql, $params);
          }
  
          list($esql, $params) = get_enrolled_sql($this->context, $capability, $groupid, true);
  
          $userfields = user_picture::fields('u');
  
          $sql = "SELECT $userfields
                    FROM {user} u
                    JOIN ($esql) je ON (je.id = u.id AND u.deleted = 0) ";
  
          if ($musthavesubmission) {
              $sql .= " JOIN {workshop_submissions} ws ON (ws.authorid = u.id AND ws.example = 0 AND ws.workshopid = :workshopid{$inc}) ";
              $params['workshopid'.$inc] = $this->id;
          }
  
          // If the activity is restricted so that only certain users should appear
          // in user lists, integrate this into the same SQL.
          $info = new \core_availability\info_module($this->cm);
          list ($listsql, $listparams) = $info->get_user_list_sql(false);
          if ($listsql) {
              $sql .= " JOIN ($listsql) restricted ON restricted.id = u.id ";
              $params = array_merge($params, $listparams);
          }
  
          return array($sql, $params);
      }
code_tokens: protected function get_users_with_capability_sql ( $ capability , $ musthavesubmission , $ groupid ) { global $ CFG ; /** @var int static counter used to generate unique parameter holders */ static $ inc = 0 ; $ inc ++ ; // If the caller requests all groups and we are using a selected grouping, // recursively call this function for each group in the grouping (this is // needed because get_enrolled_sql only supports a single group). if ( empty ( $ groupid ) and $ this -> cm -> groupingid ) { $ groupingid = $ this -> cm -> groupingid ; $ groupinggroupids = array_keys ( groups_get_all_groups ( $ this -> cm -> course , 0 , $ this -> cm -> groupingid , 'g.id' ) ) ; $ sql = array ( ) ; $ params = array ( ) ; foreach ( $ groupinggroupids as $ groupinggroupid ) { if ( $ groupinggroupid > 0 ) { // just in case in order not to fall into the endless loop list ( $ gsql , $ gparams ) = $ this -> get_users_with_capability_sql ( $ capability , $ musthavesubmission , $ groupinggroupid ) ; $ sql [ ] = $ gsql ; $ params = array_merge ( $ params , $ gparams ) ; } } $ sql = implode ( PHP_EOL . " UNION " . PHP_EOL , $ sql ) ; return array ( $ sql , $ params ) ; } list ( $ esql , $ params ) = get_enrolled_sql ( $ this -> context , $ capability , $ groupid , true ) ; $ userfields = user_picture :: fields ( 'u' ) ; $ sql = "SELECT $userfields
                    FROM {user} u
                    JOIN ($esql) je ON (je.id = u.id AND u.deleted = 0) " ; if ( $ musthavesubmission ) { $ sql .= " JOIN {workshop_submissions} ws ON (ws.authorid = u.id AND ws.example = 0 AND ws.workshopid = :workshopid{$inc}) " ; $ params [ 'workshopid' . $ inc ] = $ this -> id ; } // If the activity is restricted so that only certain users should appear // in user lists, integrate this into the same SQL. $ info = new \ core_availability \ info_module ( $ this -> cm ) ; list ( $ listsql , $ listparams ) = $ info -> get_user_list_sql ( false ) ; if ( $ listsql ) { $ sql .= " JOIN ($listsql) restricted ON restricted.id = u.id " ; $ params = array_merge ( $ params , $ listparams ) ; } return array ( $ sql , $ params ) ; }
docstring: Returns SQL to fetch all enrolled users with the given capability in the current workshop
  
  The returned array consists of string $sql and the $params array. Note that the $sql can be
  empty if a grouping is selected and it has no groups.
  
  The list is automatically restricted according to any availability restrictions
  that apply to user lists (e.g. group, grouping restrictions).
  
  @param string $capability the name of the capability
  @param bool $musthavesubmission ff true, return only users who have already submitted
  @param int $groupid 0 means ignore groups, any other value limits the result by group id
  @return array of (string)sql, (array)params
docstring_tokens: Returns SQL to fetch all enrolled users with the given capability in the current workshop