Skip to content

Commit 2eaf341

Browse files
committed
CUR-4667 Update lti tool settings functionality w.r.t tool type.
1 parent a894eb2 commit 2eaf341

21 files changed

+737
-474
lines changed

app/Http/Controllers/Api/V1/CurrikiInteractiveVideoIntegration/Kaltura/KalturaGeneratedAPIClientController.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use App\Exceptions\GeneralException;
2424
use App\Http\Requests\V1\LtiTool\KalturaAPISettingRequest;
2525
use App\Repositories\MediaSources\MediaSourcesInterface;
26+
use App\Models\LtiTool\LTIToolType;
2627

2728
class KalturaGeneratedAPIClientController extends Controller
2829
{
@@ -31,7 +32,6 @@ class KalturaGeneratedAPIClientController extends Controller
3132
protected $kalturaMediaEntryFilter;
3233
protected $kalturaFilterPager;
3334
private $ltiToolSettingRepository;
34-
private $mediaSourcesRepository;
3535

3636
/**
3737
* KalturaGeneratedAPIClientController constructor.
@@ -41,19 +41,16 @@ class KalturaGeneratedAPIClientController extends Controller
4141
* @param KalturaMediaEntryFilter $kMEF
4242
* @param KalturaFilterPager $kFP
4343
* @param LtiToolSettingInterface $ltiToolSettingRepository
44-
* @param MediaSourcesInterface $mediaSourcesRepository
4544
*/
4645
public function __construct(KalturaConfiguration $kC, KalturaClient $kClient, KalturaMediaEntryFilter $kMEF,
47-
KalturaFilterPager $kFP, LtiToolSettingInterface $ltiToolSettingRepository,
48-
MediaSourcesInterface $mediaSourcesRepository
46+
KalturaFilterPager $kFP, LtiToolSettingInterface $ltiToolSettingRepository
4947
)
5048
{
5149
$this->kalturaConfiguration = $kC;
5250
$this->kalturaClient = $kClient;
5351
$this->kalturaMediaEntryFilter = $kMEF;
5452
$this->kalturaFilterPager = $kFP;
5553
$this->ltiToolSettingRepository = $ltiToolSettingRepository;
56-
$this->mediaSourcesRepository = $mediaSourcesRepository;
5754
}
5855

5956
/**
@@ -80,15 +77,11 @@ public function __construct(KalturaConfiguration $kC, KalturaClient $kClient, Ka
8077
*/
8178
public function getMediaEntryList(KalturaAPISettingRequest $request)
8279
{
83-
$getParam = $request->only([
84-
'organization_id',
85-
'pageSize',
86-
'pageIndex',
87-
'searchText'
88-
]);
80+
$getParam = $request->all();
8981
$videoMediaSources = getVideoMediaSources();
90-
$mediaSourcesId = $this->mediaSourcesRepository->getMediaSourceIdByName($videoMediaSources['kaltura']);
91-
$ltiRowResult = $this->ltiToolSettingRepository->getRowRecordByOrgAndToolType($getParam['organization_id'], $mediaSourcesId);
82+
$ltiToolTypeRowRecord = LTIToolType::where('name', $videoMediaSources['kaltura'])->first();
83+
$ltiToolTypeId = ( empty($ltiToolTypeRowRecord) ) ? 1 : $ltiToolTypeRowRecord->id;
84+
$ltiRowResult = $this->ltiToolSettingRepository->getRowRecordByColumnMatch($getParam['organization_id'], $ltiToolTypeId);
9285
// Credentials For Kaltura Session
9386
if ($ltiRowResult) {
9487
$secret = $ltiRowResult->tool_secret_key;

app/Http/Controllers/Api/V1/LtiTool/LtiToolSettingsController.php

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Illuminate\Http\Request;
1818
use Illuminate\Http\Response;
1919
use Illuminate\View\View;
20+
use App\Models\LtiTool\LTIToolType;
2021

2122
/**
2223
* @authenticated
@@ -80,7 +81,7 @@ public function index(Request $request, Organization $suborganization)
8081
public function show(Organization $suborganization, $id)
8182
{
8283
$setting = $this->ltiToolSettingRepository->find($id);
83-
return new LtiToolSettingResource($setting->load('user', 'organization', 'mediaSources'));
84+
return new LtiToolSettingResource($setting->load('user', 'organization', 'ltiToolType'));
8485
}
8586

8687
/**
@@ -94,7 +95,7 @@ public function show(Organization $suborganization, $id)
9495
* @bodyParam tool_name string required LTI Tool Settings tool name Example: Kaltura API Integration
9596
* @bodyParam tool_url string required LTI Tool Settings tool url Example: https://4515783.kaf.kaltura.com
9697
* @bodyParam lti_version string required LTI Tool Settings lti version Example: LTI-1p0
97-
* @bodyParam media_source_id int required Id of and video media sources Example: 3
98+
* @bodyParam lti_tool_type_id int required Id of lti tool type Example: 1
9899
* @bodyParam tool_description string optional LTI Tool Settings description Example: Kaltura API Testing
99100
* @bodyParam tool_custom_parameter string optional LTI Tool Settings custom param Example: embed=true
100101
* @bodyParam tool_consumer_key string optional LTI Tool Settings consumer key Example: 4515783
@@ -116,24 +117,12 @@ public function show(Organization $suborganization, $id)
116117
*/
117118
public function store(StoreLtiToolSettingRequest $request, Organization $suborganization)
118119
{
119-
$data = $request->only([
120-
'user_id',
121-
'organization_id',
122-
'tool_name',
123-
'tool_url',
124-
'lti_version',
125-
'media_source_id',
126-
'tool_description',
127-
'tool_custom_parameter',
128-
'tool_consumer_key',
129-
'tool_secret_key',
130-
'tool_content_selection_url'
131-
]);
120+
$data = $request->all();
132121
$parse = parse_url($data['tool_url']);
133122
$data['tool_domain'] = $parse['host'];
134123
$data['tool_content_selection_url'] = (isset($data['tool_content_selection_url']) && $data['tool_content_selection_url'] != '') ? $data['tool_content_selection_url'] : $data['tool_url'];
135124
$response = $this->ltiToolSettingRepository->create($data);
136-
return response(['message' => $response['message'], 'data' => new LtiToolSettingResource($response['data']->load('user', 'organization', 'mediaSources'))], 200);
125+
return response(['message' => $response['message'], 'data' => new LtiToolSettingResource($response['data']->load('user', 'organization', 'ltiToolType'))], 200);
137126

138127
}
139128

@@ -149,7 +138,7 @@ public function store(StoreLtiToolSettingRequest $request, Organization $suborga
149138
* @bodyParam tool_name string required LTI Tool Settings tool name Example: Kaltura API Integration
150139
* @bodyParam tool_url string required LTI Tool Settings tool url Example: https://4515783.kaf.kaltura.com
151140
* @bodyParam lti_version string required LTI Tool Settings lti version Example: LTI-1p0
152-
* @bodyParam media_source_id int required Id of and video media sources Example: 3
141+
* @bodyParam lti_tool_type_id int required Id of lti tool type Example: 1
153142
* @bodyParam tool_description string optional LTI Tool Settings description Example: Kaltura API Testing
154143
* @bodyParam tool_custom_parameter string optional LTI Tool Settings custom param Example: embed=true
155144
* @bodyParam tool_consumer_key string optional LTI Tool Settings consumer key Example: 4515783
@@ -166,24 +155,12 @@ public function store(StoreLtiToolSettingRequest $request, Organization $suborga
166155
*/
167156
public function update(UpdateLtiToolSettingRequest $request, Organization $suborganization, $id)
168157
{
169-
$data = $request->only([
170-
'user_id',
171-
'organization_id',
172-
'tool_name',
173-
'tool_url',
174-
'lti_version',
175-
'media_source_id',
176-
'tool_description',
177-
'tool_custom_parameter',
178-
'tool_consumer_key',
179-
'tool_secret_key',
180-
'tool_content_selection_url'
181-
]);
158+
$data = $request->all();
182159
$parse = parse_url($data['tool_url']);
183160
$data['tool_domain'] = $parse['host'];
184161
$data['tool_content_selection_url'] = (isset($data['tool_content_selection_url']) && $data['tool_content_selection_url'] != '') ? $data['tool_content_selection_url'] : $data['tool_url'];
185162
$response = $this->ltiToolSettingRepository->update($id, $data);
186-
return response(['message' => $response['message'], 'data' => new LtiToolSettingResource($response['data']->load('user', 'organization', 'mediaSources'))], 200);
163+
return response(['message' => $response['message'], 'data' => new LtiToolSettingResource($response['data']->load('user', 'organization', 'ltiToolType'))], 200);
187164
}
188165

189166
/**
@@ -207,19 +184,15 @@ public function destroy(Organization $suborganization, $id)
207184
/**
208185
* Get LTI Tool Type List
209186
*
210-
* Get filter based media sources list for specified suborganization.
187+
* Get lti tool type list from lti_tool_type table.
211188
*
212-
* @urlParam suborganization required The Id of a suborganization Example: 1
213-
*
214-
* @responseFile responses/organization/filter-media-source.json
215-
*
216-
* @param Organization $suborganization
189+
* @responseFile 200 responses/admin/lti-tool/lti-tool-type-list.json
217190
*
218191
* @return LtiToolSettingResource
219192
*/
220-
public function getLTIToolTypeList(Organization $suborganization)
193+
public function getLTIToolTypeList()
221194
{
222-
$ltiToolType = $suborganization->filterBasedMediaSources->where('media_type', 'Video');
195+
$ltiToolType = LTIToolType::get();
223196
return new LtiToolSettingResource($ltiToolType);
224197
}
225198
}

app/Http/Requests/V1/LtiTool/StoreLtiToolSettingRequest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function rules()
3434
'tool_name' => 'required|string|max:255|unique:lti_tool_settings,tool_name,NULL,id,deleted_at,NULL,organization_id,' . $orgId,
3535
'tool_url' => 'required|url|max:255|unique:lti_tool_settings,tool_url,NULL,id,deleted_at,NULL,organization_id,' . $orgId,
3636
'lti_version' => 'required|max:20',
37-
'media_source_id' => 'required|exists:media_sources,id|unique:lti_tool_settings,media_source_id,NULL,id,deleted_at,NULL,organization_id,' . $orgId,
37+
'lti_tool_type_id' => 'required|exists:lti_tool_type,id|unique:lti_tool_settings,lti_tool_type_id,NULL,id,deleted_at,NULL,organization_id,' . $orgId,
3838
'tool_consumer_key' => 'nullable|string|max:255|unique:lti_tool_settings,tool_consumer_key,NULL,id,deleted_at,NULL,organization_id,' . $orgId,
3939
'tool_secret_key' => 'required_with:tool_consumer_key|max:255|unique:lti_tool_settings,tool_secret_key,NULL,id,deleted_at,NULL,organization_id,' . $orgId,
4040
'tool_content_selection_url' => 'nullable|url|max:255',
@@ -51,9 +51,9 @@ public function rules()
5151
public function messages()
5252
{
5353
return [
54-
'media_source_id.required' => 'The Tool Type field is required.',
55-
'media_source_id.exists' => 'The selected Tool Type is invalid.',
56-
'media_source_id.unique' => 'The Tool Type has already been taken.'
54+
'lti_tool_type_id.required' => 'The Tool Type field is required.',
55+
'lti_tool_type_id.exists' => 'The selected Tool Type is invalid.',
56+
'lti_tool_type_id.unique' => 'The Tool Type has already been taken.'
5757
];
5858
}
5959
}

app/Http/Requests/V1/LtiTool/UpdateLtiToolSettingRequest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function rules()
3535
'tool_name' => 'required|string|max:255|unique:lti_tool_settings,tool_name, ' . $id . ' ,id,deleted_at,NULL,organization_id,' . $orgId,
3636
'tool_url' => 'required|url|max:255|unique:lti_tool_settings,tool_url, ' . $id . ' ,id,deleted_at,NULL,organization_id,' . $orgId,
3737
'lti_version' => 'required|max:20',
38-
'media_source_id' => 'required|exists:media_sources,id|unique:lti_tool_settings,media_source_id, ' . $id . ' ,id,deleted_at,NULL,organization_id,' . $orgId,
38+
'lti_tool_type_id' => 'required|exists:lti_tool_type,id|unique:lti_tool_settings,lti_tool_type_id, ' . $id . ' ,id,deleted_at,NULL,organization_id,' . $orgId,
3939
'tool_consumer_key' => 'nullable|string|max:255|unique:lti_tool_settings,tool_consumer_key, ' . $id . ' ,id,deleted_at,NULL,organization_id,' . $orgId,
4040
'tool_secret_key' => 'required_with:tool_consumer_key|max:255|unique:lti_tool_settings,tool_secret_key, ' . $id . ' ,id,deleted_at,NULL,organization_id,' . $orgId,
4141
'tool_content_selection_url' => 'nullable|url|max:255',
@@ -52,9 +52,9 @@ public function rules()
5252
public function messages()
5353
{
5454
return [
55-
'media_source_id.required' => 'The Tool Type field is required.',
56-
'media_source_id.exists' => 'The selected Tool Type is invalid.',
57-
'media_source_id.unique' => 'The Tool Type has already been taken.'
55+
'lti_tool_type_id.required' => 'The Tool Type field is required.',
56+
'lti_tool_type_id.exists' => 'The selected Tool Type is invalid.',
57+
'lti_tool_type_id.unique' => 'The Tool Type has already been taken.'
5858
];
5959
}
6060
}

app/Models/LtiTool/LTIToolType.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace App\Models\LtiTool;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
use Illuminate\Database\Eloquent\SoftDeletes;
7+
8+
class LTIToolType extends Model
9+
{
10+
use SoftDeletes;
11+
protected $table = 'lti_tool_type';
12+
13+
/**
14+
* The attributes that are mass assignable.
15+
*
16+
* @var array
17+
*/
18+
protected $fillable = [
19+
'name'
20+
];
21+
}

app/Models/LtiTool/LtiToolSetting.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use Illuminate\Database\Eloquent\Model;
88
use Illuminate\Database\Eloquent\SoftDeletes;
99
use App\User;
10-
use App\Models\LtiTool\LtiToolTypesConfig;
1110
use App\Models\MediaSource;
11+
use App\Models\LtiTool\LTIToolType;
1212

1313
class LtiToolSetting extends Model
1414
{
@@ -37,7 +37,8 @@ class LtiToolSetting extends Model
3737
'tool_enabled_capability',
3838
'tool_icon',
3939
'tool_secure_icon',
40-
'media_source_id'
40+
'media_source_id',
41+
'lti_tool_type_id'
4142
];
4243

4344
/**
@@ -70,6 +71,16 @@ public function organization()
7071
public function mediaSources()
7172
{
7273
return $this->belongsTo(MediaSource::class, 'media_source_id', 'id');
74+
}
75+
76+
/**
77+
* @author Asim Sarwar
78+
* Detail Define belongs to relationship with lti_tool_type table,
79+
* @return Relationship
80+
*/
81+
public function ltiToolType()
82+
{
83+
return $this->belongsTo(LTIToolType::class, 'lti_tool_type_id', 'id');
7384
}
7485

7586
}

app/Models/Organization.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,6 @@ public function mediaSources()
179179
->withTimestamps();
180180
}
181181

182-
/**
183-
* Get the filter based media sources for the organization
184-
*/
185-
public function filterBasedMediaSources()
186-
{
187-
return $this->belongsToMany('App\Models\MediaSource', 'organization_media_sources')
188-
->withPivot('h5p_library', 'lti_tool_settings_status', 'media_sources_show_status')
189-
->withTimestamps()
190-
->wherePivot('lti_tool_settings_status', true);
191-
}
192-
193182
/**
194183
* Get organization IDs for the full tree (ancestors and children) of this org
195184
*/

app/Repositories/LtiTool/LtiToolSettingRepository.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct(LtiToolSetting $model)
3232
public function getAll($data, $suborganization)
3333
{
3434
$perPage = isset($data['size']) ? $data['size'] : config('constants.default-pagination-per-page');
35-
$query = $this->model->with(['user', 'organization', 'mediaSources']);
35+
$query = $this->model->with(['user', 'organization', 'ltiToolType']);
3636
if (isset($data['query']) && $data['query'] !== '') {
3737
$query->where(function ($query) use ($data) {
3838
$query->orWhere('tool_name', 'iLIKE', '%' . $data['query'] . '%');
@@ -48,7 +48,7 @@ public function getAll($data, $suborganization)
4848
}
4949

5050
if (isset($data['filter']) && $data['filter'] > 0) {
51-
$query = $query->whereHas('mediaSources', function ($qry) use ($data) {
51+
$query = $query->whereHas('ltiToolType', function ($qry) use ($data) {
5252
$qry->where('id', $data['filter']);
5353
});
5454
}
@@ -134,4 +134,21 @@ public function getRowRecordByOrgAndToolType($orgId, $mediaSourcesId)
134134
Log::error($e->getMessage());
135135
}
136136
}
137+
138+
/**
139+
* To get row record by org and lti_tool_type_id match
140+
*
141+
* @param $orgId integer
142+
* @param $ltiToolTypeId int
143+
* @return object
144+
* @throws GeneralException
145+
*/
146+
public function getRowRecordByColumnMatch($orgId, $ltiToolTypeId)
147+
{
148+
try {
149+
return $this->model->where([['organization_id','=', $orgId],['lti_tool_type_id','=', $ltiToolTypeId]])->first();
150+
} catch (\Exception $e) {
151+
Log::error($e->getMessage());
152+
}
153+
}
137154
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('lti_tool_type', function (Blueprint $table) {
17+
$table->id();
18+
$table->string('name', 150);
19+
$table->unique('name');
20+
$table->timestamps();
21+
$table->softDeletes();
22+
});
23+
}
24+
25+
/**
26+
* Reverse the migrations.
27+
*
28+
* @return void
29+
*/
30+
public function down()
31+
{
32+
Schema::dropIfExists('lti_tool_type');
33+
}
34+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Database\Seeders\AddToolTypeOptionToLtiToolTypeTableSeeder;
5+
6+
return new class extends Migration
7+
{
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
\Artisan::call('db:seed', [
16+
'--class' => AddToolTypeOptionToLtiToolTypeTableSeeder::class,
17+
'--force' => true
18+
]);
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
//
29+
}
30+
};

0 commit comments

Comments
 (0)