Skip to content

Commit

Permalink
CUR-4667 Update lti tool settings functionality w.r.t tool type.
Browse files Browse the repository at this point in the history
  • Loading branch information
asimsarwar committed Mar 7, 2023
1 parent a894eb2 commit 2eaf341
Show file tree
Hide file tree
Showing 21 changed files with 737 additions and 474 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use App\Exceptions\GeneralException;
use App\Http\Requests\V1\LtiTool\KalturaAPISettingRequest;
use App\Repositories\MediaSources\MediaSourcesInterface;
use App\Models\LtiTool\LTIToolType;

class KalturaGeneratedAPIClientController extends Controller
{
Expand All @@ -31,7 +32,6 @@ class KalturaGeneratedAPIClientController extends Controller
protected $kalturaMediaEntryFilter;
protected $kalturaFilterPager;
private $ltiToolSettingRepository;
private $mediaSourcesRepository;

/**
* KalturaGeneratedAPIClientController constructor.
Expand All @@ -41,19 +41,16 @@ class KalturaGeneratedAPIClientController extends Controller
* @param KalturaMediaEntryFilter $kMEF
* @param KalturaFilterPager $kFP
* @param LtiToolSettingInterface $ltiToolSettingRepository
* @param MediaSourcesInterface $mediaSourcesRepository
*/
public function __construct(KalturaConfiguration $kC, KalturaClient $kClient, KalturaMediaEntryFilter $kMEF,
KalturaFilterPager $kFP, LtiToolSettingInterface $ltiToolSettingRepository,
MediaSourcesInterface $mediaSourcesRepository
KalturaFilterPager $kFP, LtiToolSettingInterface $ltiToolSettingRepository
)
{
$this->kalturaConfiguration = $kC;
$this->kalturaClient = $kClient;
$this->kalturaMediaEntryFilter = $kMEF;
$this->kalturaFilterPager = $kFP;
$this->ltiToolSettingRepository = $ltiToolSettingRepository;
$this->mediaSourcesRepository = $mediaSourcesRepository;
}

/**
Expand All @@ -80,15 +77,11 @@ public function __construct(KalturaConfiguration $kC, KalturaClient $kClient, Ka
*/
public function getMediaEntryList(KalturaAPISettingRequest $request)
{
$getParam = $request->only([
'organization_id',
'pageSize',
'pageIndex',
'searchText'
]);
$getParam = $request->all();
$videoMediaSources = getVideoMediaSources();
$mediaSourcesId = $this->mediaSourcesRepository->getMediaSourceIdByName($videoMediaSources['kaltura']);
$ltiRowResult = $this->ltiToolSettingRepository->getRowRecordByOrgAndToolType($getParam['organization_id'], $mediaSourcesId);
$ltiToolTypeRowRecord = LTIToolType::where('name', $videoMediaSources['kaltura'])->first();
$ltiToolTypeId = ( empty($ltiToolTypeRowRecord) ) ? 1 : $ltiToolTypeRowRecord->id;
$ltiRowResult = $this->ltiToolSettingRepository->getRowRecordByColumnMatch($getParam['organization_id'], $ltiToolTypeId);
// Credentials For Kaltura Session
if ($ltiRowResult) {
$secret = $ltiRowResult->tool_secret_key;
Expand Down
51 changes: 12 additions & 39 deletions app/Http/Controllers/Api/V1/LtiTool/LtiToolSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\View\View;
use App\Models\LtiTool\LTIToolType;

/**
* @authenticated
Expand Down Expand Up @@ -80,7 +81,7 @@ public function index(Request $request, Organization $suborganization)
public function show(Organization $suborganization, $id)
{
$setting = $this->ltiToolSettingRepository->find($id);
return new LtiToolSettingResource($setting->load('user', 'organization', 'mediaSources'));
return new LtiToolSettingResource($setting->load('user', 'organization', 'ltiToolType'));
}

/**
Expand All @@ -94,7 +95,7 @@ public function show(Organization $suborganization, $id)
* @bodyParam tool_name string required LTI Tool Settings tool name Example: Kaltura API Integration
* @bodyParam tool_url string required LTI Tool Settings tool url Example: https://4515783.kaf.kaltura.com
* @bodyParam lti_version string required LTI Tool Settings lti version Example: LTI-1p0
* @bodyParam media_source_id int required Id of and video media sources Example: 3
* @bodyParam lti_tool_type_id int required Id of lti tool type Example: 1
* @bodyParam tool_description string optional LTI Tool Settings description Example: Kaltura API Testing
* @bodyParam tool_custom_parameter string optional LTI Tool Settings custom param Example: embed=true
* @bodyParam tool_consumer_key string optional LTI Tool Settings consumer key Example: 4515783
Expand All @@ -116,24 +117,12 @@ public function show(Organization $suborganization, $id)
*/
public function store(StoreLtiToolSettingRequest $request, Organization $suborganization)
{
$data = $request->only([
'user_id',
'organization_id',
'tool_name',
'tool_url',
'lti_version',
'media_source_id',
'tool_description',
'tool_custom_parameter',
'tool_consumer_key',
'tool_secret_key',
'tool_content_selection_url'
]);
$data = $request->all();
$parse = parse_url($data['tool_url']);
$data['tool_domain'] = $parse['host'];
$data['tool_content_selection_url'] = (isset($data['tool_content_selection_url']) && $data['tool_content_selection_url'] != '') ? $data['tool_content_selection_url'] : $data['tool_url'];
$response = $this->ltiToolSettingRepository->create($data);
return response(['message' => $response['message'], 'data' => new LtiToolSettingResource($response['data']->load('user', 'organization', 'mediaSources'))], 200);
return response(['message' => $response['message'], 'data' => new LtiToolSettingResource($response['data']->load('user', 'organization', 'ltiToolType'))], 200);

}

Expand All @@ -149,7 +138,7 @@ public function store(StoreLtiToolSettingRequest $request, Organization $suborga
* @bodyParam tool_name string required LTI Tool Settings tool name Example: Kaltura API Integration
* @bodyParam tool_url string required LTI Tool Settings tool url Example: https://4515783.kaf.kaltura.com
* @bodyParam lti_version string required LTI Tool Settings lti version Example: LTI-1p0
* @bodyParam media_source_id int required Id of and video media sources Example: 3
* @bodyParam lti_tool_type_id int required Id of lti tool type Example: 1
* @bodyParam tool_description string optional LTI Tool Settings description Example: Kaltura API Testing
* @bodyParam tool_custom_parameter string optional LTI Tool Settings custom param Example: embed=true
* @bodyParam tool_consumer_key string optional LTI Tool Settings consumer key Example: 4515783
Expand All @@ -166,24 +155,12 @@ public function store(StoreLtiToolSettingRequest $request, Organization $suborga
*/
public function update(UpdateLtiToolSettingRequest $request, Organization $suborganization, $id)
{
$data = $request->only([
'user_id',
'organization_id',
'tool_name',
'tool_url',
'lti_version',
'media_source_id',
'tool_description',
'tool_custom_parameter',
'tool_consumer_key',
'tool_secret_key',
'tool_content_selection_url'
]);
$data = $request->all();
$parse = parse_url($data['tool_url']);
$data['tool_domain'] = $parse['host'];
$data['tool_content_selection_url'] = (isset($data['tool_content_selection_url']) && $data['tool_content_selection_url'] != '') ? $data['tool_content_selection_url'] : $data['tool_url'];
$response = $this->ltiToolSettingRepository->update($id, $data);
return response(['message' => $response['message'], 'data' => new LtiToolSettingResource($response['data']->load('user', 'organization', 'mediaSources'))], 200);
return response(['message' => $response['message'], 'data' => new LtiToolSettingResource($response['data']->load('user', 'organization', 'ltiToolType'))], 200);
}

/**
Expand All @@ -207,19 +184,15 @@ public function destroy(Organization $suborganization, $id)
/**
* Get LTI Tool Type List
*
* Get filter based media sources list for specified suborganization.
* Get lti tool type list from lti_tool_type table.
*
* @urlParam suborganization required The Id of a suborganization Example: 1
*
* @responseFile responses/organization/filter-media-source.json
*
* @param Organization $suborganization
* @responseFile 200 responses/admin/lti-tool/lti-tool-type-list.json
*
* @return LtiToolSettingResource
*/
public function getLTIToolTypeList(Organization $suborganization)
public function getLTIToolTypeList()
{
$ltiToolType = $suborganization->filterBasedMediaSources->where('media_type', 'Video');
$ltiToolType = LTIToolType::get();
return new LtiToolSettingResource($ltiToolType);
}
}
8 changes: 4 additions & 4 deletions app/Http/Requests/V1/LtiTool/StoreLtiToolSettingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function rules()
'tool_name' => 'required|string|max:255|unique:lti_tool_settings,tool_name,NULL,id,deleted_at,NULL,organization_id,' . $orgId,
'tool_url' => 'required|url|max:255|unique:lti_tool_settings,tool_url,NULL,id,deleted_at,NULL,organization_id,' . $orgId,
'lti_version' => 'required|max:20',
'media_source_id' => 'required|exists:media_sources,id|unique:lti_tool_settings,media_source_id,NULL,id,deleted_at,NULL,organization_id,' . $orgId,
'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,
'tool_consumer_key' => 'nullable|string|max:255|unique:lti_tool_settings,tool_consumer_key,NULL,id,deleted_at,NULL,organization_id,' . $orgId,
'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,
'tool_content_selection_url' => 'nullable|url|max:255',
Expand All @@ -51,9 +51,9 @@ public function rules()
public function messages()
{
return [
'media_source_id.required' => 'The Tool Type field is required.',
'media_source_id.exists' => 'The selected Tool Type is invalid.',
'media_source_id.unique' => 'The Tool Type has already been taken.'
'lti_tool_type_id.required' => 'The Tool Type field is required.',
'lti_tool_type_id.exists' => 'The selected Tool Type is invalid.',
'lti_tool_type_id.unique' => 'The Tool Type has already been taken.'
];
}
}
8 changes: 4 additions & 4 deletions app/Http/Requests/V1/LtiTool/UpdateLtiToolSettingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function rules()
'tool_name' => 'required|string|max:255|unique:lti_tool_settings,tool_name, ' . $id . ' ,id,deleted_at,NULL,organization_id,' . $orgId,
'tool_url' => 'required|url|max:255|unique:lti_tool_settings,tool_url, ' . $id . ' ,id,deleted_at,NULL,organization_id,' . $orgId,
'lti_version' => 'required|max:20',
'media_source_id' => 'required|exists:media_sources,id|unique:lti_tool_settings,media_source_id, ' . $id . ' ,id,deleted_at,NULL,organization_id,' . $orgId,
'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,
'tool_consumer_key' => 'nullable|string|max:255|unique:lti_tool_settings,tool_consumer_key, ' . $id . ' ,id,deleted_at,NULL,organization_id,' . $orgId,
'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,
'tool_content_selection_url' => 'nullable|url|max:255',
Expand All @@ -52,9 +52,9 @@ public function rules()
public function messages()
{
return [
'media_source_id.required' => 'The Tool Type field is required.',
'media_source_id.exists' => 'The selected Tool Type is invalid.',
'media_source_id.unique' => 'The Tool Type has already been taken.'
'lti_tool_type_id.required' => 'The Tool Type field is required.',
'lti_tool_type_id.exists' => 'The selected Tool Type is invalid.',
'lti_tool_type_id.unique' => 'The Tool Type has already been taken.'
];
}
}
21 changes: 21 additions & 0 deletions app/Models/LtiTool/LTIToolType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Models\LtiTool;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class LTIToolType extends Model
{
use SoftDeletes;
protected $table = 'lti_tool_type';

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name'
];
}
15 changes: 13 additions & 2 deletions app/Models/LtiTool/LtiToolSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\User;
use App\Models\LtiTool\LtiToolTypesConfig;
use App\Models\MediaSource;
use App\Models\LtiTool\LTIToolType;

class LtiToolSetting extends Model
{
Expand Down Expand Up @@ -37,7 +37,8 @@ class LtiToolSetting extends Model
'tool_enabled_capability',
'tool_icon',
'tool_secure_icon',
'media_source_id'
'media_source_id',
'lti_tool_type_id'
];

/**
Expand Down Expand Up @@ -70,6 +71,16 @@ public function organization()
public function mediaSources()
{
return $this->belongsTo(MediaSource::class, 'media_source_id', 'id');
}

/**
* @author Asim Sarwar
* Detail Define belongs to relationship with lti_tool_type table,
* @return Relationship
*/
public function ltiToolType()
{
return $this->belongsTo(LTIToolType::class, 'lti_tool_type_id', 'id');
}

}
11 changes: 0 additions & 11 deletions app/Models/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,6 @@ public function mediaSources()
->withTimestamps();
}

/**
* Get the filter based media sources for the organization
*/
public function filterBasedMediaSources()
{
return $this->belongsToMany('App\Models\MediaSource', 'organization_media_sources')
->withPivot('h5p_library', 'lti_tool_settings_status', 'media_sources_show_status')
->withTimestamps()
->wherePivot('lti_tool_settings_status', true);
}

/**
* Get organization IDs for the full tree (ancestors and children) of this org
*/
Expand Down
21 changes: 19 additions & 2 deletions app/Repositories/LtiTool/LtiToolSettingRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(LtiToolSetting $model)
public function getAll($data, $suborganization)
{
$perPage = isset($data['size']) ? $data['size'] : config('constants.default-pagination-per-page');
$query = $this->model->with(['user', 'organization', 'mediaSources']);
$query = $this->model->with(['user', 'organization', 'ltiToolType']);
if (isset($data['query']) && $data['query'] !== '') {
$query->where(function ($query) use ($data) {
$query->orWhere('tool_name', 'iLIKE', '%' . $data['query'] . '%');
Expand All @@ -48,7 +48,7 @@ public function getAll($data, $suborganization)
}

if (isset($data['filter']) && $data['filter'] > 0) {
$query = $query->whereHas('mediaSources', function ($qry) use ($data) {
$query = $query->whereHas('ltiToolType', function ($qry) use ($data) {
$qry->where('id', $data['filter']);
});
}
Expand Down Expand Up @@ -134,4 +134,21 @@ public function getRowRecordByOrgAndToolType($orgId, $mediaSourcesId)
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());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('lti_tool_type', function (Blueprint $table) {
$table->id();
$table->string('name', 150);
$table->unique('name');
$table->timestamps();
$table->softDeletes();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('lti_tool_type');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Database\Seeders\AddToolTypeOptionToLtiToolTypeTableSeeder;

return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
\Artisan::call('db:seed', [
'--class' => AddToolTypeOptionToLtiToolTypeTableSeeder::class,
'--force' => true
]);
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
};
Loading

0 comments on commit 2eaf341

Please sign in to comment.