-
Thomas Fradet authoredThomas Fradet authored
block_career_section.php 2.18 KiB
<?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 static 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;
}
}