From fc812d17cfa3ac4391835eb423e810fc1f2b0f30 Mon Sep 17 00:00:00 2001 From: Matheus456 Date: Thu, 27 Jun 2019 13:32:17 -0300 Subject: [PATCH] =?UTF-8?q?Refatorando=20parte=20do=20c=C3=B3digo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- process.php | 2 +- return.php | 34 ++++++++++++++++++++-------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/process.php b/process.php index e72605a..653e7fe 100644 --- a/process.php +++ b/process.php @@ -24,7 +24,7 @@ require('../../config.php'); require_once("lib.php"); -require_once($CFG->libdir.'/eventslib.php'); +// require_once($CFG->libdir.'/eventslib.php'); require_once($CFG->libdir.'/enrollib.php'); require_once("../../blocks/escola_modelo/classes/util.php"); diff --git a/return.php b/return.php index 8ab0020..6c06800 100644 --- a/return.php +++ b/return.php @@ -55,23 +55,29 @@ $context = context_course::instance($course->id); // Obtem nome do curso $fullname = format_string($course->fullname, true, array('context' => $context)); -if( matriculadoNaEvl($key, $course->id, 'ILB') ) { // FIXME obter código da escola - // Matricula usuário na Escola Modelo - $roleid = $DB->get_field('role', 'id', array('shortname' => 'student')); - $enrol_plugin = enrol_get_plugin('evl'); - $enrol_instance = $DB->get_record('enrol', array('id' => $instanceid)); - $enrol_plugin->enrol_user($enrol_instance, $USER->id, $roleid); - +if( matriculadoNaEvl($key, $course->id, evlSiglaEscola()) ) { + // Assegura que foi matriculado - if (is_enrolled($context, null, '', true) || true) { + if (is_enrolled($context, null, '', true)) { // Redireciona usuário para página do curso - redirect($destination, get_string('enrol_success', 'enrol_evl', $fullname)); + redirect($destination); } else { - $PAGE->set_context($context); - $PAGE->set_url($destination); - echo $OUTPUT->header(); - notice(get_string('enrol_error', 'enrol_evl'), $destination); - echo $OUTPUT->footer(); + // Matricula usuário na Escola Modelo + $roleid = $DB->get_field('role', 'id', array('shortname' => 'student')); + $enrol_plugin = enrol_get_plugin('evl'); + $enrol_instance = $DB->get_record('enrol', array('id' => $instanceid)); + $enrol_plugin->enrol_user($enrol_instance, $USER->id, $roleid); + + if(is_enrolled($context, null, '', true)) { + // Redireciona usuário para página do curso + redirect($destination, get_string('enrol_success', 'enrol_evl', $fullname)); + } else { + $PAGE->set_context($context); + $PAGE->set_url($destination); + echo $OUTPUT->header(); + notice(get_string('enrol_error', 'enrol_evl'), $destination); + echo $OUTPUT->footer(); + } } } else { $PAGE->set_context($context);