original_string: protected function get_keyfield(?int $sortmethod) : string {
          switch ($sortmethod) {
              case self::SORTORDER_CREATED_DESC:
              case self::SORTORDER_CREATED_ASC:
                  return 'fp.created';
              case self::SORTORDER_REPLIES_DESC:
              case self::SORTORDER_REPLIES_ASC:
                  return 'replycount';
              default:
                  global $CFG;
                  $alias = $this->get_table_alias();
                  $field = "{$alias}.timemodified";
                  if (!empty($CFG->forum_enabletimedposts)) {
                      return "CASE WHEN {$field} < {$alias}.timestart THEN {$alias}.timestart ELSE {$field} END";
                  }
                  return $field;
          }
      }
code: protected function get_keyfield(?int $sortmethod) : string {
          switch ($sortmethod) {
              case self::SORTORDER_CREATED_DESC:
              case self::SORTORDER_CREATED_ASC:
                  return 'fp.created';
              case self::SORTORDER_REPLIES_DESC:
              case self::SORTORDER_REPLIES_ASC:
                  return 'replycount';
              default:
                  global $CFG;
                  $alias = $this->get_table_alias();
                  $field = "{$alias}.timemodified";
                  if (!empty($CFG->forum_enabletimedposts)) {
                      return "CASE WHEN {$field} < {$alias}.timestart THEN {$alias}.timestart ELSE {$field} END";
                  }
                  return $field;
          }
      }
code_tokens: protected function get_keyfield ( ? int $ sortmethod ) : string { switch ( $ sortmethod ) { case self :: SORTORDER_CREATED_DESC : case self :: SORTORDER_CREATED_ASC : return 'fp.created' ; case self :: SORTORDER_REPLIES_DESC : case self :: SORTORDER_REPLIES_ASC : return 'replycount' ; default : global $ CFG ; $ alias = $ this -> get_table_alias ( ) ; $ field = "{$alias}.timemodified" ; if ( ! empty ( $ CFG -> forum_enabletimedposts ) ) { return "CASE WHEN {$field} < {$alias}.timestart THEN {$alias}.timestart ELSE {$field} END" ; } return $ field ; } }
docstring: Get the field to sort by.
  
  @param int|null $sortmethod
  @return string
docstring_tokens: Get the field to sort by .