diff --git a/block_competency_iena.php b/block_competency_iena.php index ffbc8145d905dda93366c989c518a0d09b285e03..c6ab020c9b20d5ed357f901abadd119d9e66de15 100644 --- a/block_competency_iena.php +++ b/block_competency_iena.php @@ -1,98 +1,99 @@ <?php -require_once('entity/block_competency_iena_competency.php'); +defined('MOODLE_INTERNAL') || die(); -class block_competency_iena extends block_base -{ - public function init() - { - $this->title = get_string('title_plugin', 'block_competency_iena'); - } +class block_competency_iena extends block_base{ + public function init() + { + $this->title = get_string('title_plugin', 'block_competency_iena'); + } - function instance_allow_multiple() - { - return false; - } + function instance_allow_multiple() + { + return false; + } - /** - * Set the applicable formats for this block to all - * @return array - */ - function applicable_formats() - { - return array('course' => true); - } - - /** - * Allow the user to configure a block instance - * @return bool Returns true - */ - function instance_allow_config() - { - return true; - } - - function has_config() - { - return true; - } - - public function get_content() - { - global $CFG; - global $COURSE; - global $USER; - - if ($this->content !== null) { - return $this->content; - } - if (empty($this->config)) { - $this->config = new stdClass(); - } - - $this->content = new stdClass; - $this->content->text = ""; - 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 .= '<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>'; - // 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 .= '<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_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 { - $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>'; - } + /** + * Set the applicable formats for this block to all + * @return array + */ + function applicable_formats() + { + return array('course' => true); + } + + /** + * Allow the user to configure a block instance + * @return bool Returns true + */ + function instance_allow_config() + { + return true; + } + + function has_config() + { + return true; + } + + public function get_content() + { + global $CFG; + global $COURSE; + global $USER; + + if ($this->content !== null) { + return $this->content; + } + if (empty($this->config)) { + $this->config = new stdClass(); + } + + $this->content = new stdClass; + $this->content->text = ""; + 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 .= '<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>'; + // 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 .= '<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_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 { + $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(); - // $competences = $competenceI->get_competencies_by_userID($USER->id); - // $nb_ok = 0; - // $nb_total = count($competences); - // foreach ($competences as $comp) { - // if ($comp->proficiency == 1) { - // $nb_ok++; - // } - // } - // // $this->content->text .= "<p></p>"; - // if ($nb_total > 0) { - // $progress_percentage = ceil($nb_ok*100/$nb_total); - // $this->content->text .= " - // <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> - // "; - // } else { - // $progress_percentage = 0; - // $this->content->text .= " - // <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> - // "; - // } - - return $this->content; - } - } + // $competenceI = new block_competency_iena_competency(); + // $competences = $competenceI->get_competencies_by_userID($USER->id); + // $nb_ok = 0; + // $nb_total = count($competences); + // foreach ($competences as $comp) { + // if ($comp->proficiency == 1) { + // $nb_ok++; + // } + // } + // // $this->content->text .= "<p></p>"; + // if ($nb_total > 0) { + // $progress_percentage = ceil($nb_ok*100/$nb_total); + // $this->content->text .= " + // <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> + // "; + // } else { + // $progress_percentage = 0; + // $this->content->text .= " + // <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> + // "; + // } + + return $this->content; + } - ?> \ No newline at end of file + + +} +?> \ No newline at end of file diff --git a/classes/observer.php b/classes/observer.php new file mode 100644 index 0000000000000000000000000000000000000000..359dc7046be468c28275382c0cc680cbb2e73a4c --- /dev/null +++ b/classes/observer.php @@ -0,0 +1,21 @@ +<?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, ); + } +} diff --git a/db/events.php b/db/events.php new file mode 100644 index 0000000000000000000000000000000000000000..434eba2bc204074b11f3750f165edffa4fbfe469 --- /dev/null +++ b/db/events.php @@ -0,0 +1,15 @@ +<?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 diff --git a/lib.php b/lib.php new file mode 100644 index 0000000000000000000000000000000000000000..fe13a6e345434de8c11529da3988c5af3e4fdafd --- /dev/null +++ b/lib.php @@ -0,0 +1,32 @@ +<?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