|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Eddy <[email protected]> |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace App\Repository\Admin; |
|
7
|
|
|
|
|
8
|
|
|
use App\Model\Admin\EntityField; |
|
9
|
|
|
use App\Repository\Searchable; |
|
10
|
|
|
|
|
11
|
|
|
class EntityFieldRepository |
|
12
|
|
|
{ |
|
13
|
|
|
use Searchable; |
|
14
|
|
|
|
|
15
|
|
|
public static function list($perPage, $condition = []) |
|
16
|
|
|
{ |
|
17
|
|
|
$data = EntityField::query() |
|
18
|
|
|
->where(function ($query) use ($condition) { |
|
19
|
|
|
Searchable::buildQuery($query, $condition); |
|
20
|
|
|
}) |
|
21
|
|
|
->with('entity') |
|
22
|
|
|
->orderBy('id', 'desc') |
|
23
|
|
|
->paginate($perPage); |
|
24
|
|
|
$formTypes = config('light.form_type'); |
|
25
|
|
|
$data->transform(function ($item) use ($formTypes) { |
|
26
|
|
|
xssFilter($item); |
|
27
|
|
|
$item->entityName = $item->entity->name; |
|
28
|
|
|
$item->form_type = $formTypes[$item->form_type]; |
|
29
|
|
|
$item->editUrl = route('admin::entityField.edit', ['id' => $item->id]) . '?entity_id=' . $item->entity->id; |
|
30
|
|
|
$item->deleteUrl = route('admin::entityField.delete', ['id' => $item->id]); |
|
31
|
|
|
return $item; |
|
32
|
|
|
}); |
|
33
|
|
|
|
|
34
|
|
|
return [ |
|
35
|
|
|
'code' => 0, |
|
36
|
|
|
'msg' => '', |
|
37
|
|
|
'count' => $data->total(), |
|
38
|
|
|
'data' => $data->items(), |
|
39
|
|
|
]; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public static function add($data) |
|
43
|
|
|
{ |
|
44
|
|
|
return EntityField::query()->create($data); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public static function update($id, $data) |
|
48
|
|
|
{ |
|
49
|
|
|
return EntityField::query()->where('id', $id)->update($data); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public static function find($id) |
|
53
|
|
|
{ |
|
54
|
|
|
return EntityField::query()->find($id); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public static function delete($id) |
|
58
|
|
|
{ |
|
59
|
|
|
return EntityField::destroy($id); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public static function getByEntityId($id) |
|
63
|
|
|
{ |
|
64
|
|
|
return EntityField::query()->where('entity_id', $id) |
|
65
|
|
|
->orderBy('order')->orderBy('is_show_inline')->get(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public static function getFields($entityId) |
|
69
|
|
|
{ |
|
70
|
|
|
return EntityField::query()->select('name')->where('entity_id', $entityId)->get() |
|
71
|
|
|
->pluck('name')->toArray(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public static function getSaveFields($entityId) |
|
75
|
|
|
{ |
|
76
|
|
|
return EntityField::query()->select('name')->where('entity_id', $entityId) |
|
77
|
|
|
->whereNotIn('form_type', ['inputTags'])->get()->pluck('name')->toArray(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public static function getUpdateFields($entityId) |
|
81
|
|
|
{ |
|
82
|
|
|
return EntityField::query()->select('name')->where('entity_id', $entityId) |
|
83
|
|
|
->where('is_edit', EntityField::EDIT_ENABLE) |
|
84
|
|
|
->whereNotIn('form_type', ['inputTags']) |
|
85
|
|
|
->get()->pluck('form_type', 'name')->toArray(); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public static function getInputTagsField($entityId) |
|
89
|
|
|
{ |
|
90
|
|
|
return EntityField::query()->where('entity_id', $entityId) |
|
91
|
|
|
->where('form_type', 'inputTags') |
|
92
|
|
|
->first(); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public static function formTypeBeUnique($formType) |
|
96
|
|
|
{ |
|
97
|
|
|
return in_array($formType, ['inputTags'], true); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|