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

nico's avatar
nico committed
3 4
use \Firebase\JWT\JWT;

Mindiell's avatar
Mindiell committed
5 6
class Main extends Controller {
    /*
Mindiell's avatar
Mindiell committed
7 8 9 10
     * Home page
     * Presents campaign information and a random Contact
     */
    function home($f3,$args) {
11
        // Select a random contact
12
        //TODO: use weight for random
13
        $rand_id = rand(0, count($f3->get('contacts'))-1);
14 15
        $contacts = $f3->get('contacts');
        $f3->set('contact', $contacts[$rand_id]);
16
        $f3->set('random', rand(0, 2));
Mindiell's avatar
Mindiell committed
17 18 19
        $f3->set('block_content','home.html');
    }

nepski's avatar
nepski committed
20 21 22 23 24 25
    /*
     * 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
     */
26
    function feedbackform($f3, $args) {
nepski's avatar
nepski committed
27
        //GET
nepski's avatar
nepski committed
28
        if ($f3->get('VERB') == 'GET'){
29 30
            $categories = Api::get_feedback_categories();
            $f3->set('feedback_categories', $categories['categories']);
nepski's avatar
nepski committed
31

nepski's avatar
nepski committed
32 33
            $contact_id = $f3->get('POST.contact_id');
            $f3->set("contact_id", $contact_id);
nepski's avatar
use API  
nepski committed
34

nico's avatar
nico committed
35 36 37
            // Generate a jwt token
            $token = JWT::encode(array('api' => JWT_TOKEN), JWT_KEY);

nepski's avatar
nepski committed
38 39
            //TODO: create call
            //TODO: start call
nepski's avatar
use API  
nepski committed
40

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

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

nepski's avatar
nepski committed
55 56 57
    /*
     * Feedback SIP function
     */
nepski's avatar
nepski committed
58
    function feedbacksip($f3, $args) {
nepski's avatar
nepski committed
59

nepski's avatar
nepski committed
60
    }
nepski's avatar
nepski committed
61 62 63 64 65 66 67 68 69 70

    /*
     * 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') {
nepski's avatar
nepski committed
71
            $f3->set('contact', Api::get_contact()); //$args['id']
nepski's avatar
nepski committed
72 73 74 75 76 77 78 79 80 81 82

            $f3->set('block_content', 'call.html');
        }
        //POST
        elseif ($f3->get('VERB') == 'POST'){
            //GET feedbackform
            $f3->set('VERB', 'GET');
            $this->feedbackform($f3, $args);
        }
    }

nepski's avatar
nepski committed
83
    function contactslist($f3, $args) {
84 85
        $contacts = Api::get_contacts();
        $f3->set('contacts', $contacts);
86
        $f3->set('random', 2);
nepski's avatar
nepski committed
87 88 89

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

91 92 93 94 95
    function argumentation($f3, $args) {
        $arguments = Api::get_arguments();
        $f3->set('arguments', $arguments);

        $f3->set('block_content', 'argumentation.html');
96 97
    }

Mindiell's avatar
Mindiell committed
98
};