-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathLtiToolSettingRepository.php
154 lines (142 loc) · 4.6 KB
/
LtiToolSettingRepository.php
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
namespace App\Repositories\LtiTool;
use App\Exceptions\GeneralException;
use App\Models\LtiTool\LtiToolSetting;
use App\Models\Organization;
use App\Repositories\BaseRepository;
use Illuminate\Support\Facades\Log;
/**
* @author Asim Sarwar
* Date 11-10-2021
* Class LtiToolSettingRepository
*/
class LtiToolSettingRepository extends BaseRepository implements LtiToolSettingInterface
{
/**
* LtiToolSettingRepository constructor
* @param LtiToolSetting $model
*/
public function __construct(LtiToolSetting $model)
{
$this->model = $model;
}
/**
* @param $data
* @return mixed
*/
public function getAll($data, $suborganization)
{
$perPage = isset($data['size']) ? $data['size'] : config('constants.default-pagination-per-page');
$query = $this->model->with(['user', 'organization', 'mediaSources', 'ltiToolType']);
if (isset($data['query']) && $data['query'] !== '') {
$query->where(function ($query) use ($data) {
$query->orWhere('tool_name', 'iLIKE', '%' . $data['query'] . '%');
$query->orWhere('tool_url', 'iLIKE', '%' . $data['query'] . '%');
});
}
if (isset($data['order_by_column']) && $data['order_by_column'] !== '')
{
$orderByType = isset($data['order_by_type']) ? $data['order_by_type'] : 'ASC';
$query->orderBy($data['order_by_column'], $orderByType);
} else {
$query->orderBy('id', 'DESC');
}
if (isset($data['filter']) && $data['filter'] > 0) {
$query = $query->whereHas('ltiToolType', function ($qry) use ($data) {
$qry->where('id', $data['filter']);
});
}
return $query->where('organization_id', $suborganization->id)->paginate($perPage)->withQueryString();
}
/**
* @param $data
* @return mixed
* @throws GeneralException
*/
public function create($data)
{
try {
if ($createSetting = $this->model->create($data)) {
return ['message' => 'Lti Tool setting created successfully!', 'data' => $createSetting];
}
} catch (\Exception $e) {
Log::error($e->getMessage());
}
throw new GeneralException('Unable to create lti tool setting, please try again later!');
}
/**
* @param $data
* @return mixed
* @throws GeneralException
*/
public function update($id, $data)
{
try {
if ($this->find($id)->update($data)) {
return ['message' => 'Lti tool setting updated successfully!', 'data' => $this->find($id)];
}
} catch (\Exception $e) {
Log::error($e->getMessage());
}
throw new GeneralException('Unable to update lti tool setting, please try again later!');
}
/**
* @param $id
* @return mixed
* @throws GeneralException
*/
public function find($id)
{
if ($setting = $this->model->find($id)) {
return $setting;
}
throw new GeneralException('Lti tool setting not found.');
}
/**
* @param $id
* @return mixed
* @throws GeneralException
*/
public function destroy($id)
{
try {
$this->find($id)->delete();
return ['message' => 'Lti tool setting deleted!', 'data' => []];
} catch (\Exception $e) {
Log::error($e->getMessage());
}
throw new GeneralException('Unable to delete lti tool setting, please try again later!');
}
/**
* To get row record by org and tool type match
*
* @param $orgId integer
* @param $mediaSourcesId int
* @return object
* @throws GeneralException
*/
public function getRowRecordByOrgAndToolType($orgId, $mediaSourcesId)
{
try {
return $this->model->where([['organization_id','=', $orgId],['media_source_id','=', $mediaSourcesId]])->first();
} catch (\Exception $e) {
Log::error($e->getMessage());
}
}
/**
* To get row record by org and lti_tool_type_id match
*
* @param $orgId integer
* @param $ltiToolTypeId int
* @return object
* @throws GeneralException
*/
public function getRowRecordByColumnMatch($orgId, $ltiToolTypeId)
{
try {
return $this->model->where([['organization_id','=', $orgId],['lti_tool_type_id','=', $ltiToolTypeId]])->first();
} catch (\Exception $e) {
Log::error($e->getMessage());
}
}
}