0
0

More than 1 year has passed since last update.

ページングしながら全体の表示件数をある倍数にする

Posted at
 $maxPage = $lastPage = (int) ceil($totalCount / $this->getDisplayNumber());
        // 1ページでおさまるときは調整しない
        if (1 < $lastPage) {
            // 10件ずつにした際の端数
            $modByTen = $totalCount % 10;
            // ページングした際の最終ページの件数
            $modByDisplayNumber = $totalCount % $this->getDisplayNumber();

            // 全てのページが埋まっているときや、もとから10の倍数のときは調整しない
            if (0 !== $modByDisplayNumber && 0 !== $modByTen) {
                $adjust = $modByDisplayNumber - $modByTen;

                if (0 === $adjust) {
                    // 端数落としで最終ページ分がなくなったとき
                    return [$uuids, $maxPage - 1];
                }

                if ($pageNumber === $lastPage) {
                    // 最終ページの件数を調整
                    $roundedUUids = array_slice($uuids, 0, $adjust);
                    return [$roundedUUids, $maxPage];
                }
            }

        }
        return [$uuids, $maxPage];
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0