forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskCollection.php
More file actions
62 lines (56 loc) · 2.13 KB
/
TaskCollection.php
File metadata and controls
62 lines (56 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace ProcessMaker\Http\Resources;
use Illuminate\Http\Resources\Json\ResourceCollection;
use Illuminate\Pagination\AbstractPaginator;
use ProcessMaker\Models\UserResourceView;
/**
* @OA\Schema(
* schema="taskMetadata",
* @OA\Property(property="filter", type="string"),
* @OA\Property(property="sort_by", type="string"),
* @OA\Property(property="sort_order", type="string", enum={"asc", "desc"}),
* @OA\Property(property="count", type="integer"),
* @OA\Property(property="total_pages", type="integer"),
*
* @OA\Property(property="current_page", type="integer"),
* @OA\Property(property="form", type="integer"),
* @OA\Property(property="last_page", type="integer"),
* @OA\Property(property="path", type="string"),
* @OA\Property(property="per_page", type="integer"),
* @OA\Property(property="to", type="integer"),
* @OA\Property(property="total", type="integer"),
* @OA\Property(property="in_overdue", type="integer")
* )
*/
class TaskCollection extends ApiCollection
{
public $appends = ['inOverdue'];
/**
* Generic collection to add sorting and filtering metadata.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
UserResourceView::addToResourceCollection($this->collection, $request->user());
$payload = [
'data' => $this->collection,
'meta' => [
'filter' => $request->input('filter', ''),
'sort_by' => $request->input('order_by', ''),
'sort_order' => $request->input('order_direction', ''),
/**
* count: (integer, total items in current response)
*/
'count' => $this->resource->count(),
/**
* total_pages: (integer, the total number of pages available, based on per_page and total)
*/
'total_pages' => ceil($this->resource->total() / $this->resource->perPage()),
'in_overdue' => $this->appended->inOverdue,
],
];
return $payload;
}
}