Browse Source

Merge commit '8a00b9'

master
Matheus Garcia 5 years ago
parent
commit
ea6b027ee4
  1. 6
      index.php
  2. 27
      proxy.php

6
index.php

@ -1,7 +1,7 @@
<?php <?php
require_once("../../config.php"); require_once("../../config.php");
require_once("./searchform.php"); require_once("./searchform.php");
//include('httpful.phar'); require_once($CFG->dirroot.'/blocks/escola_modelo/classes/util.php');
// Check if user is logged and not guest // Check if user is logged and not guest
require_login(); require_login();
@ -9,6 +9,10 @@ if (isguestuser()) {
die(); die();
} }
if(!evlHabilitada()) {
die('Esta funcionalidade requer que a integração com a EVL esteja habilitada!');
}
// Prepare page // Prepare page
$context = context_system::instance(); $context = context_system::instance();
$PAGE->set_pagelayout('standard'); $PAGE->set_pagelayout('standard');

27
proxy.php

@ -1,17 +1,27 @@
<?php <?php
require_once("../../config.php"); require_once("../../config.php");
include_once($CFG->dirroot . "/blocks/escola_modelo/lib/httpful.phar"); require_once($CFG->dirroot.'/blocks/escola_modelo/classes/util.php');
require_once($CFG->dirroot . "/blocks/escola_modelo/classes/util.php"); include_once($CFG->dirroot . '/blocks/escola_modelo/lib/httpful.phar');
if(!evlHabilitada()) {
die('Esta funcionalidade requer que a integração com a EVL esteja habilitada!');
}
header("Content-Type: application/json"); header("Content-Type: application/json");
if(isset($_GET["conversationID"])) { // FIXME incluir APIKEY em todas as chamadas
// Obtém todas as mensagens de uma conversa
if(isset($_GET["conversationID"])) {
$id = intval($_GET['conversationID']); $id = intval($_GET['conversationID']);
$uri = evlURLWebServices() . '/api/v1/fale_conosco/mensagens'; $uri = evlURLWebServices() . '/api/v1/fale_conosco/mensagens';
$response = \Httpful\Request::post($uri) $response = \Httpful\Request::post($uri)
->sendsJson() ->sendsJson()
->body('{"conversation_id": "' . $id . '"}') ->body('{"conversation_id": "' . $id . '"}')
->send(); ->send();
} elseif(isset($_REQUEST["addMessage"])) { }
// Adiciona uma nova mensagem a uma conversa
elseif(isset($_REQUEST["addMessage"])) {
$id = intval($_GET['addMessage']); $id = intval($_GET['addMessage']);
$cpf = $USER->username; $cpf = $USER->username;
$description = $_GET['description']; $description = $_GET['description'];
@ -28,7 +38,10 @@ if(isset($_GET["conversationID"])) {
"conversation_id": "' . $id . '" "conversation_id": "' . $id . '"
}') }')
->send(); ->send();
} else { }
// Pega todas as conversas de determinada escola, em determinada situação
// FIXME parametrizar limite e tratar paginação
else {
$was_answered = intval($_GET['answered'])== 0 ? 'false':'true'; $was_answered = intval($_GET['answered'])== 0 ? 'false':'true';
$was_answered = trim($was_answered, '"'); $was_answered = trim($was_answered, '"');
$uri = evlURLWebServices() . '/api/v1/fale_conosco/conversa'; $uri = evlURLWebServices() . '/api/v1/fale_conosco/conversa';
@ -38,10 +51,10 @@ if(isset($_GET["conversationID"])) {
'{ '{
"school_initials": "' . evlSiglaEscola() . '", "school_initials": "' . evlSiglaEscola() . '",
"page" : "1", "page" : "1",
"limit": "2000", "limit": "2000",
"was_answered": '. $was_answered .' "was_answered": '. $was_answered .'
}') }')
->send(); ->send();
} }
$data=$response->body; $data=$response->body;

Loading…
Cancel
Save