Skip to content

Commit

Permalink
Merge pull request #342 from ComputerScienceHouse/develop
Browse files Browse the repository at this point in the history
Dockerize Process Dump
  • Loading branch information
jabbate19 authored Jan 11, 2024
2 parents bb40d7f + 68fd7c0 commit 4b8d25a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 7 deletions.
38 changes: 31 additions & 7 deletions api/src/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ private function firstDayAfterDate($weekday, $startDate) {
return $startDate + (60*60*24*($weekday-$weekdayOfStart));
}

private function hashTime($time, $schedule) {
return ($time['start'] . "-" .
$time['end'] . "-" .
$time['bldg'][$schedule['bldgStyle']] . "-" .
$time['room']);
}

public function generateIcal($schedule) {
date_default_timezone_set('America/New_York');
// Globals
Expand Down Expand Up @@ -64,27 +71,44 @@ public function generateIcal($schedule) {
continue;
}

// Iterate over all the times
$scheduleByTime = array();
foreach($course['times'] as $time) {
$hash = $this->hashTime($time, $schedule);
// Add to scheduleByTime array
if (array_key_exists($hash, $scheduleByTime)) {
$scheduleByTime[$hash][] = $time;
} else {
$scheduleByTime[$hash] = array($time);
}
}

// Iterate over all the times
foreach($scheduleByTime as $times) {
$code .= "BEGIN:VEVENT\r\n";
$code .= "UID:" . md5(uniqid(mt_rand(), true) . " @{$HTTPROOTADDRESS}");
$code .= "\r\n";
$code .= "TZID:America/New_York\r\n";
$code .= "DTSTAMP:" . gmdate('Ymd') . "T" . gmdate("His") . "Z\r\n";

$startTime = $this->icalFormatTime($time['start']);
$endTime = $this->icalFormatTime($time['end']);
$startTime = $this->icalFormatTime($times[0]['start']);
$endTime = $this->icalFormatTime($times[0]['end']);

// The start day of the event MUST be offset by it's day
// the -1 is b/c quarter starts are on Monday(=1)
// This /could/ be done via the RRULE WKST param, but that means
// translating days from numbers to some other esoteric format.
// @TODO: Retrieve the timezone from php or the config file
$day = date("Ymd", $this->firstDayAfterDate($time['day'], $termStart));
$day = date("Ymd", $this->firstDayAfterDate($times[0]['day'], $termStart));

$code .= "DTSTART;TZID=America/New_York:{$day}T{$startTime}\r\n";
$code .= "DTEND;TZID=America/New_York:{$day}T{$endTime}\r\n";
$code .= "RRULE:FREQ=WEEKLY;UNTIL={$termEnd}\r\n";
$dayCodes = array('SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA');
$days = array();
foreach ($times as $time) {
$days[] = $dayCodes[$time['day']];
}
$dayString = implode(',', $days);
$code .= "RRULE:FREQ=WEEKLY;INTERVAL=1;WKST=SU;BYDAY={$dayString};UNTIL={$termEnd}\r\n";
$code .= "ORGANIZER:RIT\r\n";

// Course name
Expand All @@ -96,8 +120,8 @@ public function generateIcal($schedule) {

// Meeting location
if($course['courseNum'] != 'non') {
$bldg = $time['bldg'][$schedule['bldgStyle']];
$code .= "LOCATION:{$bldg}-{$time['room']}\r\n";
$bldg = $times[0]['bldg'][$schedule['bldgStyle']];
$code .= "LOCATION:{$bldg}-{$times[0]['room']}\r\n";
}

$code .= "END:VEVENT\r\n";
Expand Down
14 changes: 14 additions & 0 deletions processDump.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM php:7.4

RUN docker-php-ext-install mysqli

WORKDIR /app

COPY inc ./inc

COPY inc/config.env.php inc/config.php

COPY tools ./tools

ENTRYPOINT ["php", "/app/tools/processDump.php", "-d"]

0 comments on commit 4b8d25a

Please sign in to comment.