original_string: protected function order_sql(?string $fieldname = null, string $order = 'ASC', ?string $tablealias = null) {
  
          if (!$tablealias) {
              $tablealias = 'analysable';
          }
  
          if ($order != 'ASC' && $order != 'DESC') {
              throw new \coding_exception('The order can only be ASC or DESC');
          }
  
          $ordersql = ' ORDER BY (CASE WHEN aua.timeanalysed IS NULL THEN 0 ELSE aua.timeanalysed END) ASC';
          if ($fieldname) {
              $ordersql .= ', ' . $tablealias . '.' . $fieldname .' ' . $order;
          }
  
          return $ordersql;
      }
code: protected function order_sql(?string $fieldname = null, string $order = 'ASC', ?string $tablealias = null) {
  
          if (!$tablealias) {
              $tablealias = 'analysable';
          }
  
          if ($order != 'ASC' && $order != 'DESC') {
              throw new \coding_exception('The order can only be ASC or DESC');
          }
  
          $ordersql = ' ORDER BY (CASE WHEN aua.timeanalysed IS NULL THEN 0 ELSE aua.timeanalysed END) ASC';
          if ($fieldname) {
              $ordersql .= ', ' . $tablealias . '.' . $fieldname .' ' . $order;
          }
  
          return $ordersql;
      }
code_tokens: protected function order_sql ( ? string $ fieldname = null , string $ order = 'ASC' , ? string $ tablealias = null ) { if ( ! $ tablealias ) { $ tablealias = 'analysable' ; } if ( $ order != 'ASC' && $ order != 'DESC' ) { throw new \ coding_exception ( 'The order can only be ASC or DESC' ) ; } $ ordersql = ' ORDER BY (CASE WHEN aua.timeanalysed IS NULL THEN 0 ELSE aua.timeanalysed END) ASC' ; if ( $ fieldname ) { $ ordersql .= ', ' . $ tablealias . '.' . $ fieldname . ' ' . $ order ; } return $ ordersql ; }
docstring: Returns the order by clause.
  
  @param  string|null $fieldname  The field name
  @param  string      $order      'ASC' or 'DESC'
  @param  string|null $tablealias The table alias of the field
  @return string
docstring_tokens: Returns the order by clause .