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 <?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()
public function init() {
{ $this->title = get_string('title_plugin', 'block_competency_iena');
$this->title = get_string('title_plugin', 'block_competency_iena'); }
}
function instance_allow_multiple() function instance_allow_multiple()
{ {
return false; return false;
} }
/** /**
* Set the applicable formats for this block to all * Set the applicable formats for this block to all
* @return array * @return array
*/ */
function applicable_formats() function applicable_formats()
{ {
return array('course' => true); return array('course' => true);
} }
/** /**
* Allow the user to configure a block instance * Allow the user to configure a block instance
* @return bool Returns true * @return bool Returns true
*/ */
function instance_allow_config() function instance_allow_config()
{ {
return true; return true;
} }
function has_config() function has_config()
{ {
return true; return true;
} }
public function get_content() public function get_content()
{ {
global $CFG; global $CFG;
global $COURSE; global $COURSE;
global $USER; global $USER;
if ($this->content !== null) { if ($this->content !== null) {
return $this->content; return $this->content;
} }
if (empty($this->config)) { if (empty($this->config)) {
$this->config = new stdClass(); $this->config = new stdClass();
} }
$this->content = new stdClass; $this->content = new stdClass;
$this->content->text = ""; $this->content->text = "";
if (has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id)) { if (has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id)) {
$this->content->text .= '<h4>Tableaux de bord</h4>'; $this->content->text .= '<h4>Tableaux de bord</h4>';
$this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competencies_2.php?courseid=' . $COURSE->id . '" class="btn btn-primary w-100 mb-3" style="white-space: normal;">Par étudiant</a>'; $this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competencies_2.php?courseid=' . $COURSE->id . '" class="btn btn-primary w-100 mb-3" style="white-space: normal;">Par étudiant</a>';
$this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competency_students_2.php?courseid=' . $COURSE->id . '" class="btn btn-primary w-100" style="white-space: normal;">Par compétence</a>'; $this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competency_students_2.php?courseid=' . $COURSE->id . '" class="btn btn-primary w-100" style="white-space: normal;">Par compétence</a>';
// marche plus // marche plus
// $this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competencies.php?courseid=' . $COURSE->id . '" class="btn btn-primary w-100 mb-3" style="white-space: normal;">Acquisition des compétences</a>'; // $this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competencies.php?courseid=' . $COURSE->id . '" class="btn btn-primary w-100 mb-3" style="white-space: normal;">Acquisition des compétences</a>';
$this->content->text .= '<hr>'; $this->content->text .= '<hr>';
$this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competencies_mgmt.php?courseid=' . $COURSE->id . '" type="button " class="btn btn-secondary w-100 mb-3" style="white-space: normal;">Gérer les compétences</a>'; $this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competencies_mgmt.php?courseid=' . $COURSE->id . '" type="button " class="btn btn-secondary w-100 mb-3" style="white-space: normal;">Gérer les compétences</a>';
$this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competency_mgmt.php?courseid=' . $COURSE->id . '" type="button " class="btn btn-secondary w-100 mb-3" style="white-space: normal;">Informations sur l\'APC</a>'; $this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competency_mgmt.php?courseid=' . $COURSE->id . '" type="button " class="btn btn-secondary w-100 mb-3" style="white-space: normal;">Informations sur l\'APC</a>';
} else { } else {
$this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competencies_2.php?courseid=' . $COURSE->id . '" class="btn btn-primary w-100 mb-3" style="white-space: normal;">Mes compétences</a>'; $this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competencies_2.php?courseid=' . $COURSE->id . '" class="btn btn-primary w-100 mb-3" style="white-space: normal;">Mes compétences</a>';
} }
// $competenceI = new block_competency_iena_competency(); // $competenceI = new block_competency_iena_competency();
// $competences = $competenceI->get_competencies_by_userID($USER->id); // $competences = $competenceI->get_competencies_by_userID($USER->id);
// $nb_ok = 0; // $nb_ok = 0;
// $nb_total = count($competences); // $nb_total = count($competences);
// foreach ($competences as $comp) { // foreach ($competences as $comp) {
// if ($comp->proficiency == 1) { // if ($comp->proficiency == 1) {
// $nb_ok++; // $nb_ok++;
// } // }
// } // }
// // $this->content->text .= "<p></p>"; // // $this->content->text .= "<p></p>";
// if ($nb_total > 0) { // if ($nb_total > 0) {
// $progress_percentage = ceil($nb_ok*100/$nb_total); // $progress_percentage = ceil($nb_ok*100/$nb_total);
// $this->content->text .= " // $this->content->text .= "
// <div class=\"progress\"> // <div class=\"progress\">
// <div class=\"progress-bar\" role=\"progressbar\" style=\"width: $progress_percentage%;\" aria-valuenow=\"$nb_ok\" aria-valuemin=\"0\" aria-valuemax=\"$nb_total\">$nb_ok/$nb_total</div> // <div class=\"progress-bar\" role=\"progressbar\" style=\"width: $progress_percentage%;\" aria-valuenow=\"$nb_ok\" aria-valuemin=\"0\" aria-valuemax=\"$nb_total\">$nb_ok/$nb_total</div>
// </div> // </div>
// "; // ";
// } else { // } else {
// $progress_percentage = 0; // $progress_percentage = 0;
// $this->content->text .= " // $this->content->text .= "
// <div class=\"progress\"> // <div class=\"progress\">
// <div class=\"progress-bar\" role=\"progressbar\" style=\"width: $progress_percentage%;\" aria-valuenow=\"$nb_ok\" aria-valuemin=\"0\" aria-valuemax=\"$nb_total\"></div> // <div class=\"progress-bar\" role=\"progressbar\" style=\"width: $progress_percentage%;\" aria-valuenow=\"$nb_ok\" aria-valuemin=\"0\" aria-valuemax=\"$nb_total\"></div>
// </div> // </div>
// "; // ";
// } // }
return $this->content; 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