Commit eca94a7a authored by Myriam Delaruelle's avatar Myriam Delaruelle
Browse files

Fin template matrice+modale

parent b4d05c40
......@@ -13,6 +13,8 @@
global $COURSE, $DB, $CFG;
echo "COURSE ID";
echo $COURSE->id;
$courseid = required_param('courseid', PARAM_INT);
......@@ -24,7 +26,8 @@
if ($_POST) {
if ($_POST['info'][0] == "delete_cpt") {
$module_id = htmlspecialchars($_POST['info'][1]);
//$module_id = htmlspecialchars($_POST['info'][1]);
$module_id=$courseid;
$cpt_id = htmlspecialchars($_POST['info'][2]);
$cpt_api = new \core_competency\api();
......@@ -42,7 +45,6 @@
$data_exist = $DB->get_record_sql('select count(*) AS count FROM {competency_modulecomp} WHERE cmid=? AND competencyid =?', array($module_id, $competency_id));
} catch (dml_exception $e) {
}
//var_dump($data_exist);
if ($data_exist->count > 0) {
//$DB->get_record_sql(' delete FROM {competency_modulecomp} WHERE cmid=? AND competencyid =?' , array($module_id, $competency_id));
try {
......@@ -121,17 +123,124 @@
exit;
}
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
require_login($course, false, NULL);
$PAGE->set_title(get_string('title_plugin', 'block_competency_iena'));
$PAGE->set_heading($OUTPUT->heading($COURSE->fullname, 2, 'headingblock header outline'));
echo $OUTPUT->header();
$PAGE->requires->js(new \moodle_url('https://code.jquery.com/jquery-3.3.1.min.js'),true);
$PAGE->requires->js(new \moodle_url('https://cdn.datatables.net/1.10.16/js/jquery.dataTables.js'),true);
$PAGE->requires->js(new \moodle_url('https://cdn.datatables.net/select/1.2.5/js/dataTables.select.min.js'),true);
$PAGE->requires->js(new \moodle_url('https://cdn.datatables.net/buttons/1.5.1/js/dataTables.buttons.min.js'),true);
$PAGE->requires->js(new \moodle_url('https://cdn.datatables.net/fixedcolumns/3.2.4/js/dataTables.fixedColumns.min.js'),true);
$PAGE->requires->css(new \moodle_url('https://cdn.datatables.net/1.10.16/css/jquery.dataTables.css'));
$PAGE->requires->js("/blocks/competency_iena/js/file.js");
$PAGE->requires->js("/blocks/competency_iena/js/matrix.js");
/* Compétences*/
$competency_instance = new block_competency_iena_competency();
$competencies = $competency_instance->get_competencies_by_courseID($courseid);
foreach ($competencies as $competency) {
$competency->link = $CFG->wwwroot . "/blocks/competency_iena/competency_iena_user.php?courseid=" . $courseid . "&competencyid=" . $competency->id;
}
$module_instance = new block_competency_iena_module();
$modules = $module_instance->get_modules_by_courseID($courseid);
$section_instance = new block_competency_iena_section();
$sections = $section_instance->get_sections_by_id_course($courseid);
$index=0;
//Pour chaque section on va regarder s'il y a des modules, et si oui on formate et on ajoute les modules à la section
foreach ($sections as $section) {
$section->modules=array();
foreach ($modules as $module) {
if($module->sectionid == $section->id){
$moduleI = new block_competency_iena_ressource();
$moduleI->get_ressource_by_id($module->moduleid);
$module->link=$moduleI->link;
$module_competencies = $competency_instance->get_competencies_by_moduleID($module->moduleid);
$module->mcompetencies=array();
foreach ($competencies as $competency) {
$key=array_search($competency->id, array_column($module_competencies, 'id'));
if($key !== false){
array_push($module->mcompetencies, $module_competencies[$key]);
}
else{
array_push($module->mcompetencies, $competency);
}
}
array_push($section->modules,$module);
}
}
if ( $section->name == NULL ) {
$section->name = "Section " . $section->section;
}
if(count($section->modules)==0){
unset($sections[$index]);
}
$index++;
}
//Comme on a unset, on réindexe le tableau pour des clés propres
$sections=array_values($sections);
//Pour les référentiels
$refI = new block_competency_iena_referentiel();
$frameworks = $refI->get_referentiels_all();
foreach ($frameworks as $framework) {
//$ordered_competencies=$ordered_competencies + $refI->get_competences_order_by_ref($framework->id);
if(isset($ordered_competencies)){
$ordered_competencies=array_merge($ordered_competencies, $refI->get_competences_order_by_ref($framework->id));
}
else{
$ordered_competencies=$refI->get_competences_order_by_ref($framework->id);
}
}
echo $OUTPUT->header();
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\">";
$view = new view_competency_iena_competencies_mgmt();
echo $view->get_content(htmlspecialchars($courseid));
//$view = new view_competency_iena_competencies_mgmt();
//echo $view->get_content(htmlspecialchars($courseid));
$data=array();
$data['competencies']=$competencies;
//$data['modules']=$modules;
$data['sections']=$sections;
$data['frameworks']=array_values($frameworks);
$data['ordered_competencies']=$ordered_competencies;
$data['form_link']= $CFG->wwwroot . "/blocks/competency_iena/competency_iena_competency_mgmt.php?courseid=" . $COURSE->id;
$data['update_link']=$CFG->wwwroot . '/blocks/competency_iena/competency_iena_competencies_api.php?courseid=' . $COURSE->id;
$data['courseid']=$COURSE->id;
//$link = $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competency_mgmt.php?courseid=' . $COURSE->id;
$renderer = $PAGE->get_renderer('block_competency_iena');
$renderer->get_competency_matrix($data);
echo $OUTPUT->footer();
......@@ -252,6 +252,7 @@ list_evidence_in_course
return $competencies;
}
//Ici ça pose problème avec le new renderer base ?
public function get_data($userID, $competenceId, $courseID)
{
global $CFG;
......@@ -282,5 +283,17 @@ list_evidence_in_course
return $value;
}
public function export_for_template(renderer_base $output) {
$data = new stdClass();
$data->id = $this->id;
$data->shortname=$this->shortname;
$data->description=$this->description;
$data->students=$this->students;
$data->student_proficiency=$this->student_proficiency;
$data->student_grade=$this->student_grade;
$data->module_ruleoutcome=$this->module_ruleoutcome;
$data->module_ruleoutcomestring=$this->module_ruleoutcomestring;
return $data;
}
}
......@@ -17,7 +17,9 @@ class block_competency_iena_module {
public function get_module_by_id($id_module)
{
global $COURSE;
$modinfo = get_fast_modinfo($COURSE->id);
foreach ($modinfo->get_cms() as $module)
{
if($module->id == $id_module)
......
......@@ -163,37 +163,46 @@
if ($competence->parentid == 0) {
$object = new block_competency_iena_referentiel();
$object->fill(1, null, $competence);
$object->frameworkid=$refid;
array_push($lvlOne, $object);
}
}
foreach ($lvlOne as $one) {
$lvlTwo = array();
$one->has_children=false;
foreach ($competences as $competence) {
if ($one->competency->id == $competence->parentid) {
$object = new block_competency_iena_referentiel();
$object->fill(2, null, $competence);
array_push($lvlTwo, $object);
$one->has_children=true;
}
}
$one->children = $lvlTwo;
foreach ($one->children as $two) {
$two->has_children=false;
$lvlTree = array();
foreach ($competences as $competence) {
if ($two->competency->id == $competence->parentid) {
$object = new block_competency_iena_referentiel();
$object->fill(3, null, $competence);
array_push($lvlTree, $object);
$two->has_children=true;
}
}
$two->children = $lvlTree;
foreach ($two->children as $tree) {
$tree->has_children=false;
$lvlFour = array();
foreach ($competences as $competence) {
if ($tree->competency->id == $competence->parentid) {
$object = new block_competency_iena_referentiel();
$object->fill(4, null, $competence);
array_push($lvlFour, $object);
$tree->has_children=true;
}
}
$tree->children = $lvlFour;
......
......@@ -12,10 +12,10 @@ function filter() {
}
function updateTextComp(value, idcourse,wwwroot){
function updateTextComp(value, url){
// console.log(value);
$.ajax({
url: wwwroot+'/blocks/competency_iena/competency_iena_competencies_api.php?courseid='+idcourse,
url: url,
type: 'POST',
timeout: 10000,
contentType: 'application/x-www-form-urlencoded',
......@@ -31,17 +31,16 @@ function updateTextComp(value, idcourse,wwwroot){
});
}
function updateTextRef(value, idcourse,wwwroot) {
function updateTextRef(value, url) {
// console.log(value);
$.ajax({
url: wwwroot + '/blocks/competency_iena/competency_iena_competencies_api.php?courseid=' + idcourse,
url:url,
type: 'POST',
timeout: 10000,
contentType: 'application/x-www-form-urlencoded',
data: {idref: value},
success: function (result) {
var json_res = JSON.parse(result);
// console.log(json_res.id);
$('#btn-comp-iena').attr('disabled', 'disabled');
$('#name_ref_iena').html(json_res.shortname);
$('#desc_ref_iena').html(json_res.description);
......
jQuery(document).ready(function($){
$.noConflict();
$('#tab_mgmt').DataTable({
responsive: true,
"language": {
"url": "https://cdn.datatables.net/plug-ins/1.10.16/i18n/French.json"
},
"bSort": false,
scrollCollapse: true,
fixedColumns: {
leftColumns: 1
},
'bFilter': false,
'bInfo': false
});
$('.fram-iena').hide();
// $('#btn-comp-iena').hide();
$( '#select-framework' ).on( 'change', function () {
$('.fram-iena').hide();
$('.fram-'+$(this).val()).show();
});
/*$('#btn-comp-iena').click(function(){
var idcomp = $('#id-comp-iena').val();
var idcourse = $('#id-course-iena').val();
var value = [];
value[0] = idcomp;
value[1] = idcourse;
$.ajax({
url: '$CFG->wwwroot/blocks/competency_iena/competency_iena_competencies_api.php?courseid='+idcourse,
type: 'POST',
timeout: 10000,
contentType: 'application/x-www-form-urlencoded',
data: {addcomp:value},
success: function(result) {
if (result.trim() == "true"){
location.reload();
} else {
alert('Cette compétence est déja liée au cours.');
}
}
});
});*/
$('#filter-iena-competence').keyup(function(){
var searchText = $(this).val();
$('ul > li').each(function(){
var reg = new RegExp(searchText, 'gi');
var currentLiText = $(this).text();
var showCurrentLi = reg.test(currentLiText);
if (searchText){
$(this).toggle(showCurrentLi);
} else {
$(this).hide(showCurrentLi);
$('#fram-'+$( '#select-framework' ).val()).show();
}
});
});
function treed(o){
var openedClass = 'glyphicon-minus-sign';
var closedClass = 'glyphicon-plus-sign';
if (typeof o != 'undefined'){
if (typeof o.openedClass != 'undefined'){
openedClass = o.openedClass;
}
if (typeof o.closedClass != 'undefined'){
closedClass = o.closedClass;
}
};
//initialize each of the top levels
var tree = $('#tree3');
tree.addClass("tree");
tree.find('li').has("ul").each(function () {
var branch = $(this); //li with children ul
branch.prepend("<i class='indicator fa " + closedClass + "'></i>");
branch.addClass('branch');
branch.on('click', function (e) {
if (this == e.target) {
var icon = $(this).children('i:first');
icon.toggleClass(openedClass + " " + closedClass);
$(this).children().children().toggle();
}
})
branch.children().children().toggle();
});
//fire event from the dynamically added icon
tree.find('.branch .indicator').each(function(){
$(this).on('click', function () {
$(this).closest('li').click();
});
});
//fire event to open branch if the li contains an anchor instead of text
tree.find('.branch>a').each(function () {
$(this).on('click', function (e) {
$(this).closest('li').click();
e.preventDefault();
});
});
//fire event to open branch if the li contains a button instead of text
tree.find('.branch>button').each(function () {
$(this).on('click', function (e) {
$(this).closest('li').click();
e.preventDefault();
});
});
}
treed({openedClass:'fa-caret-down', closedClass:'fa-caret-right'});
});
function showFilter(obj){
var p = obj.parentNode;
var c = p.children;
if (c[2].dataset.edit == 'editOn') {
c[0].setAttribute("style", "display:inline");
c[1].setAttribute("style", "display:none");
c[2].dataset.edit = 'editOff';
} else {
c[0].setAttribute("style", "display:none");
c[1].setAttribute("style", "display:inline");
c[2].dataset.edit = 'editOn';
}
// console.log(c)
// c[2].setAttribute("style", "display:none");
}
function addCompetencies(url){
var idcomp = $('#id-comp-iena').val();
var idcourse = $('#id-course-iena').val();
var value = [];
value[0] = idcomp;
value[1] = idcourse;
$.ajax({
url: url,
type: 'POST',
timeout: 10000,
contentType: 'application/x-www-form-urlencoded',
data: {addcomp:value},
success: function(result) {
if (result.trim() == "true"){
location.reload();
} else {
alert('Cette compétence est déja liée au cours.');
}
}
});
}
function supprimer_lien(obj) {
var t = obj.parentNode;
var p = t.parentNode;
var c = p.children;
c[0].setAttribute("style", "display:none");
c[1].setAttribute("style", "display:none");
c[2].setAttribute("style", "display:inline");
// console.log(c[0]);
var div_id = c[0].id;
// console.log(div_id);
var module_id = div_id.split('-')[0];
module_id = module_id.replace ( /[^\d.]/g, '' );
var competency_id = div_id.split('-')[1];
competency_id = competency_id.replace ( /[^\d.]/g, '' );
var url = window.location.href;
// console.log(url);
var info = [];
info[0] = module_id ;
info[1] = competency_id ;
info[2] = "delete" ;
// console.log(info);
$.ajax({
type: "POST",
data: {info:info},
url: url,
timeout: 10000,
contentType: 'application/x-www-form-urlencoded',
success: function (data, status) {
if (status == "success") {
// console.log(status);
// console.log(data);
//changeColor(p);
}
},
error: function (xhr, status, error) {
alert(status);
}
});
}
function supprimer_lien_cpt(cpt_id) {
var res = window.confirm('Etes-vous sûr de vouloir supprimer cette compétence de ce cours ?');
if (res) {
var info = [];
info[0] = "delete_cpt" ;
info[1] = "7" ;
info[2] = cpt_id ;
$.ajax({
type: "POST",
data: {info:info},
url: window.location.href,
timeout: 10000,
contentType: 'application/x-www-form-urlencoded',
success: function (data, status) {
if (status == "success" && data != false) {
location.reload()
}
},
error: function (xhr, status, error) {
alert(status);
}
});
}
}
function select_update(obj){
var t = obj.parentNode;
var p = t.parentNode;
var c = p.children;
c[0].setAttribute("style", "display:inline");
c[1].setAttribute("style", "display:none");
c[2].setAttribute("style", "display:inline");
c[2].dataset.edit = 'editOff';
var tab0_elem = c[1].children;
var select = tab0_elem[0];
var choix_ruleoutcome =select.value;
var select_id =select.id;
var module_id = select_id.split('-')[0];
module_id = module_id.replace ( /[^\d.]/g, '' );
var competency_id = select_id.split('-')[1];
competency_id = competency_id.replace ( /[^\d.]/g, '' );
var url = window.location.href;
var info = [];
info[0] = module_id ;
info[1] = competency_id ;
info[2] = choix_ruleoutcome ;
$.ajax({
type: "POST",
data: {info:info},
url: url,
timeout: 10000,
contentType: 'application/x-www-form-urlencoded',
success: function (data, status) {
if (status == "success"){
var renderer = data.split("/")[1];
var switchColor = data.split("/")[0];
/*if (!(switchColor.trim() == "update")){
changeColor(p);
}*/
var div_id = c[0].id;
document.getElementById(div_id).firstChild.nextSibling.textContent = renderer;
}
},
error: function (xhr, status, error)
{
alert(status);
}
});
}
function changeColor(obj)
{
// if (obj.getAttibute('class').indexOf('text-success') > -1) {
// obj.setAttibute('class', 'text-success');
// } else {
// obj.setAttibute('class', obj.getAttibute('class').replace('text-success', ''));
// }
// newColor = (obj.getAttibute('class').indexOf('text-success') > -1) ? '#28afa3' : '';
// obj.style.backgroundColor = newColor;
}
<?php
/*
* @package block_career
*/
class block_competency_iena_renderer extends plugin_renderer_base {
function get_career_list(){
global $DB, $CFG, $COURSE, $USER;
if (!has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id)) {
$link = $CFG->wwwroot . '/course/view.php?id=' . $COURSE->id;
header("Location: {$link}");
exit;
}
$listtitle=get_string('list_title', 'block_career');
$headingplugin=get_string('heading_plugin', 'block_career');
$addpath=get_string('add_path', 'block_career');
$path=$CFG->wwwroot.'/blocks/career/career_setting.php?courseid='.$COURSE->id;
$request = $DB->get_records_sql('SELECT * FROM {block_career} WHERE course = ?', array($_GET["courseid"]));
$courseid=$_GET['courseid'];
$careerlist=array();
if (empty($request)) {
$emptycareer=get_string('any_carrer', 'block_career');