Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
La Quadrature du Net
piphone
piphone-front
Commits
fee0499c
Commit
fee0499c
authored
Nov 22, 2014
by
Mindiell
Browse files
Added fake random contact and use it in contact template
parent
0ce90aa2
Changes
4
Hide whitespace changes
Inline
Side-by-side
app/Api.php
View file @
fee0499c
...
@@ -4,21 +4,80 @@
...
@@ -4,21 +4,80 @@
* Static class for REST API communication
* Static class for REST API communication
*/
*/
class
Api
{
class
Api
{
// Generic get function for REST API
static
function
get
(
$url
)
{
static
function
get
(
$url
)
{
$curl
=
curl_init
();
$curl
=
curl_init
();
$url
=
API_BASE
.
$url
;
$url
=
API_BASE
.
$url
;
curl_setopt
(
$curl
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$curl
,
CURLOPT_URL
,
$url
);
curl_setopt
(
$curl
,
CURLOPT_RETURNTRANSFER
,
1
);
curl_setopt
(
$curl
,
CURLOPT_RETURNTRANSFER
,
true
);
$result
=
curl_exec
(
$curl
);
$result
=
curl_exec
(
$curl
);
curl_close
(
$curl
);
curl_close
(
$curl
);
return
$result
;
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
()
{
static
function
get_campaign
()
{
// Asking for campaign informations
$json
=
Api
::
get
(
"campaign/"
.
CAMPAIGN_ID
);
$json
=
Api
::
get
(
"campaign/"
.
CAMPAIGN_ID
);
return
json_decode
(
$json
,
true
);
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
);
}
};
};
app/Main.php
View file @
fee0499c
...
@@ -7,6 +7,7 @@ class Main extends Controller {
...
@@ -7,6 +7,7 @@ class Main extends Controller {
*/
*/
function
home
(
$f3
,
$args
)
{
function
home
(
$f3
,
$args
)
{
$f3
->
set
(
'campaign'
,
Api
::
get_campaign
());
$f3
->
set
(
'campaign'
,
Api
::
get_campaign
());
$f3
->
set
(
'contact'
,
Api
::
get_contact
());
$f3
->
set
(
'block_content'
,
'home.html'
);
$f3
->
set
(
'block_content'
,
'home.html'
);
}
}
...
...
app/RestApi.php
View file @
fee0499c
...
@@ -21,6 +21,44 @@ class RestApi {
...
@@ -21,6 +21,44 @@ class RestApi {
// Specified contact
// Specified contact
}
else
{
}
else
{
// Random contact
// 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": ""
}
]
}'
;
}
}
}
}
...
...
templates/contact.html
View file @
fee0499c
<!-- contact page -->
<!-- contact page -->
<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/108570.jpg"
alt=
"mep"
></p>
<p
id=
"name"
>
Amelia ANDERSDOTTER
</p>
<p
id=
"name"
>
{{ @contact.first_name }} {{ @contact.last_name }}
</p>
<ul
id=
"resume"
>
<ul
id=
"resume"
>
<li
id=
"phone"
>
Phone number:
<a
href=
"tel:+322 28 45922 "
>
+322 28 45922
</a></li>
<li
id=
"phone"
>
Phone number:
<a
href=
"tel:+322 28 45922 "
>
{{ @contact.tel }}
</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>
<repeat
group=
"{{ @contact.groups }}"
value=
"{{ @group }}"
>
<li
id=
"party"
><span>
National party:
</span>
Piratpartiet
</li>
<check
if=
"{{ @group.type!='Committee' }}"
>
<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=
"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>
<ul
id=
"committee"
>
<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>
<repeat
group=
"{{ @contact.groups }}"
value=
"{{ @group }}"
>
<li
title=
"Committee on International Trade"
><a
href=
"https://memopol.lqdn.fr/europe/parliament/committee/INTA/"
style=
"color: white;"
>
INTA
</a></li>
<check
if=
"{{ @group.type=='Committee' }}"
>
<li
title=
"Committee on Budgetary Control"
><a
href=
"https://memopol.lqdn.fr/europe/parliament/committee/CONT/"
style=
"color: white;"
>
CONT
</a></li>
<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>
</ul>
<p
id=
"info"
><a
href=
"https://memopol.lqdn.fr/europe/parliament/deputy/AmeliaAndersdotter/"
>
Get more info…
</a></p>
<p
id=
"info"
><a
href=
"https://memopol.lqdn.fr/europe/parliament/deputy/AmeliaAndersdotter/"
>
Get more info…
</a></p>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment