Main.php 2.77 KB
Newer Older
Mindiell's avatar
Mindiell committed
1 2
<?php

3
use \Firebase\JWT\JWT;
4 5 6 7
use Psr\Http\Message\ResponseInterface;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7;
use GuzzleHttp\Exception\RequestException;
8

Mindiell's avatar
Mindiell committed
9 10
class Main extends Controller {
    /*
11 12 13 14
     * Home page
     * Presents campaign information and a random Contact
     */
    function home($f3,$args) {
15
        // Select a random contact
16
        //TODO: use weight for random
17
        $contacts = $f3->get('contacts');
okhin's avatar
okhin committed
18 19 20 21

        $groups = Api::get_groups();
        $f3->set('groups', $groups);

okhin's avatar
okhin committed
22
        $f3->set('block_content', 'home.html');
Mindiell's avatar
Mindiell committed
23 24
    }

nepski's avatar
nepski committed
25 26 27 28 29 30
    /*
     * 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
     */
31
    function feedbackform($f3, $args) {
nepski's avatar
nepski committed
32
        //GET
nepski's avatar
nepski committed
33
        if ($f3->get('VERB') == 'GET'){
34
            $categories = Api::get_feedback_categories();
okhin's avatar
okhin committed
35
            $f3->set('feedback_categories', $categories);
nepski's avatar
nepski committed
36

nepski's avatar
nepski committed
37 38
            $contact_id = $f3->get('POST.contact_id');
            $f3->set("contact_id", $contact_id);
nepski's avatar
nepski committed
39

okhin's avatar
okhin committed
40 41 42
            $arguments = Api::get_arguments();
            $f3->set('arguments', $arguments);

nepski's avatar
nepski committed
43 44
            $f3->set('block_content', 'feedbackform.html');
        }
nepski's avatar
nepski committed
45
        //POST
nepski's avatar
nepski committed
46
        elseif ($f3->get('VERB') == 'POST'){
nepski's avatar
nepski committed
47 48
            $contact_id = $f3->get('POST.contact_id');
            $feedback = $f3->get('POST.feedback');
nepski's avatar
nepski committed
49
            $category = $f3->get('POST.feedback_category');
nepski's avatar
nepski committed
50

nepski's avatar
nepski committed
51
            //send feedback to campaign
nepski's avatar
nepski committed
52
            $f3->set('post_feedback_result', Api::post_feedback($contact_id, $feedback, $category));
nepski's avatar
nepski committed
53 54
            $f3->set('block_content', 'thankyou.html');
        }
55
    }
nepski's avatar
nepski committed
56

nepski's avatar
nepski committed
57 58 59 60 61 62 63 64 65
    /*
     * 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') {
66
            $f3->set('contact', Api::get_contact($args['id']));
okhin's avatar
okhin committed
67
            $f3->set('block_content', 'feedbackform.html');
nepski's avatar
nepski committed
68 69 70
        }
        //POST
        elseif ($f3->get('VERB') == 'POST'){
okhin's avatar
okhin committed
71 72 73 74
            // To get the callee, we have the callee_id in the form. Using that
            // to load the callee and retrieve its number.
            $contact = Api::get_contact($args['id']);
            $f3->set('contact', $contact);
75
            $call_id = str_replace('.', '-', uniqid('', true));
okhin's avatar
okhin committed
76
        }
nepski's avatar
nepski committed
77 78
    }

79
    function contactslist($f3, $args) {
80 81
        $contacts = Api::get_contacts();
        $f3->set('contacts', $contacts);
82 83 84

        $f3->set('block_content', 'contactslist.html');
    }
85

okhin's avatar
okhin committed
86
    function campaign($f3, $args) {
87 88 89
        $arguments = Api::get_arguments();
        $f3->set('arguments', $arguments);

okhin's avatar
okhin committed
90
        $f3->set('block_content', 'campaign.html');
91 92
    }

okhin's avatar
okhin committed
93
    function piphone($f3, $args) {
94
        $f3->set('block_content', 'piphone.html');
okhin's avatar
okhin committed
95
    }
Mindiell's avatar
Mindiell committed
96
};
okhin's avatar
okhin committed
97
;