block_career_section.php 2.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
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
<?php

	/**
	 * block_career_section
	 *
	 *
	 * @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_section
	{
		
		/** @var int Id of section */
		public $id;
		/** @var string name of section */
		public $name;
		/** @var int id of course */
		public $id_course;
		/** @var block_career_ressources array<Object> ressources */
		public $ressources;
		/** @var string summary */
		public $summary;
		/** @var int order of section */
		public $orde;
		/** @var string intro of section */
		public $intro;
		
		/**
		 * Set $id, $name, $id_course and $summary
		 * @param array $id_section
		 *
		 * @return void
		 */
		public function get_section_by_id_section($id_section)
		{
			global $DB;
			$requete = $DB->get_record_sql('SELECT * FROM {course_sections} WHERE id = ?', array($id_section));
			$this->id = $requete->id;
			$this->name = $requete->name;
			$this->id_course = $requete->course;
			$this->summary = $requete->summary;
			$this->orde = $requete->section;
			$this->intro = $requete->summary;
			
			if (!$this->name) {
				$this->name = "Section " . $requete->section;
			}
		}
		
		/**
		 * Get all sections in a course
		 * return a array
		 * @param array $id_course
		 *
		 * @return array<block_career_section> $sections
		 */
		public function get_sections_by_id_course($id_course)
		{

			global $DB;
			$requete = $DB->get_records_sql('SELECT * FROM {course_sections} WHERE course = ? ORDER BY section', array($id_course));
			// $numsection = $DB->get_record_sql('SELECT value FROM {course_format_options} WHERE courseid = ? AND name = ?', array($id_course,"numsections"));
			$sections = array();
			$i = 0;
			foreach ($requete as $value) {
				// if ($value->section > $numsection->value){
				// 	continue;
				// }
				$section = new block_career_section();
				$section->get_section_by_id_section($value->id);
				$sections[$i] = $section;
				$i++;
			}
			
			return $sections;

		}








		
	}