streaming-website/model/Relive.php

125 lines
2.5 KiB
PHP
Raw Normal View History

<?php
class Relive
{
private $conference;
public function __construct($conference)
{
$this->conference = $conference;
}
public function getConference() {
return $this->conference;
}
public function isEnabled()
{
// having CONFERENCE.RELIVE is not enough!
return $this->getConference()->has('CONFERENCE.RELIVE_JSON');
}
2015-04-01 19:03:51 +00:00
public function getJsonUrl()
{
return $this->getConference()->get('CONFERENCE.RELIVE_JSON');
2015-04-01 19:03:51 +00:00
}
public function getJsonCache()
{
return sprintf('/tmp/relive-cache-%s.json', $this->getConference()->getSlug());
}
public function getTalks()
{
2016-12-18 09:37:10 +00:00
if(!file_exists($this->getJsonCache()))
return array();
2016-12-27 08:27:28 +00:00
$talks = file_get_contents($this->getJsonCache());
$talks = (array)json_decode($talks, true);
$mapping = $this->getScheduleToRoomMapping();
2016-12-10 17:24:03 +00:00
usort($talks, function($a, $b) {
// first, make sure that live talks are always on top
if($a['status'] == 'live' && $b['status'] != 'live') {
return -1;
}
else if($a['status'] != 'live' && $b['status'] == 'live') {
return 1;
}
else if($a['status'] == 'live' && $b['status'] == 'live') {
// sort live talks by room
return strcmp($a['room'], $b['room']);
}
// all other talks get sorted by their start time
// sorting the most recent talks to the top
$delta = $b['start'] - $a['start'];
// sort by room in case of a collision
if($delta == 0)
return strcmp($a['room'], $b['room']);
else
return $delta;
2016-12-10 17:24:03 +00:00
});
$talks_by_id = array();
foreach ($talks as $talk)
{
if($talk['status'] == 'not_running')
continue;
2016-12-27 10:26:07 +00:00
if($talk['status'] == 'released') {
$talk['url'] = $talk['release_url'];
2016-12-27 10:26:07 +00:00
}
else {
$talk['url'] = joinpath([
$this->getConference()->getSlug(),
'relive',
rawurlencode($talk['id']),
]);
}
if(isset($mapping[$talk['room']]))
{
$room = $mapping[$talk['room']];
$talk['room'] = $room->getDisplay();
$talk['roomlink'] = $room->getLink();
}
$talks_by_id[$talk['id']] = $talk;
}
2015-09-02 15:03:16 +00:00
return $talks_by_id;
}
public function getTalk($id)
{
$talks = $this->getTalks();
if(!isset($talks[$id]))
throw new NotFoundException('Relive-Talk id '.$id);
return $talks[$id];
}
private function getScheduleToRoomMapping()
{
2016-12-27 08:17:46 +00:00
$schedule = $this->getConference()->getSchedule();
$mapping = array();
foreach($schedule->getScheduleToRoomSlugMapping() as $schedule => $slug)
{
try {
2016-12-27 08:17:46 +00:00
$mapping[$schedule] = $this->getConference()->getRoom($slug);
}
catch(NotFoundException $e)
{
//
}
}
return $mapping;
}
}