diff --git a/build/router/controller/ics.php b/build/router/controller/ics.php index 6ed9d09..d939bde 100644 --- a/build/router/controller/ics.php +++ b/build/router/controller/ics.php @@ -3,6 +3,7 @@ namespace router\controller; use \database\core\DatabaseDriver; + use \service\CalendarExtractor as CE; class ics{ @@ -49,6 +50,152 @@ } + public function view(){ + + /* [1] Get periods + =========================================================*/ { + + /* (1) Get the list of available periods */ + $sqlr = DatabaseDriver::getPDO()->query("SELECT * from period"); + $periods = $sqlr->fetchAll(); + + /* (2) Manage error */ + if( !$periods ) + die("Error cannot get config"); + + /* (3) Begin html */ + echo ""; + echo " ICS UPPA university"; + echo " "; + echo " "; + echo ""; + echo ""; + + } + + + /* [2] For each period (week) + =========================================================*/ { + + echo "
"; + + $cal_height = 54; // in css:vw + + foreach($periods as $period){ + + echo "
"; + + /* (1) Display week number */ + $days = [ + date('Y-m-d', strtotime($period['monday'].' + 0 days')), + date('Y-m-d', strtotime($period['monday'].' + 1 days')), + date('Y-m-d', strtotime($period['monday'].' + 2 days')), + date('Y-m-d', strtotime($period['monday'].' + 3 days')), + date('Y-m-d', strtotime($period['monday'].' + 4 days')) + ]; + echo "
Week from ${days[0]} to ${days[4]}
"; + + echo "
"; + + /* (2) For each day */ + foreach($days as $day_n=>$day){ + + /* (2.1) Display day grid */ + echo "
"; + + /* (2.2) Get available courses */ + $sqlr = DatabaseDriver::getPDO()->prepare("SELECT + DATE_FORMAT(c.start_date, '%H:%i') as startd, + DATE_FORMAT(c.stop_date, '%H:%i') as stopd, + l.basename as lbname, + l.name as lname, + e.basename as ebname, + e.name as ename, + e.color as color + FROM event as e, location as l, course as c + WHERE e.id_diplome = :idd + AND c.id_event = e.id_event + AND c.id_location = l.id_location + AND DATE_FORMAT(c.start_date, '%Y-%m-%d') = :day + ORDER BY startd ASC"); + $sqlr->execute([ + ':idd' => $this->diplome_id, + ':day' => $day + ]); + $courses = $sqlr->fetchAll(); + + /* (2.3) Manage error */ + if( !$courses ) + continue; + + /* (2.4) For each course */ + foreach($courses as $course){ + + $start_hour = 0; + $stop_hour = 0; + + /* (2.4.1) Extract time in hour */ + if( preg_match('@^(\d+):(\d+)$@', $course['startd'], $m) ) + $start_hour = $m[1] + $m[2]/60; + + if( preg_match('@^(\d+):(\d+)$@', $course['stopd'], $m) ) + $stop_hour = $m[1] + $m[2]/60; + + /* (2.4.2) Calc positionning */ + $top = ($start_hour-CE::$start_h) * $cal_height / (CE::$stop_h-CE::$start_h); + $height = ($stop_hour-CE::$start_h) * $cal_height / (CE::$stop_h-CE::$start_h) - $top; + $color = $course['color']; + + /* (2.4.3) Position
according to hours */ + echo "
"; + + echo "
".$course['startd']."
"; + echo "
".$course['stopd']."
"; + echo "
"; + echo "".$course['ename'].""; + echo "".$course['lname'].""; + echo "
"; + + echo "
"; + + + } + + + } + + echo "
"; + + } + + echo "
"; + + } + + + echo ""; + + + // echo "
"; + // echo ""; + + // foreach($d_cols as $data){ + + // $id = $data['id_event']; + // $basename = $data['basename']; + // $color = $data['color']; + // $name = $data['name']; + + // echo ""; + + // } + // echo "
Read nameCorrection
$basename
"; + + // echo ""; + + // echo "
"; + + } public function lessons(){ diff --git a/build/router/controller/page.php b/build/router/controller/page.php index 2d3d90c..deee199 100644 --- a/build/router/controller/page.php +++ b/build/router/controller/page.php @@ -41,7 +41,7 @@ /* [2] Display the links =========================================================*/ - echo ""; + echo "
DiplomeLessons' nameLocationLinkLast Update
"; foreach($diplomes as $id=>$data){ @@ -66,6 +66,12 @@ if( file_exists($link) ) echo " href='/ics/$id.ics'"; + // link to view + echo ""; + echo ""; diff --git a/build/service/CalendarExtractor.php b/build/service/CalendarExtractor.php index 7fa8ab2..ce83030 100644 --- a/build/service/CalendarExtractor.php +++ b/build/service/CalendarExtractor.php @@ -21,8 +21,8 @@ =========================================================*/ public static $start_y = 79; // start y public static $stop_y = 699; // stop y - public static $start_h = 8; // start hour - public static $stop_h = 20; // stop hour + public static $start_h = 6; // start hour (GMT) + public static $stop_h = 18; // stop hour (GMT) @@ -52,7 +52,7 @@ throw new \Exception("CalendarExtractor.__construct(, , ) received but cannot reach "); /* (3) Check @start_d format */ - if( !preg_match("@^\d{1,2}-\d{1,2}-\d{3,}$@", $start_d) ) + if( !preg_match("@^\d{3,}-\d{1,2}-\d{1,2}$@", $start_d) ) throw new \Exception("CalendarExtractor.__construct(, , ) received has not the correct format"); /* (4) Check @d_uid format */ @@ -158,13 +158,14 @@ // {1} calculate time // $start_y = $y; - $time = $this->yToTime($day_n, $start_y); + $time_start = $this->yToTime($day_n, $start_y); + $date_start = date('Ymd\THis\Z', $time_start); // {2} Incr uid // $uid++; // {3} Store event start // - $this->event[$uid][$time] = []; + $this->event[$uid][$date_start] = []; // {4} Seek end of event // $y++; @@ -173,10 +174,11 @@ // {5} If end reached // - $this->event[$uid][$time] = [ $this->yToTime($day_n, $y) ]; + $time_stop = $this->yToTime($day_n, $y); + $this->event[$uid][$date_start] = [ date('Ymd\THis\Z', $time_stop) ]; // {6} Exctract event's image // - $ev = $this->extractEvent("$time-$uid", [$col_x, $start_y+1], [$col_ind[$day_n+1]-1, $y]); + $ev = $this->extractEvent("$date_start-$uid", [$col_x, $start_y+1], [$col_ind[$day_n+1]-1, $y]); /* {7} Check @event if already exists */ { @@ -226,8 +228,35 @@ } + /* (9) Check @course if already exists */ { + + $date = [ + 'start' => date('Y-m-d H:i:s', $time_start), + 'stop' => date('Y-m-d H:i:s', $time_stop) + ]; + + $sqlr = DatabaseDriver::getPDO()->prepare("SELECT c.id_course as idc FROM course as c, event as e, location as l WHERE c.id_event = e.id_event AND c.id_location = l.id_location AND e.name = :ename AND l.name = :lname AND e.id_event = :ide AND l.id_location = :idl AND c.start_date = :startd AND c.stop_date = :stopd"); + $sqlr->execute([ ':ename' => $read_name, ':lname' => $read_location, ':ide' => $event_id, ':idl' => $location_id, ':startd' => $date['start'], ':stopd' => $date['stop'] ]); + $fetched = $sqlr->fetch(); + + // {8.1} If not found in db -> insert // + if( !$fetched ){ + + // {8.2} Insert new location // + $sqlr = DatabaseDriver::getPDO()->prepare("INSERT INTO course(id_course,id_event,id_location,start_date,stop_date) VALUES(DEFAULT,:ide,:idl,:startd,:stopd)"); + $sqlr->execute([ ':ide' => $event_id, ':idl' => $location_id, ':startd' => $date['start'], ':stopd' => $date['stop'] ]); + + // {8.3} Store id in current location // + $course_id = DatabaseDriver::getPDO()->lastInsertId(); + + + }else + $course_id = $fetched['idc']; + + } + /* (9) Store local data for ics */ - $this->event[$uid][$time][1] = $location_id; + $this->event[$uid][$date_start][1] = $location_id; } @@ -352,7 +381,7 @@ * @day_n Day relative index * @y y Coordinate * - * @return time Formatted time (HH:mm) + * @return time GMT timestamp * ---------------------------------------------------------*/ private function yToTime($day_n, $y){ @@ -394,13 +423,13 @@ /* [3] Convert to GMT (UTC+0) =========================================================*/ /* (1) Set fixed timezone offset */ - $tz_offset = +2; + // $tz_offset = +2; /* (2) Get GMT (UTC+0) timestamp */ - $ts = strtotime("${day} $hour:$min:00") - (3600*$tz_offset); + $ts = strtotime("${day} $hour:$min:00"); /* (3) Return GMT date */ - return date("Ymd\THis\Z", $ts); + return $ts; } diff --git a/build/service/Config.php b/build/service/Config.php index ae42ef6..1d1a087 100644 --- a/build/service/Config.php +++ b/build/service/Config.php @@ -159,7 +159,7 @@ $month = self::monthAsso()[ $m[2] ]; // {3} Get monday date // - $mon = date( 'd-m-Y', strtotime("${m[1]}-$month-${m[3]} - 5 days") ); + $mon = date( 'Y-m-d', strtotime("${m[3]}-$month-${m[1]} - 5 days") ); // {4} Register into the list // $p_list[ "S${m[4]}" ] = $mon; @@ -279,8 +279,6 @@ } - - /* [2] Return the instance =========================================================*/ return new Config($d_list, $p_list); diff --git a/config/routes.json b/config/routes.json index 25d7000..0806131 100644 --- a/config/routes.json +++ b/config/routes.json @@ -28,6 +28,14 @@ } }, + "/view/{diplome_id}": { + "methods": ["GET"], + "controller": "ics:view", + "arguments": { + "diplome_id": "T\\d+" + } + }, + "/lessons/{diplome_id}": { "methods": ["GET"], "controller": "ics:lessons", diff --git a/public_html/css/layout.css b/public_html/css/layout.css new file mode 100644 index 0000000..551f016 --- /dev/null +++ b/public_html/css/layout.css @@ -0,0 +1,110 @@ +body{ + font-family: 'Lato', 'Open Sans'; + font-size: 16px; +} + +div.null{ + display: none; +} + + +div.period{ + display: block; + position: relative; + left: 10vw; + margin-top: 10vw; + + width: 80vw; + height: 54vw; + + background: red; + border: 1px solid black; +} + +div.period > .title{ + display: inline-block; + position: absolute; + margin-top: -1.2em; + left: 50%; + + transform: translateX(-50%); + + font-size: 1.2em; +} + +div.period > [class^=d]{ + display: block; + position: absolute; + top: 0; + left: 0; + + width: calc( 80vw / 5 - 1px ); + height: 100%; + + border-right: 1px solid black; + + background-color: #F8F8F8; +} + +div.period > .d1{ + left: 20%; +} + +div.period > .d2{ + left: 40%; +} + +div.period > .d3{ + left: 60%; +} + +div.period > .d4{ + left: 80%; + border-right: none; + width: calc( 80vw / 5 ); +} + +div.period > [class^=d] > .course{ + display: block; + position: absolute; + top: 0; + left: 0; + + width: 100%; + height: 0; + + font-size: 1.2vw; +} + +div.period > [class^=d] > .course > .start{ + display: inline-block; + position: absolute; + top: 1px; + left: 1px; +} + +div.period > [class^=d] > .course > .stop{ + display: inline-block; + position: absolute; + bottom: 1px; + right: 1px; +} + +div.period > [class^=d] > .course > .container{ + display: flex; + position: absolute; + top: 0; + left: 0; + + width: 100%; + height: 100%; + + flex-direction: column; + flex-wrap: nowrap; + justify-content: center; + align-items: center; +} + +div.period > [class^=d] > .course > .container *{ + text-align: center; +} \ No newline at end of file
DiplomeLessons' nameLocationViewLinkLast Update
Viewhttps://$url