Commit 1e41f659 authored by DELARUELLE Myriam's avatar DELARUELLE Myriam
Browse files

delete/add an activity to the matrix if it's deleted/duplicated

parent 5e7f91a6
<?php
require_once('entity/block_competency_iena_competency.php');
defined('MOODLE_INTERNAL') || die();
class block_competency_iena extends block_base
{
class block_competency_iena extends block_base{
public function init()
{
$this->title = get_string('title_plugin', 'block_competency_iena');
......@@ -93,6 +92,8 @@ class block_competency_iena extends block_base
return $this->content;
}
}
?>
\ No newline at end of file
}
?>
\ No newline at end of file
<?php
defined('MOODLE_INTERNAL') || die();
//require_once($CFG->dirroot.'/blocks/competency_iena/block_competency_iena.php');
require_once($CFG->dirroot.'/blocks/competency_iena/lib.php');
class block_competency_iena_observer {
/**
* Observer that monitors course module suppressed event and update the linked matrix competencies .
*
* @param \core\event\course_module_deleted $event the event object.
*/
public static function course_module_deleted(\core\event\course_module_deleted $event) {
$cmid = $event->contextinstanceid;
delete_matrix_competencies($cmid);
}
public static function course_module_created(\core\event\course_module_created $event) {
$cmid = $event->contextinstanceid;
duplicate_matrix_competencies($cmid, );
}
}
<?php
defined('MOODLE_INTERNAL') || die();
$observers = array(
array(
'eventname' => '\core\event\course_module_deleted',
'callback' => 'block_competency_iena_observer::course_module_deleted',
),
array(
'eventname' => '\core\event\course_module_created',
'callback' => 'block_competency_iena_observer::course_module_created',
)
);
?>
\ No newline at end of file
<?php
defined('MOODLE_INTERNAL') || die();
/**
* Delete an activity from the matrix when it's deleted from a course
* @param int $moduleid
*/
function delete_matrix_competencies($moduleid){
global $DB;
$activity=$DB->record_exists('block_competency_iena', array('cmid' => $moduleid));
if($activity){
$DB->delete_records('block_competency_iena', array('cmid' => $moduleid));
}
}
/**
* Add an activity to the matrix when it's duplicated (if the new one is linked to competencies). Moodle automatically add the corresponding competencies to the new activity, so we just have to check that to add it to the matrix if necessary
* @param int $moduleid
*/
function duplicate_matrix_competencies($moduleid){
global $DB;
$sql = "SELECT mc.cmid, m.section FROM {competency_modulecomp} mc JOIN {course_modules} m ON mc.cmid=m.id WHERE mc.cmid= :moduleid";
$params=array('moduleid'=>$moduleid);
$activity=$DB->get_record_sql($sql, $params);
if($activity){
$DB->insert_record('block_competency_iena', array('cmid' => $activity->cmid, 'sectionid'=>$activity->section));
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment