|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\PanelTraits; |
|
4
|
|
|
|
|
5
|
|
|
trait Read |
|
6
|
|
|
{ |
|
7
|
|
|
/* |
|
8
|
|
|
|-------------------------------------------------------------------------- |
|
9
|
|
|
| READ |
|
10
|
|
|
|-------------------------------------------------------------------------- |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Find and retrieve an entry in the database or fail. |
|
15
|
|
|
* |
|
16
|
|
|
* @param [int] The id of the row in the db to fetch. |
|
17
|
|
|
* |
|
18
|
|
|
* @return [Eloquent Collection] The row in the db. |
|
|
|
|
|
|
19
|
|
|
*/ |
|
20
|
17 |
|
public function getEntry($id) |
|
|
|
|
|
|
21
|
|
|
{ |
|
22
|
17 |
|
if (! $this->entry) { |
|
23
|
17 |
|
$this->entry = $this->model->findOrFail($id); |
|
|
|
|
|
|
24
|
10 |
|
$this->entry = $this->entry->withFakes(); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
10 |
|
return $this->entry; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Make the query JOIN all relationships used in the columns, too, |
|
32
|
|
|
* so there will be less database queries overall. |
|
33
|
|
|
*/ |
|
34
|
3 |
|
public function autoEagerLoadRelationshipColumns() |
|
35
|
|
|
{ |
|
36
|
3 |
|
$relationships = $this->getColumnsRelationships(); |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
3 |
|
if (count($relationships)) { |
|
39
|
1 |
|
$this->with($relationships); |
|
|
|
|
|
|
40
|
|
|
} |
|
41
|
3 |
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Get all entries from the database. |
|
45
|
|
|
* |
|
46
|
|
|
* @return [Collection of your model] |
|
|
|
|
|
|
47
|
|
|
*/ |
|
48
|
1 |
|
public function getEntries() |
|
|
|
|
|
|
49
|
|
|
{ |
|
50
|
1 |
|
$this->autoEagerLoadRelationshipColumns(); |
|
51
|
|
|
|
|
52
|
1 |
|
$entries = $this->query->get(); |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
// add the fake columns for each entry |
|
55
|
1 |
|
foreach ($entries as $key => $entry) { |
|
56
|
1 |
|
$entry->addFakes($this->getFakeColumnsAsArray()); |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
1 |
|
return $entries; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Get the fields for the create or update forms. |
|
64
|
|
|
* |
|
65
|
|
|
* @param [form] create / update / both - defaults to 'both' |
|
66
|
|
|
* @param [integer] the ID of the entity to be edited in the Update form |
|
67
|
|
|
* |
|
68
|
|
|
* @return [array] all the fields that need to be shown and their information |
|
|
|
|
|
|
69
|
|
|
*/ |
|
70
|
23 |
|
public function getFields($form, $id = false) |
|
|
|
|
|
|
71
|
|
|
{ |
|
72
|
23 |
|
switch (strtolower($form)) { |
|
73
|
23 |
|
case 'create': |
|
74
|
14 |
|
return $this->getCreateFields(); |
|
|
|
|
|
|
75
|
|
|
break; |
|
|
|
|
|
|
76
|
|
|
|
|
77
|
11 |
|
case 'update': |
|
78
|
11 |
|
return $this->getUpdateFields($id); |
|
|
|
|
|
|
79
|
|
|
break; |
|
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
default: |
|
82
|
|
|
return $this->getCreateFields(); |
|
|
|
|
|
|
83
|
|
|
break; |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Check if the create/update form has upload fields. |
|
89
|
|
|
* Upload fields are the ones that have "upload" => true defined on them. |
|
90
|
|
|
* @param [form] create / update / both - defaults to 'both' |
|
91
|
|
|
* @param [id] id of the entity - defaults to false |
|
92
|
|
|
* @return bool |
|
93
|
|
|
*/ |
|
94
|
4 |
|
public function hasUploadFields($form, $id = false) |
|
95
|
|
|
{ |
|
96
|
4 |
|
$fields = $this->getFields($form, $id); |
|
97
|
3 |
|
$upload_fields = array_where($fields, function ($value, $key) { |
|
|
|
|
|
|
98
|
3 |
|
return isset($value['upload']) && $value['upload'] == true; |
|
99
|
3 |
|
}); |
|
100
|
|
|
|
|
101
|
3 |
|
return count($upload_fields) ? true : false; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Enable the DETAILS ROW functionality:. |
|
106
|
|
|
* |
|
107
|
|
|
* In the table view, show a plus sign next to each entry. |
|
108
|
|
|
* When clicking that plus sign, an AJAX call will bring whatever content you want from the EntityCrudController::showDetailsRow($id) and show it to the user. |
|
|
|
|
|
|
109
|
|
|
*/ |
|
110
|
1 |
|
public function enableDetailsRow() |
|
111
|
|
|
{ |
|
112
|
1 |
|
$this->details_row = true; |
|
|
|
|
|
|
113
|
1 |
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Disable the DETAILS ROW functionality:. |
|
117
|
|
|
*/ |
|
118
|
1 |
|
public function disableDetailsRow() |
|
119
|
|
|
{ |
|
120
|
1 |
|
$this->details_row = false; |
|
121
|
1 |
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Set the number of rows that should be show on the table page (list view). |
|
125
|
|
|
*/ |
|
126
|
1 |
|
public function setDefaultPageLength($value) |
|
127
|
|
|
{ |
|
128
|
1 |
|
$this->default_page_length = $value; |
|
|
|
|
|
|
129
|
1 |
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Get the number of rows that should be show on the table page (list view). |
|
133
|
|
|
*/ |
|
134
|
2 |
|
public function getDefaultPageLength() |
|
135
|
|
|
{ |
|
136
|
|
|
// return the custom value for this crud panel, if set using setPageLength() |
|
137
|
2 |
|
if ($this->default_page_length) { |
|
138
|
1 |
|
return $this->default_page_length; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
// otherwise return the default value in the config file |
|
142
|
1 |
|
if (config('backpack.crud.default_page_length')) { |
|
143
|
|
|
return config('backpack.crud.default_page_length'); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
1 |
|
return 25; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/* |
|
150
|
|
|
|-------------------------------------------------------------------------- |
|
151
|
|
|
| EXPORT BUTTONS |
|
152
|
|
|
|-------------------------------------------------------------------------- |
|
153
|
|
|
*/ |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Tell the list view to show the DataTables export buttons. |
|
157
|
|
|
*/ |
|
158
|
1 |
|
public function enableExportButtons() |
|
159
|
|
|
{ |
|
160
|
1 |
|
$this->export_buttons = true; |
|
|
|
|
|
|
161
|
1 |
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Check if export buttons are enabled for the table view. |
|
165
|
|
|
* @return bool |
|
166
|
|
|
*/ |
|
167
|
2 |
|
public function exportButtons() |
|
168
|
|
|
{ |
|
169
|
2 |
|
return $this->export_buttons; |
|
170
|
|
|
} |
|
171
|
|
|
} |
|
172
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.