block_career.php 2.79 KB
Newer Older
Thomas Fradet's avatar
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
106
107
108
109
<?php

/**
 * block_career
 *
 *
 * @package    block_career
 * @category   block
 * @copyright  2018 Softia/Université lorraine
 * @author     vrignaud camille/ faouzi / Thomas Fradet
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

class block_career extends block_base
{
	/**
	 *
	 */
	public function init()
	{
		$this->title = get_string('title_plugin', 'block_career');
	}
	
	/**
	 * @return bool
	 */
	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 stdClass
	 */
	public function get_content()
	{
		global $CFG;
		global $COURSE;
		global $DB;
		
		if ($this->content !== null) {
			return $this->content;
		}
		if (empty($this->config)) {
			$this->config = new stdClass();
		}
		
		$request = $DB->get_records_sql('SELECT * FROM {block_career} WHERE course = ?', array($COURSE->id));
		// var_dump($request);
		$careerId = optional_param("career", NULL, PARAM_INT);
		$active = "";
		
		$this->content = new stdClass;
		$this->content->text .= '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $COURSE->id . '"  class="btn btn-success btn-career-block mb-3">Accueil du cours</a>';
		
		// $image = "";
		
		$this->content->text .= '<div class="list-group">';
		
		foreach ($request as $value) {
			
			// if (file_get_contents("$CFG->wwwroot/blocks/career/$value->image") != null) {
			// 	$image = "<img src='$CFG->wwwroot/blocks/career/$value->image' class='img_moodle_list'/>";
			// }
			
			if ($careerId != null && $careerId == $value->id) {
				$active = "active";
			} else {
				$active = "";
			}
			
			$this->content->text .= "<a href='" . $CFG->wwwroot . "/blocks/career/career_unit.php?career=" . $value->id . "' class='list-group-item $active'>$value->name</a>";
			// $this->content->text .= "<a href='" . $CFG->wwwroot . "/blocks/career/career_unit.php?career=" . $value->id . "' class='full list-group-item list-group-item-action $active'><div class=' left img_center'>$image</div>
			// &nbsp&nbsp $value->name</a><br>";
		}
		
		$this->content->text .= '</div>';
		
		if (empty($request)) {
			$this->content->text .= "<p>" . get_string('any_carrer', 'block_career') . "</p>";
		}
		
		$this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/career/career_list.php?course=' . $COURSE->id . '" type="button " class="btn btn-primary btn-career-block mt-3">Gérer les parcours</a>';
		
		// $this->content->text .= "<p></p>";
		
		return $this->content;
	}
}

?>