competency_iena_competencies_mgmt.php 4.55 KB
Newer Older
Thomas Fradet's avatar
folder  
Thomas Fradet committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<?php
	
	require_once('../../config.php');

// ENLEVER SI NON NECESSAIRE :
	require_once('entity/block_competency_iena_competency.php');
	require_once('entity/block_competency_iena_module.php');
	require_once('entity/block_competency_iena_ressource.php');
	require_once('entity/block_competency_iena_section.php');
	require_once('entity/block_competency_iena_student.php');
	require_once('entity/block_competency_iena_referentiel.php');
	require_once('view/view_competency_iena_competencies_mgmt.php');
	
	
	global $COURSE, $DB, $CFG;

17 18 19
	$courseid = required_param('courseid', PARAM_INT);

	$url = new moodle_url('/blocks/competency_iena/competency_iena_competencies_mgmt.php', array('courseid' => $courseid));
Thomas Fradet's avatar
folder  
Thomas Fradet committed
20 21
//$requete = $DB->get_record_sql('SELECT course FROM {block_competency_iena} WHERE id = ?', array($courseid));

22
	$PAGE->set_url($url);
Thomas Fradet's avatar
folder  
Thomas Fradet committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
	
	if ($_POST) {

		if ($_POST['info'][0] == "delete_cpt") {
			$module_id = htmlspecialchars($_POST['info'][1]);
			$cpt_id = htmlspecialchars($_POST['info'][2]);
			
			$cpt_api = new \core_competency\api();
			$cpt_list = $cpt_api->remove_competency_from_course($module_id, $cpt_id);
			echo $cpt_list;
		}
		else if ($_POST['info'][2] == "delete") {
			// Suppression du lien module - compétence dans la BDD
			
			$module_id = htmlspecialchars($_POST['info'][0]);
			$competency_id = htmlspecialchars($_POST['info'][1]);
			
			// vérification si lien module - compétence existe
			try {
				$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 {
					$DB->delete_records('competency_modulecomp', array('cmid' => $module_id, 'competencyid' => $competency_id));
				} catch (dml_exception $e) {
				}
				// vérifier si succes suppression
				echo 'true';
			} else {
				echo 'false';
			}
		} // Insert or update DB
		else {
			$module_id = htmlspecialchars($_POST['info'][0]);
			$competency_id = htmlspecialchars($_POST['info'][1]);
			$choix_ruleoutcome = htmlspecialchars($_POST['info'][2]);
			// check if link module - skill exists
			try {
				$data_exist = $DB->get_record_sql('select * FROM {competency_modulecomp} WHERE cmid=? AND competencyid =?', array($module_id, $competency_id));
			} catch (dml_exception $e) {
			}
			
			
			$date = new DateTime();
			$modulecomp_data = new stdClass();
			$modulecomp_data->cmid = $module_id;
			$modulecomp_data->competencyid = $competency_id;
			$modulecomp_data->ruleoutcome = $choix_ruleoutcome;
			$modulecomp_data->timemodified = $date->getTimestamp();
			$modulecomp_data->usermodified = $USER->id;
			
			// insert
			if (empty($data_exist)) {
				$modulecomp_data->sortorder = 0;
				$modulecomp_data->timecreated = $modulecomp_data->timemodified;
				try {
					$resultat = $DB->insert_record('competency_modulecomp', $modulecomp_data, true);
				} catch (dml_exception $e) {
				}
			} // update
			else {
				$modulecomp_data->id = $data_exist->id;
				try {
					$resultat = $DB->update_record('competency_modulecomp', $modulecomp_data, false);
				} catch (dml_exception $e) {
				}
				if ($resultat == true) {
					$resultat = "update";
				}
				
			}
			
			$response = array();
			$response[0] = $resultat;
			switch ($choix_ruleoutcome) //better with result of insert update queries
			{
				case 0:
					$response[1] = 'Ne rien faire';
					break;
				case 1:
					$response[1] = 'Joindre une preuve';
					break;
				case 2:
					$response[1] = 'Envoyer pour validation';
					break;
				case 3:
					$response[1] = 'Marquer la compétence comme atteinte';
					break;
				default:
					break;
			}
			echo $response[0] . '/' . $response[1];
			
		}
		
		exit;
	}
	
124 125 126 127 128 129 130
	$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();

Thomas Fradet's avatar
folder  
Thomas Fradet committed
131 132 133 134 135
	$PAGE->requires->js("/blocks/competency_iena/js/file.js");
	echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\">";
	
	$view = new view_competency_iena_competencies_mgmt();
	echo $view->get_content(htmlspecialchars($courseid));
136 137

	echo $OUTPUT->footer();