View added + db management of each course + now GMT managed directly in scale for reading image

This commit is contained in:
xdrm-brackets 2017-09-16 18:03:10 +02:00
parent 9fb8327c24
commit c5ae428db4
6 changed files with 314 additions and 16 deletions

View File

@ -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 "<head>";
echo " <title>ICS UPPA university</title>";
echo " <meta name='author' content='xdrm-brackets (Adrien Marquès)'>";
echo " <link type='text/css' rel='stylesheet' href='/css/layout.css' />";
echo "</head>";
echo "<body>";
}
/* [2] For each period (week)
=========================================================*/ {
echo "<div class='null'>";
$cal_height = 54; // in css:vw
foreach($periods as $period){
echo "</div><div class='period'>";
/* (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 "<div class='title'>Week from ${days[0]} to ${days[4]}</div>";
echo "<div class='null'>";
/* (2) For each day */
foreach($days as $day_n=>$day){
/* (2.1) Display day grid */
echo "</div><div class='day d$day_n'>";
/* (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 <div> according to hours */
echo "<div class='course' style='top: ${top}vw; height: ${height}vw; background-color: $color;'>";
echo "<div class='start'>".$course['startd']."</div>";
echo "<div class='stop'>".$course['stopd']."</div>";
echo "<div class='container'>";
echo "<span><b>".$course['ename']."</b></span>";
echo "<span>".$course['lname']."</span>";
echo "</div>";
echo "</div>";
}
}
echo "</div>";
}
echo "</div>";
}
echo "</body>";
// echo "<form method='POST' action='/xlessons/".$this->diplome_id."'>";
// echo "<table><thead style='font-weight: bold;'><tr><td>Read name</td><td>Correction</td></tr></thead><tbody>";
// foreach($d_cols as $data){
// $id = $data['id_event'];
// $basename = $data['basename'];
// $color = $data['color'];
// $name = $data['name'];
// echo "<tr><td>$basename</td><td><input type='text' style='display: inline-block; margin: 1em .2em; padding: .2em; border: none; background-color: $color;' name='name[$id]' value='$name'></td></tr>";
// }
// echo "</tbody></table>";
// echo "<input type='submit' value='SAVE'>";
// echo "</form>";
}
public function lessons(){

View File

@ -41,7 +41,7 @@
/* [2] Display the links
=========================================================*/
echo "<table><thead style='font-weight: bold;'><tr><td>Diplome</td><td>Lessons' name</td><td>Location</td><td>Link</td><td>Last Update</td></tr></thead><tbody>";
echo "<table><thead style='font-weight: bold;'><tr><td>Diplome</td><td>Lessons' name</td><td>Location</td><td>View</td><td>Link</td><td>Last Update</td></tr></thead><tbody>";
foreach($diplomes as $id=>$data){
@ -66,6 +66,12 @@
if( file_exists($link) )
echo " href='/ics/$id.ics'";
// link to view
echo "<td><a href='/view/$id'>View</a></td>";
echo "<td><a";
if( file_exists($link) )
echo " href='/ics/$id.ics'";
// link to .ics
echo ">https://$url</a></td>";

View File

@ -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(<String>, <URL>, <String>) received but cannot reach <URL>");
/* (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(<String>, <String>, <DATE>) received <DATE> 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<int> Day relative index
* @y<int> y Coordinate
*
* @return time<String> Formatted time (HH:mm)
* @return time<int> 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;
}

View File

@ -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);

View File

@ -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",

110
public_html/css/layout.css Normal file
View File

@ -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;
}