2015-03-30 14:20:30 +00:00
|
|
|
<?php
|
|
|
|
|
2016-12-10 17:22:34 +00:00
|
|
|
class Relive
|
2015-03-30 14:20:30 +00:00
|
|
|
{
|
2016-12-10 17:22:34 +00:00
|
|
|
private $conference;
|
|
|
|
|
|
|
|
public function __construct($conference)
|
|
|
|
{
|
|
|
|
$this->conference = $conference;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getConference() {
|
|
|
|
return $this->conference;
|
|
|
|
}
|
|
|
|
|
2015-03-31 21:17:01 +00:00
|
|
|
public function isEnabled()
|
2015-03-30 14:20:30 +00:00
|
|
|
{
|
2015-03-31 21:17:01 +00:00
|
|
|
// having CONFERENCE.RELIVE is not enough!
|
2016-12-10 17:22:34 +00:00
|
|
|
return $this->getConference()->has('CONFERENCE.RELIVE_JSON');
|
2015-03-31 21:17:01 +00:00
|
|
|
}
|
|
|
|
|
2015-04-01 19:03:51 +00:00
|
|
|
public function getJsonUrl()
|
|
|
|
{
|
2016-12-10 17:22:34 +00:00
|
|
|
return $this->getConference()->get('CONFERENCE.RELIVE_JSON');
|
2015-04-01 19:03:51 +00:00
|
|
|
}
|
|
|
|
|
2015-03-31 21:17:01 +00:00
|
|
|
public function getTalks()
|
|
|
|
{
|
2016-10-23 13:42:20 +00:00
|
|
|
if(!file_exists($this->getJsonUrl()))
|
|
|
|
return array();
|
|
|
|
|
2015-04-01 19:03:51 +00:00
|
|
|
$talks = file_get_contents($this->getJsonUrl());
|
2015-03-30 14:20:30 +00:00
|
|
|
$talks = (array)json_decode($talks, true);
|
|
|
|
|
2015-04-04 11:31:01 +00:00
|
|
|
$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 name
|
|
|
|
return strcmp($a['title'], $b['title']);
|
|
|
|
});
|
2015-03-30 14:20:30 +00:00
|
|
|
|
|
|
|
$talks_by_id = array();
|
2015-03-31 21:17:01 +00:00
|
|
|
foreach ($talks as $talk)
|
2015-03-30 14:20:30 +00:00
|
|
|
{
|
2015-04-05 13:25:45 +00:00
|
|
|
if($talk['status'] == 'not_running')
|
|
|
|
continue;
|
|
|
|
|
2015-03-31 21:17:01 +00:00
|
|
|
if($talk['status'] == 'released')
|
|
|
|
$talk['url'] = $talk['release_url'];
|
|
|
|
else
|
|
|
|
$talk['url'] = 'relive/'.rawurlencode($talk['id']).'/';
|
|
|
|
|
2015-04-04 11:31:01 +00:00
|
|
|
if(isset($mapping[$talk['room']]))
|
|
|
|
{
|
|
|
|
$room = $mapping[$talk['room']];
|
|
|
|
$talk['room'] = $room->getDisplay();
|
|
|
|
$talk['roomlink'] = $room->getLink();
|
|
|
|
}
|
|
|
|
|
2015-03-31 21:17:01 +00:00
|
|
|
$talks_by_id[$talk['id']] = $talk;
|
2015-03-30 14:20:30 +00:00
|
|
|
}
|
|
|
|
|
2015-09-02 15:03:16 +00:00
|
|
|
return $talks_by_id;
|
2015-03-31 21:17:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getTalk($id)
|
|
|
|
{
|
|
|
|
$talks = $this->getTalks();
|
|
|
|
if(!isset($talks[$id]))
|
|
|
|
throw new NotFoundException('Relive-Talk id '.$id);
|
|
|
|
|
|
|
|
return $talks[$id];
|
|
|
|
}
|
|
|
|
|
2015-04-04 11:31:01 +00:00
|
|
|
private function getScheduleToRoomMapping()
|
|
|
|
{
|
|
|
|
$schedule = new Schedule();
|
|
|
|
$mapping = array();
|
|
|
|
|
|
|
|
foreach($schedule->getScheduleToRoomSlugMapping() as $schedule => $slug)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$mapping[$schedule] = new Room($slug);
|
|
|
|
}
|
|
|
|
catch(NotFoundException $e)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $mapping;
|
|
|
|
}
|
|
|
|
|
2015-03-30 14:20:30 +00:00
|
|
|
}
|