From bf9e65689c5ae8b9625d62544923e33907779787 Mon Sep 17 00:00:00 2001 From: Sesostris Vieira Date: Thu, 13 Mar 2014 11:54:05 -0300 Subject: [PATCH] =?UTF-8?q?N=C3=A3o=20permitir=20matr=C3=ADcula=20em=20cur?= =?UTF-8?q?sos=20com=20mesmo=20prefixo=20no=20campo=20idnumber=20dentro=20?= =?UTF-8?q?do=20per=C3=ADodo=20de=20car=C3=AAncia?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lang/en/enrol_ilbead.php | 4 ++++ lang/pt_br/enrol_ilbead.php | 4 ++++ lib.php | 24 +++++++++++++++++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lang/en/enrol_ilbead.php b/lang/en/enrol_ilbead.php index 60145ed..9ee993f 100644 --- a/lang/en/enrol_ilbead.php +++ b/lang/en/enrol_ilbead.php @@ -122,3 +122,7 @@ $string['timeend'] = 'Expected time end'; $string['maxongoingmessage'] = 'You are already enrolled in {$a} ILB/EAD courses, New enrollments will only be accepted after the completion of at least one of them.'; $string['customenrolmessage'] = 'Custom enrol message'; $string['customenrolmessage_help'] = 'A custom message may be displayed at enrol form as plain text or Moodle-auto format, including HTML tags and multi-lang tags.'; +$string['samecoursealert'] = 'Wrong classroom!'; +$string['samecoursemessage'] = 'You are already enrolled in this course, but in another class!
+Your correct classroom is {$a}.'; +$string['alreadyenroled'] = 'You are already enrolled in this but cannot access them.'; diff --git a/lang/pt_br/enrol_ilbead.php b/lang/pt_br/enrol_ilbead.php index ec6a103..06bdbb8 100644 --- a/lang/pt_br/enrol_ilbead.php +++ b/lang/pt_br/enrol_ilbead.php @@ -122,3 +122,7 @@ $string['timeend'] = 'Data prevista de término'; $string['maxongoingmessage'] = 'Você já está matriculado em {$a} curso(s) sem tutoria, Novas matrículas somente serão aceitas após a conclusão de pelo menos um deles.'; $string['customenrolmessage'] = 'Mensagem personalizada de matrícula'; $string['customenrolmessage_help'] = 'Uma mensagem personalizada que pode ser exibida no formulário de inscrição como um texto plano ou no padrão de autoformatação Moodle, incluindo tags HTML e multi-linguagem.'; +$string['samecoursealert'] = 'Turma errada!'; +$string['samecoursemessage'] = 'Você já está matriculado neste curso, mas em outra turma!
+Sua turma correta é {$a}.'; +$string['alreadyenroled'] = 'Você já está inscrito neste curso mas não pode acessá-lo.'; diff --git a/lib.php b/lib.php index d86b945..d75ec2b 100644 --- a/lib.php +++ b/lib.php @@ -201,9 +201,10 @@ class enrol_ilbead_plugin extends enrol_plugin { // Can not enrol guest!! return null; } + if ($DB->record_exists('user_enrolments', array('userid'=>$USER->id, 'enrolid'=>$instance->id))) { - //TODO: maybe we should tell them they are already enrolled, but can not access the course - return null; + $error = get_string('alreadyenroled', 'enrol_ilbead'); + return $OUTPUT->box($error).$OUTPUT->continue_button("$CFG->wwwroot/index.php"); } if ($instance->enrolstartdate != 0 and $instance->enrolstartdate > time()) { @@ -221,8 +222,9 @@ class enrol_ilbead_plugin extends enrol_plugin { return null; } + $ongoing = $this->get_ongoing($instance); + if ($instance->customint7 !== null and $instance->customint7 > 0) { - $ongoing = $this->get_ongoing($instance); if (count($ongoing) >= $instance->customint7) { // Max ongoing EAD courses reached. New enrol not allowed $error = $OUTPUT->error_text(get_string('maxongoing', 'enrol_ilbead')); @@ -242,6 +244,22 @@ class enrol_ilbead_plugin extends enrol_plugin { } } + $course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST); + $course_prefix = explode('.', $course->idnumber); + $course_prefix = $course_prefix[0]; + + foreach ($ongoing as $course) { + $ongoing_prefix = explode('.', $course->idnumber); + $ongoing_prefix = $ongoing_prefix[0]; + if ($course_prefix == $ongoing_prefix) { + $error = $OUTPUT->error_text(get_string('samecoursealert', 'enrol_ilbead')); + $link = ''.$course->fullname.''; + $error .= '

'.get_string('samecoursemessage', 'enrol_ilbead', $link).'

'; + $error = $OUTPUT->box($error).$OUTPUT->continue_button("$CFG->wwwroot/index.php"); + return $error; + } + } + if ($instance->customint5) { require_once("$CFG->dirroot/cohort/lib.php"); if (!cohort_is_member($instance->customint5, $USER->id)) {