Maintenance Gitlab - Jeudi 09 Décembre 2021 à partir de 10h - Mises à jour de sécurité

block_competency_iena.php 3.4 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
17
18
19
20
21
22
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
<?php

require_once('entity/block_competency_iena_competency.php');

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;
	}

	/**
		 * 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;
			if (has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id)) {
				$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_mgmt.php?courseid=' . $COURSE->id . '" type="button " class="btn btn-success 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.php?courseid=' . $COURSE->id . '"  class="btn btn-primary w-100 mb-3">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);
			// var_dump($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>
				";
			}
			// $this->content->text .= "
			// <div class=\"thermo\">
			// <div class=\"round_thermo\">
			// <span class=\"text_round_thermo\">
			// $nb_ok/$nb_total
			// </span>
			// </div>
			// <div class=\"thermo_bar\">
			// <progress class=\"progress\" max=\"$nb_total\" value=\"$nb_ok\"></progress>
			// </div>
			// </div>
			// ";
			
			
			return $this->content;
		}
	}

	?>