original_string: public static function fields($tableprefix = '', array $extrafields = NULL, $idalias = 'id', $fieldprefix = '') {
          if (!$tableprefix and !$extrafields and !$idalias) {
              return implode(',', self::$fields);
          }
          if ($tableprefix) {
              $tableprefix .= '.';
          }
          foreach (self::$fields as $field) {
              if ($field === 'id' and $idalias and $idalias !== 'id') {
                  $fields[$field] = "$tableprefix$field AS $idalias";
              } else {
                  if ($fieldprefix and $field !== 'id') {
                      $fields[$field] = "$tableprefix$field AS $fieldprefix$field";
                  } else {
                      $fields[$field] = "$tableprefix$field";
                  }
              }
          }
          // add extra fields if not already there
          if ($extrafields) {
              foreach ($extrafields as $e) {
                  if ($e === 'id' or isset($fields[$e])) {
                      continue;
                  }
                  if ($fieldprefix) {
                      $fields[$e] = "$tableprefix$e AS $fieldprefix$e";
                  } else {
                      $fields[$e] = "$tableprefix$e";
                  }
              }
          }
          return implode(',', $fields);
      }
code: public static function fields($tableprefix = '', array $extrafields = NULL, $idalias = 'id', $fieldprefix = '') {
          if (!$tableprefix and !$extrafields and !$idalias) {
              return implode(',', self::$fields);
          }
          if ($tableprefix) {
              $tableprefix .= '.';
          }
          foreach (self::$fields as $field) {
              if ($field === 'id' and $idalias and $idalias !== 'id') {
                  $fields[$field] = "$tableprefix$field AS $idalias";
              } else {
                  if ($fieldprefix and $field !== 'id') {
                      $fields[$field] = "$tableprefix$field AS $fieldprefix$field";
                  } else {
                      $fields[$field] = "$tableprefix$field";
                  }
              }
          }
          // add extra fields if not already there
          if ($extrafields) {
              foreach ($extrafields as $e) {
                  if ($e === 'id' or isset($fields[$e])) {
                      continue;
                  }
                  if ($fieldprefix) {
                      $fields[$e] = "$tableprefix$e AS $fieldprefix$e";
                  } else {
                      $fields[$e] = "$tableprefix$e";
                  }
              }
          }
          return implode(',', $fields);
      }
code_tokens: public static function fields ( $ tableprefix = '' , array $ extrafields = NULL , $ idalias = 'id' , $ fieldprefix = '' ) { if ( ! $ tableprefix and ! $ extrafields and ! $ idalias ) { return implode ( ',' , self :: $ fields ) ; } if ( $ tableprefix ) { $ tableprefix .= '.' ; } foreach ( self :: $ fields as $ field ) { if ( $ field === 'id' and $ idalias and $ idalias !== 'id' ) { $ fields [ $ field ] = "$tableprefix$field AS $idalias" ; } else { if ( $ fieldprefix and $ field !== 'id' ) { $ fields [ $ field ] = "$tableprefix$field AS $fieldprefix$field" ; } else { $ fields [ $ field ] = "$tableprefix$field" ; } } } // add extra fields if not already there if ( $ extrafields ) { foreach ( $ extrafields as $ e ) { if ( $ e === 'id' or isset ( $ fields [ $ e ] ) ) { continue ; } if ( $ fieldprefix ) { $ fields [ $ e ] = "$tableprefix$e AS $fieldprefix$e" ; } else { $ fields [ $ e ] = "$tableprefix$e" ; } } } return implode ( ',' , $ fields ) ; }
docstring: Returns a list of required user fields, useful when fetching required user info from db.
  
  In some cases we have to fetch the user data together with some other information,
  the idalias is useful there because the id would otherwise override the main
  id of the result record. Please note it has to be converted back to id before rendering.
  
  @param string $tableprefix name of database table prefix in query
  @param array $extrafields extra fields to be included in result (do not include TEXT columns because it would break SELECT DISTINCT in MSSQL and ORACLE)
  @param string $idalias alias of id field
  @param string $fieldprefix prefix to add to all columns in their aliases, does not apply to 'id'
  @return string
docstring_tokens: Returns a list of required user fields useful when fetching required user info from db .