Select Git revision
-
Tobias Reischmann authoredTobias Reischmann authored
semester_date.php 5.37 KiB
<?php
//start HsH
// #### Start - Change From Beuth-Hochschule M.E. ID=07_04 ####
// Functions from block_sem_course_overview to sort the courses in the navigation (my courses)
// This function returns the semester to a given date.
function getSem($startDate, $short = true) {
global $coc_config;
$coc_config = get_config('block_course_overview_campus');
$startYear = date("Y",$startDate);
$startMonth = date("n",$startDate);
if($short)
$type = 'short';
else
$type = 'long';
if($startYear <= "2000")
return get_string('morethanone','local_hsh');
if($startMonth <= "2")
{
$startYear = $startYear-1;
$startMonth = 9;
}
if($startMonth >= "9")
{
$startSem = $coc_config->term2name.' ';
$startSem.=$startYear;
$startSem.="/";
$startSem.=substr($startYear+1,2,2);
}
else
{
$startSem = $coc_config->term1name.' '.$startYear;
}
return $startSem;
}
// This function gives the first day of a semester
function getFirstDayOfSem($startDate) {
$startYear = date("Y",$startDate);
$startMonth = date("n",$startDate);
if($startYear <= "2000")
return "0";
// #### Start - Change from Beuth-Hochschule M.E. ID=07_05 ####
// Start Month is March and not April. March is summerterm.
// if($startMonth <= "3") { // original
if($startMonth < "2") {
// #### End - Change From Beuth-Hochschule M.E. ID=07_05 ####
$startYear = $startYear-1;
$startMonth = "9";
}
elseif($startMonth >= "9") {
$startMonth = "9";
}
else {
$startMonth = "3";
}
return mktime(0, 0, 0, $startMonth, 1, $startYear);
}
//returns Parent-Root-Node of the course
function getSemesterNode($rootNode, $course) {
global $PAGE;
$startday = getFirstDayOfSem($course->startdate);
$parent = $rootNode->find($startday,navigation_node::TYPE_ROOTNODE);
if(!$parent) {
$text = getSem($startday);
$parent = $rootNode->add($text, null, navigation_node::TYPE_ROOTNODE, $text, $startday);
if ($startday == getFirstDayOfSem(strtotime('first day of this month', time()))) {
$parent->force_open();
$parent->collapse = false;
$parent->parent->collapse = false;
}
}
// $parent->parent = $rootNode;
return $parent;
}
function courseSort(&$mycourses, $sortByShortName = true ) {
if ( ! function_exists('cmp_course_short') ) {
function cmp_course_short($a, $b) {
$startA = getFirstDayOfSem($a->startdate);
$startB = getFirstDayOfSem($b->startdate);
if ($startA == $startB) {
return strcmp($a->shortname,$b->shortname);
}
return ($startA > $startB) ? -1 : 1;
}
}
if ( ! function_exists('cmp_course_lang') ) {
function cmp_course_lang($a, $b) {
$startA = getFirstDayOfSem($a->startdate);
$startB = getFirstDayOfSem($b->startdate);
if ($startA == $startB) {
return strcmp($a->fullname,$b->fullname);
}
return ($startA > $startB) ? -1 : 1;
}
}
if($sortByShortName)
usort($mycourses, "cmp_course_short");
else
usort($mycourses, "cmp_course_lang");
}
//end HsH
class SemesterTitle
{
public $correct_title;
public $startDate;
public $coc_config;
// This function returns the semester to a given date.
function getSem()
{
global $coc_config;
$coc_config = get_config('block_course_overview_campus');
#echo "StartDate: ".$this->startDate."\n";
$startYear = date("Y", $this->startDate);
$startMonth = date("n", $this->startDate);
if ($startMonth <= "2") {
$startYear = $startYear - 1;
$startMonth = 9;
}
if ($startMonth >= "9") {
$startSem = $coc_config->term2name . " ";
$startSem .= $startYear;
$startSem .= "/";
$startSem .= substr($startYear + 1, 2, 2);
} else {
$startSem = $coc_config->term1name . " " . $startYear;
}
return $startSem;
}
/**
* @param $short switch between only the number "14" or "14/15" for the shortcut or
/* the long version "WiSe 2014/15" or "SoSe 14"
* @return array with 3 parts
*/
function run($short)
{
$this->startDate = strtotime('first day of this month', time());
$array = array();
//switch between only the number "14" or "14/15" for the shortcut or
//the long version "WiSe 2014/15" or "SoSe 14"
$tmp_part = $this->getSem();
$this->startDate = strtotime('first day of +6 months');
$tmp_part2 = $this->getSem();
$this->startDate = strtotime('first day of +12 months');
$tmp_part3 = $this->getSem();
if ($short) {
$tmp_part = preg_split("/[\s]/",$tmp_part);
$tmp_part2 = preg_split("/[\s]/",$tmp_part2);
$tmp_part3 = preg_split("/[\s]/",$tmp_part3);
$array = array(substr($tmp_part[1], 2), substr($tmp_part2[1], 2), substr($tmp_part3[1], 2));
} else {
$array = array($tmp_part, $tmp_part2, $tmp_part3);
}
return $array;
}
function getShortened($long){
$long = preg_split("/[\s]/",$long);
return substr($long[0], 2);
}
}
?>