| @@ 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 | ||
| @@ 92-132 (lines=41) @@ | ||
| 89 | return $connection; |
|
| 90 | } |
|
| 91 | ||
| 92 | private function buildPagination($args) |
|
| 93 | { |
|
| 94 | $this->queryBus->handle( |
|
| 95 | new CountProjectsQuery( |
|
| 96 | $this->currentUser, |
|
| 97 | $args['organizationId'], |
|
| 98 | $args['name'] |
|
| 99 | ), |
|
| 100 | $total |
|
| 101 | ); |
|
| 102 | ||
| 103 | $beforeOffset = $this->connectionBuilder->getOffsetWithDefault( |
|
| 104 | isset($args['before']) |
|
| 105 | ? $args['before'] |
|
| 106 | : null, |
|
| 107 | $total |
|
| 108 | ); |
|
| 109 | $afterOffset = $this->connectionBuilder->getOffsetWithDefault( |
|
| 110 | isset($args['after']) |
|
| 111 | ? $args['after'] |
|
| 112 | : null, |
|
| 113 | -1 |
|
| 114 | ); |
|
| 115 | $startOffset = max($afterOffset, -1) + 1; |
|
| 116 | $endOffset = min($beforeOffset, $total); |
|
| 117 | ||
| 118 | if (isset($args['first']) && is_numeric($args['first'])) { |
|
| 119 | $endOffset = min($endOffset, $startOffset + $args['first']); |
|
| 120 | } |
|
| 121 | if (isset($args['last']) && is_numeric($args['last'])) { |
|
| 122 | $startOffset = max($startOffset, $endOffset - $args['last']); |
|
| 123 | } |
|
| 124 | $offset = max($startOffset, 0); |
|
| 125 | $limit = $endOffset - $startOffset; |
|
| 126 | ||
| 127 | return [ |
|
| 128 | $offset, |
|
| 129 | $limit, |
|
| 130 | $total, |
|
| 131 | ]; |
|
| 132 | } |
|
| 133 | } |
|
| 134 | ||