aboutsummaryrefslogtreecommitdiff
path: root/model/Relive.php
diff options
context:
space:
mode:
authorMaZderMind2015-03-31 23:17:01 +0200
committerMaZderMind2015-03-31 23:17:01 +0200
commit024d632396def58c335944cae24371a10a3306b9 (patch)
tree579b4cdf2b4bb00a4329e186e19d2b2f9b1e519d /model/Relive.php
parent5b3788456f9e5b290eb2148af50b3f0a981a8923 (diff)
Implement Relive based on the MVT Pattern
Diffstat (limited to '')
-rw-r--r--model/Relive.php66
1 files changed, 61 insertions, 5 deletions
diff --git a/model/Relive.php b/model/Relive.php
index 3ffdc1b..a76761c 100644
--- a/model/Relive.php
+++ b/model/Relive.php
@@ -2,9 +2,18 @@
class Relive extends ModelBase
{
- function relive_talks()
+ public function isEnabled()
{
- $talks = @file_get_contents(get('OVERVIEW.RELIVE_JSON'));
+ // having CONFERENCE.RELIVE is not enough!
+ return $this->has('CONFERENCE.RELIVE_JSON');
+ }
+
+ public function getTalks()
+ {
+ if($talks_by_id = $this->getCached())
+ return $talks_by_id;
+
+ $talks = file_get_contents($this->get('CONFERENCE.RELIVE_JSON'));
$talks = utf8_decode($talks);
$talks = (array)json_decode($talks, true);
@@ -14,11 +23,58 @@ class Relive extends ModelBase
});
$talks_by_id = array();
- foreach ($talks as $value)
+ foreach ($talks as $talk)
{
- $talks_by_id[$value['id']] = $value;
+ if($talk['status'] == 'released')
+ $talk['url'] = $talk['release_url'];
+ else
+ $talk['url'] = 'relive/'.rawurlencode($talk['id']).'/';
+
+ $talks_by_id[$talk['id']] = $talk;
}
- return $talks_by_id;
+ return $this->doCache($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 isCacheEnabled()
+ {
+ return $this->has('CONFERENCE.RELIVE_JSON_CACHE') && function_exists('apc_fetch') && function_exists('apc_store');
+ }
+
+ private function getCacheDuration()
+ {
+ return $this->get('CONFERENCE.RELIVE_JSON_CACHE', 60*10 /* 10 minutes */);
+ }
+
+ private $localCache = null;
+ private function getCached()
+ {
+ if($this->localCache)
+ return $this->localCache;
+
+ if(!$this->isCacheEnabled())
+ return null;
+
+ return apc_fetch('RELIVE.CACHE');
+ }
+
+ private function doCache($value)
+ {
+ $this->localCache = $value;
+
+ if(!$this->isCacheEnabled())
+ return $value;
+
+ apc_store('RELIVE.CACHE', $value, $this->getCacheDuration());
+ return $value;
}
}