Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cur 4667 update tool type functionality inside lti tool settings #1571

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
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\Repositories\LtiTool\LtiToolType\LtiToolTypeInterface;

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

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

/**
Expand All @@ -80,15 +80,10 @@ 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);
$ltiToolTypeId = $this->ltiToolTypeRepo->getLtiToolTypeIdByName($videoMediaSources['kaltura']);
$ltiRowResult = $this->ltiToolSettingRepository->getRowRecordByColumnMatch($getParam['organization_id'], $ltiToolTypeId);
// Credentials For Kaltura Session
if ($ltiRowResult) {
$secret = $ltiRowResult->tool_secret_key;
Expand Down
56 changes: 16 additions & 40 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\Repositories\LtiTool\LtiToolType\LtiToolTypeInterface;

/**
* @authenticated
Expand All @@ -28,15 +29,18 @@
class LtiToolSettingsController extends Controller
{
private $ltiToolSettingRepository;
protected $ltiToolTypeRepo;

/**
* LtiToolSettingsController constructor.
*
* @param LtiToolSettingInterface $ltiToolSettingRepository
* @param LtiToolTypeInterface $ltiToolTypeRepo
*/
public function __construct(LtiToolSettingInterface $ltiToolSettingRepository)
public function __construct(LtiToolSettingInterface $ltiToolSettingRepository, LtiToolTypeInterface $ltiToolTypeRepo)
{
$this->ltiToolSettingRepository = $ltiToolSettingRepository;
$this->ltiToolTypeRepo = $ltiToolTypeRepo;
}

/**
Expand Down Expand Up @@ -80,7 +84,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', 'mediaSources', 'ltiToolType'));
}

/**
Expand All @@ -94,7 +98,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 +120,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', 'mediaSources', 'ltiToolType'))], 200);

}

Expand All @@ -149,7 +141,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 +158,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', 'mediaSources', 'ltiToolType'))], 200);
}

/**
Expand All @@ -207,19 +187,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 = $this->ltiToolTypeRepo->all();
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.'
];
}
}
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');
}

}
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'
];
}
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
3 changes: 3 additions & 0 deletions app/Providers/RepositoryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
use App\Repositories\MicrosoftTeam\MicrosoftTeamRepository;
use App\Repositories\MediaSources\MediaSourcesInterface;
use App\Repositories\MediaSources\MediaSourcesRepository;
use App\Repositories\LtiTool\LtiToolType\LtiToolTypeInterface;
use App\Repositories\LtiTool\LtiToolType\LtiToolTypeRepository;

class RepositoryServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -130,6 +132,7 @@ public function register()
$this->app->bind(OrganizationRoleTypeRepositoryInterface::class, OrganizationRoleTypeRepository::class);
$this->app->bind(MicrosoftTeamRepositoryInterface::class, MicrosoftTeamRepository::class);
$this->app->bind(MediaSourcesInterface::class, MediaSourcesRepository::class);
$this->app->bind(LtiToolTypeInterface::class, LtiToolTypeRepository::class);
}

/**
Expand Down
10 changes: 10 additions & 0 deletions app/Repositories/LtiTool/LtiToolSettingInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,14 @@ interface LtiToolSettingInterface extends EloquentRepositoryInterface
* @throws GeneralException
*/
public function getRowRecordByOrgAndToolType($orgId, $mediaSourcesId);

/**
* 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);
}
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', 'mediaSources', '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());
}
}
}
Loading