mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 13:02:07 +02:00
MDL-65306 mod_lti: remove direct coupling to subplugin
This commit is contained in:
parent
e5423ddb93
commit
cfbc361dd6
@ -226,6 +226,42 @@ abstract class service_base {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a new LTI Instance is added.
|
||||
*
|
||||
* @param object $lti LTI Instance.
|
||||
*/
|
||||
public function instance_added(object $lti): void {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a new LTI Instance is updated.
|
||||
*
|
||||
* @param object $lti LTI Instance.
|
||||
*/
|
||||
public function instance_updated(object $lti): void {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a new LTI Instance is deleted.
|
||||
*
|
||||
* @param int $id LTI Instance.
|
||||
*/
|
||||
public function instance_deleted(int $id): void {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the form data when displaying the LTI Instance form.
|
||||
*
|
||||
* @param object $defaultvalues Default form values.
|
||||
*/
|
||||
public function set_instance_form_values(object $defaultvalues): void {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array with the names of the parameters that the service will be saving in the configuration
|
||||
*
|
||||
@ -471,5 +507,4 @@ abstract class service_base {
|
||||
return $ok;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -47,7 +47,6 @@
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
use ltiservice_gradebookservices\local\service\gradebookservices;
|
||||
|
||||
/**
|
||||
* List of features supported in URL module
|
||||
@ -119,7 +118,10 @@ function lti_add_instance($lti, $mform) {
|
||||
lti_grade_item_update($lti);
|
||||
}
|
||||
|
||||
gradebookservices::update_coupled_gradebookservices($lti, $lti->lineitemresourceid ?? '', $lti->lineitemtag ?? '');
|
||||
$services = lti_get_services();
|
||||
foreach ($services as $service) {
|
||||
$service->instance_added( $lti );
|
||||
}
|
||||
|
||||
$completiontimeexpected = !empty($lti->completionexpected) ? $lti->completionexpected : null;
|
||||
\core_completion\api::update_completion_date_event($lti->coursemodule, 'lti', $lti->id, $completiontimeexpected);
|
||||
@ -168,7 +170,10 @@ function lti_update_instance($lti, $mform) {
|
||||
$lti->typeid = $lti->urlmatchedtypeid;
|
||||
}
|
||||
|
||||
gradebookservices::update_coupled_gradebookservices($lti, $lti->lineitemresourceid, $lti->lineitemtag);
|
||||
$services = lti_get_services();
|
||||
foreach ($services as $service) {
|
||||
$service->instance_updated( $lti );
|
||||
}
|
||||
|
||||
$completiontimeexpected = !empty($lti->completionexpected) ? $lti->completionexpected : null;
|
||||
\core_completion\api::update_completion_date_event($lti->coursemodule, 'lti', $lti->id, $completiontimeexpected);
|
||||
@ -185,7 +190,8 @@ function lti_update_instance($lti, $mform) {
|
||||
* @return boolean Success/Failure
|
||||
**/
|
||||
function lti_delete_instance($id) {
|
||||
global $DB;
|
||||
global $DB, $CFG;
|
||||
require_once($CFG->dirroot.'/mod/lti/locallib.php');
|
||||
|
||||
if (! $basiclti = $DB->get_record("lti", array("id" => $id))) {
|
||||
return false;
|
||||
@ -206,7 +212,15 @@ function lti_delete_instance($id) {
|
||||
\core_completion\api::update_completion_date_event($cm->id, 'lti', $id, null);
|
||||
|
||||
// We must delete the module record after we delete the grade item.
|
||||
return $DB->delete_records("lti", array("id" => $basiclti->id));
|
||||
if ($DB->delete_records("lti", array("id" => $basiclti->id)) ) {
|
||||
$services = lti_get_services();
|
||||
foreach ($services as $service) {
|
||||
$service->instance_deleted( $id );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,7 +50,6 @@ defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
require_once($CFG->dirroot.'/course/moodleform_mod.php');
|
||||
require_once($CFG->dirroot.'/mod/lti/locallib.php');
|
||||
use ltiservice_gradebookservices\local\service\gradebookservices;
|
||||
|
||||
class mod_lti_mod_form extends moodleform_mod {
|
||||
|
||||
@ -339,21 +338,17 @@ class mod_lti_mod_form extends moodleform_mod {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current values for resource and tag in case of update.
|
||||
* Sets the current values handled by services in case of update.
|
||||
*
|
||||
* @param object $defaultvalues default values to populate the form with.
|
||||
*/
|
||||
public function set_data($defaultvalues) {
|
||||
$defaultvalues->lineitemresourceid = '';
|
||||
$defaultvalues->lineitemtag = '';
|
||||
if (is_object($defaultvalues) && $defaultvalues->instance) {
|
||||
$gbs = gradebookservices::find_ltiservice_gradebookservice_for_lti($defaultvalues->instance);
|
||||
if ($gbs) {
|
||||
$defaultvalues->lineitemresourceid = $gbs->resourceid;
|
||||
$defaultvalues->lineitemtag = $gbs->tag;
|
||||
$services = lti_get_services();
|
||||
if (is_object($defaultvalues)) {
|
||||
foreach ($services as $service) {
|
||||
$service->set_instance_form_values( $defaultvalues );
|
||||
}
|
||||
}
|
||||
|
||||
parent::set_data($defaultvalues);
|
||||
}
|
||||
}
|
||||
|
@ -649,6 +649,41 @@ class gradebookservices extends service_base {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a new LTI Instance is added.
|
||||
*
|
||||
* @param object $lti LTI Instance.
|
||||
*/
|
||||
public function instance_added(object $lti): void {
|
||||
self::update_coupled_gradebookservices($lti, $lti->lineitemresourceid ?? '', $lti->lineitemtag ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a new LTI Instance is updated.
|
||||
*
|
||||
* @param object $lti LTI Instance.
|
||||
*/
|
||||
public function instance_updated(object $lti): void {
|
||||
self::update_coupled_gradebookservices($lti, $lti->lineitemresourceid ?? '', $lti->lineitemtag ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the form data when displaying the LTI Instance form.
|
||||
*
|
||||
* @param object $defaultvalues Default form values.
|
||||
*/
|
||||
public function set_instance_form_values(object $defaultvalues): void {
|
||||
$defaultvalues->lineitemresourceid = '';
|
||||
$defaultvalues->lineitemtag = '';
|
||||
if (is_object($defaultvalues) && $defaultvalues->instance) {
|
||||
$gbs = self::find_ltiservice_gradebookservice_for_lti($defaultvalues->instance);
|
||||
if ($gbs) {
|
||||
$defaultvalues->lineitemresourceid = $gbs->resourceid;
|
||||
$defaultvalues->lineitemtag = $gbs->tag;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes orphaned rows from the 'ltiservice_gradebookservices' table.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user