block_career.php 3.17 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
<?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()
	{
Thomas Fradet's avatar
Thomas Fradet committed
55
		global $CFG, $COURSE, $DB, $USER;
Thomas Fradet's avatar
Thomas Fradet committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
		
		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;
		
Thomas Fradet's avatar
Thomas Fradet committed
71
		$this->content->text = '';
Thomas Fradet's avatar
Thomas Fradet committed
72
		$this->content->text .= '<div class="list-group career-list-group font-weight-light">';
Thomas Fradet's avatar
Thomas Fradet committed
73

Thomas Fradet's avatar
Thomas Fradet committed
74
		$this->content->text .= '<a href="' . $CFG->wwwroot . '/course/view.php?id=' . $COURSE->id . '"  class="list-group-item list-group-item-success list-group-item-action" style="border-top-left-radius: .15rem; border-top-right-radius: .15rem; border-top: none;">Accueil du cours</a>';
Thomas Fradet's avatar
Thomas Fradet committed
75
76
77
78
79
80
81
82
83
84
85
86
87
		
		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 = "";
			}
			
Thomas Fradet's avatar
Thomas Fradet committed
88
			$this->content->text .= "<a href='" . $CFG->wwwroot . "/blocks/career/career_unit.php?career=" . $value->id . "' class='list-group-item list-group-item-action $active'>$value->name</a>";
Thomas Fradet's avatar
Thomas Fradet committed
89
90
91
92
			// $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>";
		}
		
Thomas Fradet's avatar
Thomas Fradet committed
93
		if (has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id)) {
Thomas Fradet's avatar
Thomas Fradet committed
94
			$this->content->text .= '<a href="' . $CFG->wwwroot . '/blocks/career/career_list.php?courseid=' . $COURSE->id . '" " class="list-group-item list-group-item-primary list-group-item-action" style="border-bottom-left-radius: .15rem; border-bottom-right-radius: .15rem; border-bottom: none;">Gérer les parcours</a>';
Thomas Fradet's avatar
Thomas Fradet committed
95
96
		}

Thomas Fradet's avatar
Thomas Fradet committed
97
98
99
100
101
102
103
104
105
106
107
108
109
		$this->content->text .= '</div>';
		
		if (empty($request)) {
			$this->content->text .= "<p>" . get_string('any_carrer', 'block_career') . "</p>";
		}
		
		// $this->content->text .= "<p></p>";
		
		return $this->content;
	}
}

?>