Commit 253c4236 authored by Mindiell's avatar Mindiell

Api uses cache, RestApi is based on json files

parent 8c40758d
......@@ -19,6 +19,13 @@ class Controller {
// Init campaign informations
$f3->set('campaign', Api::get_campaign());
// Init contacts list if needed
if (!$f3->exists('contacts')) {
$f3->set('contacts', Api::get_contacts()['contacts'], API_TIMEOUT);
}
// Workaround for caching variables
$f3->set('contacts', $f3->get('contacts'));
}
// Function called after routing
......
......@@ -6,7 +6,9 @@ class Main extends Controller {
* Presents campaign information and a random Contact
*/
function home($f3,$args) {
$f3->set('contact', Api::get_contact());
// Select a random contact
$rand_id = rand(0, count($f3->get('contacts'))-1);
$f3->set('contact', $f3->get('contacts')[$rand_id]);
$f3->set('block_content','home.html');
}
......
<?php
// Fake REST API from Campaign module
/*
* Fake REST API from Campaign module
*
* Uses datas folder to retrieve informations
*/
class RestApi {
function return_datas($filename) {
$f = fopen($filename, 'r');
$result = fread($f, filesize($filename));
fclose($f);
return $result;
}
function campaign($f3,$args) {
echo '{
"title": "Piphone Demo\'s campaign",
"description": "This is a demo campaign used to illustrate how the piphone works. This campaign does not grants you the possibility to contact anyone, it\'s just an ilustration of how it works.",
"start_date": "2014-01-01",
"end_date": "2014-12-31",
"default_language": "en"
}';
echo $this->return_datas('app/datas/campaign.json');
}
function contacts($f3,$args) {
// List of contacts
echo '{"contacts":[{
"id": "4123",
"last_name": "ANDERSDOTTER",
"first_name": "Amelia",
"tel": "+322 28 45922",
"groups": [{"type": "Political group","name": "Greens/EFA","media": ""},{"type": "National party","name": "Piratpartiet","media": ""},
{"type": "Country","name": "SE","media": ""},{"type": "Committee","name": "ITRE","media": ""},{"type": "Committee","name": "INTA","media": ""},
{"type": "Committee","name": "CONT","media": ""}
]},{
"id": "4123",
"last_name": "ANDERSDOTTER",
"first_name": "Amelia",
"tel": "+322 28 45922",
"groups": [{"type": "Political group","name": "Greens/EFA","media": ""},{"type": "National party","name": "Piratpartiet","media": ""},
{"type": "Country","name": "SE","media": ""},{"type": "Committee","name": "ITRE","media": ""},{"type": "Committee","name": "INTA","media": ""},
{"type": "Committee","name": "CONT","media": ""}
]},{
"id": "4123",
"last_name": "ANDERSDOTTER",
"first_name": "Amelia",
"tel": "+322 28 45922",
"groups": [{"type": "Political group","name": "Greens/EFA","media": ""},{"type": "National party","name": "Piratpartiet","media": ""},
{"type": "Country","name": "SE","media": ""},{"type": "Committee","name": "ITRE","media": ""},{"type": "Committee","name": "INTA","media": ""},
{"type": "Committee","name": "CONT","media": ""}
]}
]}';
echo $this->return_datas('app/datas/contacts.json');
}
function contact($f3,$args) {
......
This folder contains only datas for the fake REST API (for tests and dev).
{
"title": "Piphone Demo's campaign",
"description": "This is a demo campaign used to illustrate how the piphone works. This campaign does not grants you the possibility to contact anyone, it's just an ilustration of how it works.",
"start_date": "2014-01-01",
"end_date": "2014-12-31",
"default_language": "en"
}
{
"contacts":[
{
"id": "75426",
"last_name": "ANDERSDOTTER",
"first_name": "Amelia",
"tel": "+322 28 45922",
"external_id": "108570",
"groups": [
{
"type": "Political group",
"name": "Greens/EFA",
"media": ""
},
{
"type": "National party",
"name": "Piratpartiet",
"media": ""
},
{
"type": "Country",
"name": "SE",
"media": ""
},
{
"type": "Committee",
"name": "ITRE",
"media": ""
},
{
"type": "Committee",
"name": "INTA",
"media": ""
},
{
"type": "Committee",
"name": "CONT",
"media": ""
}
]
},
{
"id": "1245",
"last_name": "BLINKEVIČIŪTĖ",
"first_name": "Vilija",
"tel": "+322 28 45435",
"external_id": "96681",
"groups": [
{
"type": "Political group",
"name": "S&D",
"media": ""
},
{
"type": "National party",
"name": "LSDP",
"media": ""
},
{
"type": "Country",
"name": "LI",
"media": ""
},
{
"type": "Committee",
"name": "LIBE",
"media": ""
},
{
"type": "Committee",
"name": "FEMM",
"media": ""
},
{
"type": "Committee",
"name": "EMPL",
"media": ""
}
]
},
{
"id": "2324",
"last_name": "ANDRIEU",
"first_name": "Eric",
"tel": "+322 28 45170",
"external_id": "113892",
"groups": [
{
"type": "Political group",
"name": "S&D",
"media": ""
},
{
"type": "National party",
"name": "Parti socialiste",
"media": ""
},
{
"type": "Country",
"name": "FR",
"media": ""
},
{
"type": "Committee",
"name": "INTA",
"media": ""
},
{
"type": "Committee",
"name": "AGRI",
"media": ""
}
]
}
]
}
<!-- contact page -->
<h3>Random MEP</h3>
<p class="left"><img src="http://www.europarl.europa.eu/mepphoto/108570.jpg" alt="mep"></p>
<p class="left"><img src="http://www.europarl.europa.eu/mepphoto/{{ @contact.external_id }}.jpg" alt="mep"></p>
<p id="name">{{ @contact.first_name }} {{ @contact.last_name }}</p>
<ul id="resume">
<li id="phone">Phone number: <a href="tel:{{ @contact.tel }} ">{{ @contact.tel }}</a></li>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment