-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathActivityItemRepository.php
More file actions
129 lines (116 loc) · 4.17 KB
/
ActivityItemRepository.php
File metadata and controls
129 lines (116 loc) · 4.17 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
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
<?php
namespace App\Repositories\ActivityItem;
use App\Exceptions\GeneralException;
use App\Models\ActivityItem;
use App\Repositories\BaseRepository;
use App\Repositories\ActivityItem\ActivityItemRepositoryInterface;
use Illuminate\Support\Collection;
class ActivityItemRepository extends BaseRepository implements ActivityItemRepositoryInterface
{
/**
* ActivityItemRepository constructor.
*
* @param ActivityItem $model
*/
public function __construct(ActivityItem $model)
{
parent::__construct($model);
}
/**
* @param $suborganization
* @param $data
*
* @return mixed
*/
public function getAll($suborganization, $data)
{
$query = $this->model;
// if specific index projects requested
if (isset($data['query']) && $data['query'] !== '') {
$query = $query->where('title', 'iLIKE', '%' . $data['query'] . '%');
}
if (isset($data['skipPagination']) && $data['skipPagination'] === 'true') {
return $query->where('organization_id', $suborganization->id)
->orderBy('order', 'ASC')
->orderBy('title', 'ASC')
->get();
}
if (isset($data['filter']) && $data['filter'] !== '') {
$query = $query->whereHas('activityType', function ($qry) use ($data) {
$qry->where('id',$data['filter']);
});
}
$perPage = isset($data['size']) ? $data['size'] : config('constants.default-pagination-per-page');
if (isset($data['order_by_column']) && $data['order_by_column'] === 'order') {
$orderByType = isset($data['order_by_type']) ? $data['order_by_type'] : 'ASC';
$query = $query->orderBy($data['order_by_column'], $orderByType);
} else {
$query = $query->orderBy('order', 'ASC');
}
return $query->where('organization_id', $suborganization->id)
->orderBy('order', 'ASC')
->orderBy('title', 'ASC')
->paginate($perPage)->withQueryString();
}
/**
* @return mixed
*/
public function getActivityLayouts()
{
return $this->model->whereIn('title', [
'Interactive Video',
'Column Layout',
'Interactive Book',
'Course Presentation',
'Quiz'
]
)
->orderBy('order', 'ASC')
->get();
}
/**
* @param $data
* @return mixed
* @throws GeneralException
*/
public function create($data)
{
try {
if ($item = $this->model->create($data)) {
return $item;
}
} catch (\Exception $e) {
\Log::error($e->getMessage());
}
throw new GeneralException('Unable to create activity Item, please try again later!');
}
/**
* @param $data
* @return mixed
* @throws GeneralException
*/
public function update($id, $data)
{
try {
if ($this->find($id)->update($data)) {
return $this->find($id);
}
} catch (\Exception $e) {
\Log::error($e->getMessage());
}
throw new GeneralException('Unable to update activity Item, please try again later!');
}
/**
* Get the h5p content for activity item.
*
* @param int $libraryName for activity item
* @param int $libraryMajorVersion for activity item
* @param int $libraryMinorVerison for activity item
* @return array
*/
public function getActivityItem($libraryName, $libraryMajorVersion, $libraryMinorVerison) {
// Create full name of library with major and minor version
$libName = $libraryName. ' ' . $libraryMajorVersion . '.' .$libraryMinorVerison ;
return $this->model::select('id', 'h5pLib', 'activity_type_id')->where('h5pLib', $libName)->with('activityType')->first();
}
}