original_string: private function addOrders(ModelCriteria &$query)
      {
          Logger::log(static::class . ' extract orders start ', LOG_DEBUG);
          $orderAdded = FALSE;
          $tableMap = $this->getTableMap();
          foreach ($this->order->getOrders() as $field => $direction) {
              if ($column = ApiHelper::checkFieldExists($tableMap, $field)) {
                  $orderAdded = TRUE;
                  if ($direction === Order::ASC) {
                      $query->addAscendingOrderByColumn($column->getPhpName());
                  } else {
                      $query->addDescendingOrderByColumn($column->getPhpName());
                  }
              }
          }
          if (!$orderAdded) {
              $pks = $this->getPkDbName();
              foreach(array_keys($pks) as $key) {
                  $query->addAscendingOrderByColumn($key);
              }
          }
          Logger::log(static::class . ' extract orders end', LOG_DEBUG);
      }
code: private function addOrders(ModelCriteria &$query)
      {
          Logger::log(static::class . ' extract orders start ', LOG_DEBUG);
          $orderAdded = FALSE;
          $tableMap = $this->getTableMap();
          foreach ($this->order->getOrders() as $field => $direction) {
              if ($column = ApiHelper::checkFieldExists($tableMap, $field)) {
                  $orderAdded = TRUE;
                  if ($direction === Order::ASC) {
                      $query->addAscendingOrderByColumn($column->getPhpName());
                  } else {
                      $query->addDescendingOrderByColumn($column->getPhpName());
                  }
              }
          }
          if (!$orderAdded) {
              $pks = $this->getPkDbName();
              foreach(array_keys($pks) as $key) {
                  $query->addAscendingOrderByColumn($key);
              }
          }
          Logger::log(static::class . ' extract orders end', LOG_DEBUG);
      }
code_tokens: private function addOrders ( ModelCriteria & $ query ) { Logger :: log ( static :: class . ' extract orders start ' , LOG_DEBUG ) ; $ orderAdded = FALSE ; $ tableMap = $ this -> getTableMap ( ) ; foreach ( $ this -> order -> getOrders ( ) as $ field => $ direction ) { if ( $ column = ApiHelper :: checkFieldExists ( $ tableMap , $ field ) ) { $ orderAdded = TRUE ; if ( $ direction === Order :: ASC ) { $ query -> addAscendingOrderByColumn ( $ column -> getPhpName ( ) ) ; } else { $ query -> addDescendingOrderByColumn ( $ column -> getPhpName ( ) ) ; } } } if ( ! $ orderAdded ) { $ pks = $ this -> getPkDbName ( ) ; foreach ( array_keys ( $ pks ) as $ key ) { $ query -> addAscendingOrderByColumn ( $ key ) ; } } Logger :: log ( static :: class . ' extract orders end' , LOG_DEBUG ) ; }
docstring: Add order fields to query
  @param ModelCriteria $query
  @throws \PSFS\base\exception\ApiException
docstring_tokens: Add order fields to query