From 5b404caa61857a8f8c54c54f7924e685e31520fd Mon Sep 17 00:00:00 2001 From: matheus Date: Tue, 10 Mar 2020 13:35:42 -0300 Subject: [PATCH] =?UTF-8?q?In=C3=ADcio=20de=20adapta=C3=A7=C3=A3o=20para?= =?UTF-8?q?=20pr=C3=A9-matricula=20de=20cursos=20presenciais?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib.php | 61 ++++++++++++++++++++++++++++++++++++++++++++++-- manage.php | 2 ++ manage_table.php | 4 +++- renderer.php | 9 +++---- 4 files changed, 69 insertions(+), 7 deletions(-) diff --git a/lib.php b/lib.php index 4b1adf1..fe8b2a4 100644 --- a/lib.php +++ b/lib.php @@ -89,6 +89,45 @@ class enrol_apply_plugin extends enrol_plugin { return new moodle_url('/enrol/apply/edit.php', array('courseid' => $courseid)); } + // TODO mover para outro local, usado também em certificado + function obtemCampoCustomizadoCurso($idCurso, $nomeCampo) { + global $DB; + + $sql = " + SELECT d.value, f.configdata::json->>'options' as options + FROM mdl_course c + JOIN mdl_context ctx + ON c.id = ? + AND ctx.contextlevel = 50 + AND ctx.instanceid = c.id + JOIN mdl_customfield_field f + ON f.shortname = ? + JOIN mdl_customfield_data d + ON d.fieldid = f.id + AND d.contextid = ctx.id + "; + + $valueArray = $DB->get_record_sql($sql, [$idCurso, $nomeCampo]); + + if($valueArray) { + $value = $valueArray->value; + $options = $valueArray->options; + + if($options == null) { + return $value; + } else { + $optionsArray = preg_split("/\s*\n\s*/", trim($options)); + return $optionsArray[$value-1]; + } + } else { + return ''; + } + } + + public function insere_assinatura_sigad($codProtocolo, $codUsuario) { + // retorna true se inseriu ou se já tinha, ou falso em caso de erro ou timeout + } + public function enrol_page_hook(stdClass $instance) { global $CFG, $OUTPUT, $SESSION, $USER, $DB; @@ -103,7 +142,19 @@ class enrol_apply_plugin extends enrol_plugin { } if ($DB->record_exists('user_enrolments', array('userid' => $USER->id, 'enrolid' => $instance->id))) { - return $OUTPUT->notification(get_string('notification', 'enrol_apply'), 'notifysuccess'); + // TODO: incluir aqui chamada para WS que atribui assinatura a documento no SIGAD + // analisar resultado: se timeout ou erro, assinatura deve ser inserida manualmente + // DO contrário já mostra link para usuário assinar. + + $textoAssinatura = ''; + if(insere_assinatura_sigad()) { + $textoAssinatura = 'Inseriu'; + } else { + $textoAssinatura = 'Erro'; + } + + $textoassinatura = 'Assinar'; + return $textoassinatura . ' '. $OUTPUT->notification(get_string('notification', 'enrol_apply'), 'notifysuccess'); } if ($instance->customint3 > 0) { @@ -115,6 +166,9 @@ class enrol_apply_plugin extends enrol_plugin { } } + + + require_once("$CFG->dirroot/enrol/apply/apply_form.php"); $form = new enrol_apply_apply_form(null, $instance); @@ -145,8 +199,11 @@ class enrol_apply_plugin extends enrol_plugin { } $output = $form->render(); + profile_load_custom_fields($USER); - return $OUTPUT->box($output); + $campo = obtemCampoCustomizadoCurso($instance->courseid, 'sf_restringir_matricula'); + + return $OUTPUT->box('Teste ' . $campo . $USER->profile['sf_cargo_chefia']) . $OUTPUT->box($output); } public function get_action_icons(stdClass $instance) { diff --git a/manage.php b/manage.php index 6b102b6..3be7ca9 100644 --- a/manage.php +++ b/manage.php @@ -36,6 +36,8 @@ require_login(); $manageurlparams = array(); if ($id == null) { $context = context_system::instance(); + // TODO verificar se coordenador tem esse papel + // TODO criar task para verificar assinaturas e confirmar automaticamente require_capability('enrol/apply:manageapplications', $context); $pageheading = get_string('confirmusers', 'enrol_apply'); $instance = null; diff --git a/manage_table.php b/manage_table.php index fbd1706..9e5eecc 100644 --- a/manage_table.php +++ b/manage_table.php @@ -47,10 +47,12 @@ class enrol_apply_manage_table extends table_sql { $this->set_sql( 'ue.id AS userenrolmentid, ue.userid, ue.status AS enrolstatus, ue.timecreated AS applydate, - ai.comment AS applycomment, u.*, c.fullname as course', + ai.comment AS applycomment, u.*, c.fullname as course, fcd.data as sf_cargo_chefia ', "{user_enrolments} AS ue LEFT JOIN {enrol_apply_applicationinfo} ai ON ai.userenrolmentid = ue.id JOIN {user} u ON u.id = ue.userid + LEFT JOIN {user_info_field} fc ON fc.shortname = 'sf_cargo_chefia' + LEFT JOIN {user_info_data} fcd ON fc.id = fcd.fieldid AND u.id = fcd.userid JOIN {enrol} e ON e.id = ue.enrolid JOIN {course} c ON c.id = e.courseid", $sqlwhere, diff --git a/renderer.php b/renderer.php index 54abf88..f353841 100644 --- a/renderer.php +++ b/renderer.php @@ -80,16 +80,17 @@ class enrol_apply_renderer extends plugin_renderer_base { public function manage_table($table, $instance) { $columns = array( 'checkboxcolumn', - 'course', + 'sf_cargo_chefia', 'fullname', // Magic happens here: The column heading will automatically be set. - 'email', + //'email', 'applydate', 'applycomment'); $headers = array( html_writer::checkbox('toggleall', 'toggleall', false, '', array('id' => 'toggleall')), - get_string('course'), + 'sf_cargo_chefia', + //get_string('course'), 'fullname', // Magic happens here: The column heading will automatically be set due to column name 'fullname'. - get_string('email'), + //get_string('email'), get_string('applydate', 'enrol_apply'), get_string('applycomment', 'enrol_apply'), );