Commit 747827ab authored by okhin's avatar okhin

Merge branch 'nepski_qcc4' into 'qcc4'

Nepski qcc4

Feedback form: view, controller, tests, POST and GET route.
Feedback SIP: empty controller function, POST route.

See merge request !4
parents d6336284 eed9d053
......@@ -11,5 +11,70 @@ class Main extends Controller {
$f3->set('block_content','home.html');
}
/*
* Feedback page
* Form for a feedback after a call
* GET: show the form
* POST: send the form to the campaign API and show thank you
*/
function feedbackform($f3, $args) {
//GET
if ($f3->get('VERB') == 'GET'){
$categories = Api::get_feedback_categories()['categories'];
$f3->set('feedback_categories', $categories);
$contact_id = $f3->get('POST.contact_id');
$f3->set("contact_id", $contact_id);
//TODO: create call
//TODO: start call
$f3->set('block_content', 'feedbackform.html');
}
//POST
elseif ($f3->get('VERB') == 'POST'){
$contact_id = $f3->get('POST.contact_id');
$feedback = $f3->get('POST.feedback');
$category = $f3->get('POST.feedback_category');
//send feedback to campaign
$f3->set('post_feedback_result', Api::post_feedback($contact_id, $feedback, $category));
$f3->set('block_content', 'thankyou.html');
}
}
/*
* Feedback SIP function
*/
function feedbacksip($f3, $args) {
}
/*
* call Page
* Form to call
* GET: show the form
* POST: send the form and GET feedbackform
*/
function call($f3, $args) {
//GET
if ($f3->get('VERB') == 'GET') {
$f3->set('contact', Api::get_contact()); //$args['id']
$f3->set('block_content', 'call.html');
}
//POST
elseif ($f3->get('VERB') == 'POST'){
//GET feedbackform
$f3->set('VERB', 'GET');
$this->feedbackform($f3, $args);
}
}
function contactslist($f3, $args) {
$f3->set('contacts', Api::get_contacts()['contacts']);
$f3->set('block_content', 'contactslist.html');
}
};
......@@ -14,6 +14,32 @@ class RestApi {
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": ""}
]}
]}';
}
function contact($f3,$args) {
......@@ -68,6 +94,12 @@ class RestApi {
function categories($f3,$args) {
// List of feedback categories
echo'{"categories": [
"category1",
"category2",
"category3"
]
}';
}
function feedback_add($f3,$args) {
......
......@@ -12,3 +12,9 @@ GET /restapi/campaign/@id/feedback/categories=RestApi->categories
POST /restapi/campaign/@id/feedback/add=RestApi->feedback_add
GET /restapi/campaign/@id/arguments/@lang=RestApi->arguments
GET|POST @feedback:/feedback=Main->feedbackform
GET|POST @call:/call/@id=Main->call
GET @contactslist:/contactslist=Main->contactslist
POST @feedbacksip:/feedbacksip=Main->feedbacksip
\ No newline at end of file
<h2>{{ _("Call for free") }}</h2>
<form method="post" action="/call/{{ @contact.id }}">
<input type="text" id="contact_id" name="contact_id" hidden="hidden" value="{{ @contact.id }}">
<p>{{ _("If you want to call for free, you must provide us with your phone number (the PiPhone will call that number to initiate the communication).") }}</p>
<p>
<label for="phone">{{_("Your phone number:") }}</label>
<input type="text" name="phone" id="phone" placeholder="+33123456789001" />
</p>
<p>
{{ _('Starting with your <a href="https://en.wikipedia.org/wiki/List_of_country_calling_codes#Zones_3-4:_Europe">country code</a>, without the initial 0') }}
</p>
<input type="submit" value="{{ _("I'm ready, call me") }}" />
</form>
<h2>{{ _("Call at your expense") }}</h2>
<p>{{ _("If you don't want to call for free, here is the number of the current MEP (you can either dial it from your phone or push the button if any VoIP client is installed on your device.") }}</p>
<a href="tel:{{ @contact.tel }}" target="_blank">☎ {{ @contact.tel }}</a>
<p><a href="/">{{ _("Cancel the call") }}</a></p>
<repeat group="{{ @contacts }}" value="{{ @contact }}">
<p>
<include href="contact.html" />
</p>
<form method="post" action="/call/{{ @contact.id }}">
<input type="submit" value="{{ _("Call") }}" />
</form>
</repeat>
<h2>{{ _("Feedback Form") }}</h2>
<!-- error message -->
<p>{{ _("Please tell us what happened if you was able to talk to someone. Your feedback is important to us.") }}</p>
<form method="post" action="/feedback/" >
<input type="text" id="contact_id" name="contact_id" hidden="hidden" value="{{ @contact_id }}" />
<repeat group="{{ @feedback_categories }}" value="{{ @feedback_category }}">
<input type="radio" name="feedback_category" value="{{ @feedback_category }}" />
{{ @feedback_category }}
</repeat>
<p>
<textarea id="feedback" name="feedback"></textarea>
</p>
<input type="submit" name="go" value="{{ _("Send my feedback") }}" />
</form>
\ No newline at end of file
<p>{{ _("thank you! <3") }}</p>
<a href="/">"{{ _("Call another deputy") }}"</a>
......@@ -43,6 +43,23 @@ class Test_Main_Class extends BaseTest {
$this->f3->clear('ERROR'); // clear any errors
}
function test_main_get_feedbackform_return_categories_array() {
$this->f3->mock('GET /feedback/');
$this->test->expect(
is_array($this->f3->get('feedback_categories')),
"Do not get a categories array"
);
$this->f3->clear('ERROR'); // clear any errors
}
function test_main_get_feedbackform_return_contact_id() {
$this->f3->mock('GET /feedback/');
$this->test->expect(
!is_nan($this->f3->get('contact_id')),
"Do not get a numeric contact id"
);
$this->f3->clear('ERROR'); // clear any errors
}
}
// Launching tests
......
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