- $sql .= sprintf(
- ' ORDER BY profile.%s %s, profile.nickname ASC LIMIT %d, %d',
- $sort,
- $this->reverse ? 'DESC' : 'ASC',
- $offset,
- $limit
- );
+ $order = sprintf('%1$s.%2$s %3$s, %1$s.%4$s ASC',
+ $profile->escapedTableName(),
+ $this->getSortKey('nickname'),
+ $this->reverse ? 'DESC' : 'ASC',
+ 'nickname');
+ $profile->orderBy($order);
+ $profile->limit($offset, $limit);