From 502ea3fa474688fe7e0ed6e99b96ae7535e59366 Mon Sep 17 00:00:00 2001 From: Matheus456 Date: Wed, 17 Oct 2018 17:54:26 -0300 Subject: [PATCH] =?UTF-8?q?Ajustando=20o=20fale=20conosco=20para=20as=20no?= =?UTF-8?q?vas=20requisi=C3=A7=C3=B5es=20do=20escolamodelows?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- amd/src/config.js | 271 ++++++++++++++++++++--------------------- block_fale_conosco.php | 6 +- db/access.php | 16 +-- index.php | 113 ++--------------- proxy.php | 64 +++++----- searchform.php | 32 ++--- 6 files changed, 203 insertions(+), 299 deletions(-) diff --git a/amd/src/config.js b/amd/src/config.js index e550c66..4faf5b6 100644 --- a/amd/src/config.js +++ b/amd/src/config.js @@ -1,147 +1,136 @@ define(['jquery', 'js/jquery.dataTables.min.js', 'js/jquery-ui.min.js'] , function($) { - var exports = {}; - - var init = exports.init = function() { - $( "#id_situacao" ).change(function() { - alert( "Handler for .change() called." ); - }); - - var tabelaContatos = $('#tabela_contatos').DataTable({ - //dom: "Bfrtip", - ajax: { - url: "proxy.php", -// dataType: "json", - // contentType: "aplication/json", - dataSrc:"" - }, - columns: [ - { data: "id_conversa" }, - { data: "titulo" }, - { data: "cpf" } - ], - //select: true - }); - - $( "#tabs" ).tabs({ active: 0 }); - - $('#tabela_contatos tbody').on( 'click', 'tr', function () { - if ( $(this).hasClass('selected') ) { - $(this).removeClass('selected'); - - } - else { - tabelaContatos.$('tr.selected').removeClass('selected'); - $(this).addClass('selected'); - } - - getMessagesFromContact(); - } ); - } - - /* - Obtém todas as trocas de mensagens relacionadas a um determinado contato no Fale Conosco - */ - var getMessagesFromContact = exports.getMessagesFromContact = function(contactID) { - $.ajax({ - url: "proxy.php?contactID=" + contactID, - async: true, + var exports = {}; + var answered = 1; + var school = 'SSL'; + var init = exports.init = function() { + // Altera entre mensagens respondidas e não respondidas + $( "#id_situacao" ).change(function() { + answered = $(this).val(); + $("#id_situacao").val(answered); + tabelaContatos.ajax.url('proxy.php?schoolInitials=' + school +' + &answered=' + answered) + tabelaContatos.ajax.reload(); + }); + + // Obtém dados de todas as conversas + var tabelaContatos = $('#tabela_contatos').DataTable({ + ajax: { + url: "proxy.php?schoolInitials=" + school + "&answered=" + 0, + dataSrc:"" + }, + columns: [ + { data: "id_conversa" }, + { data: "titulo" }, + { data: "cpf" } + ], + // Passando o datatable para português + "oLanguage": { + "sEmptyTable": "Nenhum registro encontrado", + "sInfo": "Mostrando de _START_ até _END_ de _TOTAL_ registros", + "sInfoEmpty": "Mostrando 0 até 0 de 0 registros", + "sInfoFiltered": "(Filtrados de _MAX_ registros)", + "sInfoPostFix": "", + "sInfoThousands": ".", + "sLengthMenu": "_MENU_ resultados por página", + "sLoadingRecords": "Carregando...", + "sProcessing": "Processando...", + "sZeroRecords": "Nenhum registro encontrado", + "sSearch": "Pesquisar", + "oPaginate": { + "sNext": "Próximo", + "sPrevious": "Anterior", + "sFirst": "Primeiro", + "sLast": "Último" + }, + "oAria": { + "sSortAscending": ": Ordenar colunas de forma ascendente", + "sSortDescending": ": Ordenar colunas de forma descendente" + } + }, + }); + + $( "#tabs" ).tabs({ active: 0 }); + + $('#tabela_contatos tbody').on( 'click', 'tr', function () { + if ( $(this).hasClass('selected') ) { + $(this).removeClass('selected'); + } + else { + tabelaContatos.$('tr.selected').removeClass('selected'); + $(this).addClass('selected'); + } + data = tabelaContatos.row(this).data(); + getMessagesFromContact(data); + } ); + } + + // Obtém todas as trocas de mensagens relacionadas a um determinado contato no Fale Conosco + var getMessagesFromContact = exports.getMessagesFromContact = function(data_conversation) { + $.ajax({ + url: "proxy.php?conversationID=" + data_conversation.id_conversa, + type: "POST", + dataType: 'json', + success: function (data) { + var mensagens = ""; + for (var i = 0, len = data.length; i < len; i++) { + var desc = data[i].body; + arrayReturn.push([ data[i].id, data[i].name, data[i].email]); + if (data[i].aluno != false) { + mensagens += '
'; + } + else { + mensagens += '
'; + } + mensagens += + '
'+ + '

' + data[i].cpf + '

'+ + '
'+ + '
'+ + data[i].texto_mensagem + + '
'+ + Date(data[i].data_mensagem) + + '
'; + }; + mensagens += + '
'+ + ''+ + ''+ + '
' + + ''; + + $('#mensagens').html(mensagens); + $('#sendMessage').click(function (){ + description = $('#comment').val(); + $('#comment').attr('value', "") + $.ajax({ + url: "proxy.php?addMessage=" + data_conversation.id_conversa + "&description=" + description, + contentType: "application/json; charset=utf-8", + type: "post", dataType: 'json', success: function (data) { - var mensagens = ""; - for (var i = 0, len = data.length; i < len; i++) { - var desc = data[i].body; - arrayReturn.push([ data[i].id, data[i].name, data[i].email]); - mensagens += - '
'+ - '
'+ - '

' + data[i].description + '

'+ - '
'+ - '
'+ - data[i].description + - '
'+ - '
'; - }; - mensagens += - '
'+ - ''+ - ''+ - '
' + - ''; - - $('#mensagens').html(mensagens); - $('#sendMessage').click(function (){ - $.ajax({ - url: "proxy.php?addMessage=1", - data: "Teste", //ur data to be sent to server - contentType: "application/json; charset=utf-8", - type: "POST", - success: function (data) { - alert("Mensagem enviada!"); - $( "#tabs" ).tabs({ active: 0 }); - }, - error: function (x, y, z) { - alert(x.responseText +" " +x.status); - } - }); - }); - $( "#tabs" ).tabs({ active: 1 }); - } - }); - }; - - /* - Obtém dados de todos os contatos do Fale Conosco - */ - var getTableContacts = exports.getTableContacts = function() { - - $( "#tabs" ).tabs(); - - $('ul.tabs li').click(function(){ - var tab_id = $(this).attr('data-tab'); - - $('ul.tabs li').removeClass('current'); - $('.tab-content').removeClass('current'); - - $(this).addClass('current'); - $("#"+tab_id).addClass('current'); - }) - - /* - var arrayReturn = []; - $.ajax({ - url: "proxy.php", - async: true, - dataType: 'json', - success: function (data) { - for (var i = 0, len = data.length; i < len; i++) { - var desc = data[i].body; - arrayReturn.push([ data[i].id, data[i].name, data[i].email]); - } - - tabela = $('#tabela_contatos').DataTable( - //{"aaData": arrayReturn} - {ajax: "proxy.php"} - ); - - //$( "#tabs" ).tabs({ active: 0 }); - - $('#tabela_contatos tbody').on( 'click', 'tr', function () { - if ( $(this).hasClass('selected') ) { - $(this).removeClass('selected'); - - } - else { - tabela.$('tr.selected').removeClass('selected'); - $(this).addClass('selected'); - } - - getMessagesFromContact(); - } ); + alert("Mensagem enviada!"); + $( "#tabs" ).tabs({ active: 0 }); + }, + error: function (x, y, z) { + alert(x.responseText +" " +x.status); } + }); }); - */ - }; - - return exports; -}); \ No newline at end of file + $( "#tabs" ).tabs({ active: 1 }); + } + }); + }; + + // Obtém dados de todos os contatos do Fale Conosco + var getTableContacts = exports.getTableContacts = function() { + $( "#tabs" ).tabs(); + $('ul.tabs li').click(function(){ + var tab_id = $(this).attr('data-tab'); + $('ul.tabs li .tab-content').removeClass('current'); + $(this).addClass('current'); + $("#"+tab_id).addClass('current'); + }) + }; + + return exports; +}); diff --git a/block_fale_conosco.php b/block_fale_conosco.php index 2bec71b..5a2d1c9 100644 --- a/block_fale_conosco.php +++ b/block_fale_conosco.php @@ -9,11 +9,11 @@ class block_fale_conosco extends block_base { if ($this->content !== null) { return $this->content; } - + $this->content = new stdClass; $this->content->text = 'The content of our SimpleHTML block!'; $this->content->footer = 'Footer here...'; - + return $this->content; } -} \ No newline at end of file +} diff --git a/db/access.php b/db/access.php index 20f9f38..a25b852 100644 --- a/db/access.php +++ b/db/access.php @@ -1,27 +1,29 @@ array( 'captype' => 'write', 'contextlevel' => CONTEXT_SYSTEM, 'archetypes' => array( - 'user' => CAP_ALLOW + // 'user' => CAP_ALLOW + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'manager' => CAP_ALLOW, ), - + 'clonepermissionsfrom' => 'moodle/my:manageblocks' ), - + 'block/fale_conosco:addinstance' => array( 'riskbitmask' => RISK_SPAM | RISK_XSS, - + 'captype' => 'write', 'contextlevel' => CONTEXT_BLOCK, 'archetypes' => array( 'editingteacher' => CAP_ALLOW, 'manager' => CAP_ALLOW ), - + 'clonepermissionsfrom' => 'moodle/site:manageblocks' ), ); - diff --git a/index.php b/index.php index 1f01a3b..3fd66bb 100644 --- a/index.php +++ b/index.php @@ -10,7 +10,7 @@ if (isguestuser()) { } // Prepare page -$context = context_system::instance(); +$context = context_system::instance(); $PAGE->set_pagelayout('standard'); $PAGE->set_url('/blocks/fale_conosco/index.php'); $PAGE->requires->css(new moodle_url('https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css')); @@ -18,6 +18,7 @@ $PAGE->requires->css(new moodle_url('https://code.jquery.com/ui/1.12.1/themes/ba $PAGE->requires->css(new moodle_url('https://cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css')); + $PAGE->set_context($context); // Get data @@ -25,36 +26,16 @@ $strtitle = get_string('fale_conosco', 'block_fale_conosco'); $user = $USER; //$icon = $OUTPUT->pix_icon('print', get_string('print', 'block_fale_conosco'), 'block_fale_conosco'); -global $DB, $CFG; - - -/* -$uri = 'https://escolamodelows.interlegis.leg.br/api/v1/fale_conosco'; -$response = \Httpful\Request::get($uri) - //->sendsJson() - //->body('{"school_initial": "SSL"}') - ->expectsJson() - ->send(); - -$data=$response->body; - -html_writer::span("

Quantidade" . count($data) . '

'); +global $DB, $CFG, $USER; -// Print the header -$PAGE->navbar->add($strtitle); -$PAGE->set_title($strtitle); -$PAGE->set_heading($strtitle); - -*/ -//$PAGE->requires->css('/blocks/fale_conosco/printstyle.css'); echo $OUTPUT->header(); // Print concluded courses echo $OUTPUT->box_start('generalbox boxaligncenter'); echo $OUTPUT->heading(get_string('fale_conosco', 'block_fale_conosco')); -//Instantiate simplehtml_form +//Instantiate simplehtml_form $mform = new searchform(); //Form processing and displaying is done here @@ -65,92 +46,15 @@ if ($mform->is_cancelled()) { } else { // this branch is executed if the form is submitted but the data doesn't validate and the form should be redisplayed // or on the first display of the form. - - //Set default data (if any) - //$mform->set_data($toform); - //displays the form $mform->display(); } ?> - - - - requires->js_call_amd('block_fale_conosco/config', 'init'); -//$PAGE->requires->js_call_amd('block_fale_conosco/config', 'getTableContacts'); + $PAGE->requires->js_call_amd('block_fale_conosco/config', 'getTableContacts'); ?>
@@ -163,14 +67,15 @@ if ($mform->is_cancelled()) { ID - Usuário - E-mail + Assunto + CPF
+
diff --git a/proxy.php b/proxy.php index 54df8b3..6a1284d 100644 --- a/proxy.php +++ b/proxy.php @@ -1,44 +1,52 @@ sendsJson() - ->body('{"conversation_id": "1"}') - //->expectsJson() + ->body('{"conversation_id": "' . $id . '"}') ->send(); } elseif(isset($_REQUEST["addMessage"])) { + $id = intval($_GET['addMessage']); + $cpf = $USER->username; + $description = $_GET['description']; + + // ***Pega o contexto do curso e verifica o papel do usuário + // $cContext = context_course::instance(3); + // $isStudent = current(get_user_roles($cContext, $USER->id))->shortname =='student'? 'true' : 'false'; + + // ***Verifica se o usuário assume o papel de estudante em algum curso + // $isStudent = user_has_role_assignment($USER->id, 5); + $uri = 'https://escolamodelows.interlegis.leg.br/api/v1/fale_conosco/adicionar'; $response = \Httpful\Request::post($uri) ->sendsJson() ->body('{ - "name": "Matheus", - "email": "garcia.figueiredo@gmail.com", - "cpf": "05272886674", - "description": "Palmeiras nunca vai ganhar um mundial", - "date": "2018-08-01", - "course_id": "1", - "course_category_id": "1" , - "school_initials": "SSL", - "id_conversation": "1" - }') + "name": "' . $USER->username . '", + "email": "' . $USER->email . '", + "cpf": "' . $cpf . '", + "description": "' . $description . '", + "is_student": false, + "conversation_id": "' . $id . '" + }') ->send(); -} -else { - $uri = 'https://escolamodelows.interlegis.leg.br/api/v1/fale_conosco/conversa'; - $response = \Httpful\Request::post($uri) - ->sendsJson() - ->body( - '{ - "school_initials": "SSL", - "page" : "1", - "limit": "10" - }' - ) - //->expectsJson() +} elseif(isset($_REQUEST["schoolInitials"])) { + $not_answered = intval($_GET['answered'])== 0 ? 'false':'true'; + $not_answered = trim($not_answered, '"'); + $uri = 'https://escolamodelows.interlegis.leg.br/api/v1/fale_conosco/conversa'; + $response = \Httpful\Request::post($uri) + ->sendsJson() + ->body( + '{ + "school_initials": "SSL", + "page" : "1", + "limit": "2000", + "not_answered": '. $not_answered .' + }') ->send(); } diff --git a/searchform.php b/searchform.php index 32776c5..0b8fd94 100644 --- a/searchform.php +++ b/searchform.php @@ -1,22 +1,22 @@ libdir/formslib.php"); - + class searchform extends moodleform { - - function definition() { - global $CFG; - - $mform = $this->_form; // Don't forget the underscore! - - $attributes=array('size'=>'20'); - $selSituacao = $mform->addElement('select', 'situacao', get_string('situacao', 'block_fale_conosco'), - array('Não respondidas', 'Respondidas', 'Pendentes'), $attributes); - $selSituacao->setMultiple(false); + function definition() { + global $CFG; + + $mform = $this->_form; // Don't forget the underscore! + + $attributes=array('size'=>'20'); + $selSituacao = $mform->addElement('select', 'situacao', get_string('situacao', 'block_fale_conosco'), + array('Não respondidas', 'Respondidas'), $attributes); + + $selSituacao->setMultiple(false); - $attributes=array('size'=>'20'); - $txtUsuario = $mform->addElement('text', 'usuario', get_string('usuario', 'block_fale_conosco'), $attributes); + $attributes=array('size'=>'20'); + // $txtUsuario = $mform->addElement('text', 'usuario', get_string('usuario', 'block_fale_conosco'), $attributes); + // $mform->addElement('button', 'Atualizar', get_string("atualizar", "block_fale_conosco")); - $mform->addElement('button', 'Atualizar', get_string("atualizar", "block_fale_conosco")); - } -} \ No newline at end of file + } +}