Commit fee0499c authored by Mindiell's avatar Mindiell

Added fake random contact and use it in contact template

parent 0ce90aa2
......@@ -4,21 +4,80 @@
* Static class for REST API communication
*/
class Api {
// Generic get function for REST API
static function get($url) {
$curl = curl_init();
$url = API_BASE . $url;
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
// Generic post function for REST API
static function post($url, $data) {
$curl = curl_init();
$url = API_BASE . $url;
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
// Asking for campaign informations
static function get_campaign() {
// Asking for campaign informations
$json = Api::get("campaign/" . CAMPAIGN_ID);
return json_decode($json, true);
}
// Searching a random or specific contact
static function get_contact($contact_id='') {
if ($contact_id!='') {
$json = Api::get("campaign/" . CAMPAIGN_ID . "/contact/" . $contact_id);
} else {
$json = Api::get("campaign/" . CAMPAIGN_ID . "/contact");
}
return json_decode($json, true);
}
// Asking for complete list of contacts
static function get_contacts() {
$json = Api::get("campaign/" . CAMPAIGN_ID . "/contacts");
return json_decode($json, true);
}
// Asking for complete list of groups
static function get_groups() {
$json = Api::get("campaign/" . CAMPAIGN_ID . "/groups");
return json_decode($json, true);
}
// Asking for complete list of feedback categories
static function get_feedback_categories() {
$json = Api::get("campaign/" . CAMPAIGN_ID . "/feedback/categories");
return json_decode($json, true);
}
// Asking for arguments by language
static function get_arguments($language='en') {
$json = Api::get("campaign/" . CAMPAIGN_ID . "/arguments/" . $language);
return json_decode($json, true);
}
// Posting a feedback
static function post_feedback($contact_id, $comment, $feedback_category='') {
$data = array(
"contact_id"=>$contact_id,
"comment"=>$comment,
"feedback_category"=>$feedback_category
);
$json = Api::post("campaign/" . CAMPAIGN_ID . "/feedback/add", $data);
return json_decode($json, true);
}
};
......@@ -7,6 +7,7 @@ class Main extends Controller {
*/
function home($f3,$args) {
$f3->set('campaign', Api::get_campaign());
$f3->set('contact', Api::get_contact());
$f3->set('block_content','home.html');
}
......
......@@ -21,6 +21,44 @@ class RestApi {
// Specified contact
} else {
// Random contact
echo '{
"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": ""
}
]
}';
}
}
......
<!-- contact page -->
<p class="left"><img src="http://www.europarl.europa.eu/mepphoto/108570.jpg" alt="mep"></p>
<p id="name">Amelia ANDERSDOTTER</p>
<p id="name">{{ @contact.first_name }} {{ @contact.last_name }}</p>
<ul id="resume">
<li id="phone">Phone number: <a href="tel:+322 28 45922 ">+322 28 45922 </a></li>
<li id="group"><span>Political group:</span><a href="https://memopol.lqdn.fr/europe/parliament/group/Greens/EFA/"><img style="vertical-align: middle;" src="https://memopol.lqdn.fr/static/img/groups/eu/GreensEFA.png" height="24" alt="Greens/EFA" /></a> - Greens/EFA</li>
<li id="party"><span>National party:</span> Piratpartiet</li>
<li id="country"><span>Country: </span><img style="vertical-align: middle;" src="/static/ui-2.0/flag/SE.png" height="24" alt="SE" /></li>
<li id="phone">Phone number: <a href="tel:+322 28 45922 ">{{ @contact.tel }}</a></li>
<repeat group="{{ @contact.groups }}" value="{{ @group }}">
<check if="{{ @group.type!='Committee' }}">
<li id="group"><span>{{ @group.type }}:</span><a href="https://memopol.lqdn.fr/europe/parliament/group/Greens/EFA/"><img src="https://memopol.lqdn.fr/static/img/groups/eu/GreensEFA.png" height="24" alt="Greens/EFA" /></a> - {{ @group.name }}</li>
</check>
</repeat>
</ul>
<ul id="committee">
<li title="Committee on Industry, Research and Energy"><a href="https://memopol.lqdn.fr/europe/parliament/committee/ITRE/" style="color: white;">ITRE</a></li>
<li title="Committee on International Trade"><a href="https://memopol.lqdn.fr/europe/parliament/committee/INTA/" style="color: white;">INTA</a></li>
<li title="Committee on Budgetary Control"><a href="https://memopol.lqdn.fr/europe/parliament/committee/CONT/" style="color: white;">CONT</a></li>
<repeat group="{{ @contact.groups }}" value="{{ @group }}">
<check if="{{ @group.type=='Committee' }}">
<li title="Committee on Industry, Research and Energy"><a href="https://memopol.lqdn.fr/europe/parliament/committee/ITRE/">{{ @group.name }}</a></li>
</check>
</repeat>
</ul>
<p id="info"><a href="https://memopol.lqdn.fr/europe/parliament/deputy/AmeliaAndersdotter/">Get more info…</a></p>
......
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