| @@ 71-110 (lines=40) @@ | ||
| 68 | return $connection; |
|
| 69 | } |
|
| 70 | ||
| 71 | private function buildPagination($args) |
|
| 72 | { |
|
| 73 | $this->queryBus->handle( |
|
| 74 | new CountOrganizationsQuery( |
|
| 75 | $this->currentUser, |
|
| 76 | $args['name'] |
|
| 77 | ), |
|
| 78 | $total |
|
| 79 | ); |
|
| 80 | ||
| 81 | $beforeOffset = $this->connectionBuilder->getOffsetWithDefault( |
|
| 82 | isset($args['before']) |
|
| 83 | ? $args['before'] |
|
| 84 | : null, |
|
| 85 | $total |
|
| 86 | ); |
|
| 87 | $afterOffset = $this->connectionBuilder->getOffsetWithDefault( |
|
| 88 | isset($args['after']) |
|
| 89 | ? $args['after'] |
|
| 90 | : null, |
|
| 91 | -1 |
|
| 92 | ); |
|
| 93 | $startOffset = max($afterOffset, -1) + 1; |
|
| 94 | $endOffset = min($beforeOffset, $total); |
|
| 95 | ||
| 96 | if (isset($args['first']) && is_numeric($args['first'])) { |
|
| 97 | $endOffset = min($endOffset, $startOffset + $args['first']); |
|
| 98 | } |
|
| 99 | if (isset($args['last']) && is_numeric($args['last'])) { |
|
| 100 | $startOffset = max($startOffset, $endOffset - $args['last']); |
|
| 101 | } |
|
| 102 | $offset = max($startOffset, 0); |
|
| 103 | $limit = $endOffset - $startOffset; |
|
| 104 | ||
| 105 | return [ |
|
| 106 | $offset, |
|
| 107 | $limit, |
|
| 108 | $total, |
|
| 109 | ]; |
|
| 110 | } |
|
| 111 | } |
|
| 112 | ||
| @@ 75-115 (lines=41) @@ | ||
| 72 | return $connection; |
|
| 73 | } |
|
| 74 | ||
| 75 | private function buildPagination($args) |
|
| 76 | { |
|
| 77 | $this->queryBus->handle( |
|
| 78 | new CountProjectsQuery( |
|
| 79 | $this->currentUser, |
|
| 80 | $args['organizationId'], |
|
| 81 | $args['name'] |
|
| 82 | ), |
|
| 83 | $total |
|
| 84 | ); |
|
| 85 | ||
| 86 | $beforeOffset = $this->connectionBuilder->getOffsetWithDefault( |
|
| 87 | isset($args['before']) |
|
| 88 | ? $args['before'] |
|
| 89 | : null, |
|
| 90 | $total |
|
| 91 | ); |
|
| 92 | $afterOffset = $this->connectionBuilder->getOffsetWithDefault( |
|
| 93 | isset($args['after']) |
|
| 94 | ? $args['after'] |
|
| 95 | : null, |
|
| 96 | -1 |
|
| 97 | ); |
|
| 98 | $startOffset = max($afterOffset, -1) + 1; |
|
| 99 | $endOffset = min($beforeOffset, $total); |
|
| 100 | ||
| 101 | if (isset($args['first']) && is_numeric($args['first'])) { |
|
| 102 | $endOffset = min($endOffset, $startOffset + $args['first']); |
|
| 103 | } |
|
| 104 | if (isset($args['last']) && is_numeric($args['last'])) { |
|
| 105 | $startOffset = max($startOffset, $endOffset - $args['last']); |
|
| 106 | } |
|
| 107 | $offset = max($startOffset, 0); |
|
| 108 | $limit = $endOffset - $startOffset; |
|
| 109 | ||
| 110 | return [ |
|
| 111 | $offset, |
|
| 112 | $limit, |
|
| 113 | $total, |
|
| 114 | ]; |
|
| 115 | } |
|
| 116 | } |
|
| 117 | ||