From 635480a93cbd64390a3b2e7e023feb9fc5c03885 Mon Sep 17 00:00:00 2001 From: Sesostris Vieira Date: Fri, 28 Feb 2014 16:57:38 -0300 Subject: [PATCH] Melhorias no plugin de enrol --- lang/en/enrol_ilbead.php | 4 ++ lang/pt_br/enrol_ilbead.php | 6 ++- lib.php | 85 ++++++++++++------------------------- locallib.php | 10 ----- 4 files changed, 35 insertions(+), 70 deletions(-) diff --git a/lang/en/enrol_ilbead.php b/lang/en/enrol_ilbead.php index 71150da..fb1f641 100644 --- a/lang/en/enrol_ilbead.php +++ b/lang/en/enrol_ilbead.php @@ -116,3 +116,7 @@ $string['enrolledat'] = 'enrolled at'; $string['abandonalert'] = 'You have abandoned courses and cannot enroll in new courses.'; $string['abandonpunishment'] = 'Days of punishment for abandon'; $string['abandonpunishment_help'] = 'Number of days that the user cannot enroll in another ILB EAD course after abandon any ILB EAD course.'; +$string['coursename'] = 'Course name'; +$string['timestart'] = 'Time start'; +$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.'; diff --git a/lang/pt_br/enrol_ilbead.php b/lang/pt_br/enrol_ilbead.php index 4711cb9..bd0ff67 100644 --- a/lang/pt_br/enrol_ilbead.php +++ b/lang/pt_br/enrol_ilbead.php @@ -114,5 +114,9 @@ $string['ongoingcourses'] = 'Lista de cursos que você não concluiu'; $string['abandonedcourses'] = 'Cursos abandonados'; $string['enrolledat'] = 'inscrito em'; $string['abandonalert'] = 'Você abandonou curso(s) e não pode se inscrever em novos cursos.'; -$string['abandonpunishment'] = 'Dias de punição por abandono'; +$string['abandonpunishment'] = 'Dias de suspensão por abandono/reprovação'; $string['abandonpunishment_help'] = 'Número de dias que o aluno não poderá se inscrever em outro curso EAD do ILB depois de ter abandonado um curso.'; +$string['coursename'] = 'Nome do curso'; +$string['timestart'] = 'Data de início'; +$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.'; diff --git a/lib.php b/lib.php index 3ab3033..49812ff 100644 --- a/lib.php +++ b/lib.php @@ -222,29 +222,23 @@ class enrol_ilbead_plugin extends enrol_plugin { } if ($instance->customint7 !== null and $instance->customint7 > 0) { - $ongoing = $this->get_ongoing(); + $ongoing = $this->get_ongoing($instance); if (count($ongoing) >= $instance->customint7) { // Max ongoing EAD courses reached. New enrol not allowed - $s = get_string('maxongoing', 'enrol_ilbead').'

'; - $s .= '' . get_string('ongoingcourses', 'enrol_ilbead') . ':
'; + $error = $OUTPUT->error_text(get_string('maxongoing', 'enrol_ilbead')); + $error .= '

'.get_string('maxongoingmessage', 'enrol_ilbead', count($ongoing)).'

'; + $error .= '

'.get_string('ongoingcourses', 'enrol_ilbead').'

'; + $table = new html_table(); + $table->head = array(get_string('coursename', 'enrol_ilbead'), get_string('timestart', 'enrol_ilbead'), get_string('timeend', 'enrol_ilbead'), get_string('abandonpunishment', 'enrol_ilbead')); + $tabledata = array(); foreach ($ongoing as $course) { - $s .= "{$course->fullname}
"; + $link = ''.$course->fullname.''; + $tabledata[] = array($link, userdate($course->timestart), userdate($course->timeend), $course->abandonpunishment); } - return $OUTPUT->box($s); - } - } - - if ($instance->customint8 !== null and $instance->customint8 > 0) { - $abandoned = $this->abandon_courses($instance); - if (count($abandoned) > 0) { - $s = get_string('abandonalert', 'enrol_ilbead').'

'; - $s .= '' . get_string('abandonedcourses', 'enrol_ilbead') . ':
'; - $enrolledat = get_string('enrolledat', 'enrol_ilbead'); - foreach ($abandoned as $course) { - $date = userdate($course->timecreated); - $s .= "{$course->fullname}, $enrolledat $date
"; - } - return $OUTPUT->box($s); + $table->data = $tabledata; + $error .= html_writer::table($table); + $error = $OUTPUT->box($error).$OUTPUT->continue_button("$CFG->wwwroot/index.php"); + return $error; } } @@ -617,19 +611,20 @@ class enrol_ilbead_plugin extends enrol_plugin { * @return array ongoing EAD courses */ - public function get_ongoing() { + public function get_ongoing($instance) { global $DB; global $USER; - return $DB->get_records_sql(" - select ue.timecreated, c.fullname - from {user_enrolments} ue - join {enrol} e on e.id = ue.enrolid - join {course} c on c.id = e.courseid - left outer join {course_completions} cc on cc.userid = ue.userid and cc.course = e.courseid - where e.enrol = 'ilbead' - and cc.timecompleted is null - and ue.timecreated > ? - and ue.userid = ?", array(time() - (60*86400), $USER->id)); + $sql = "select c.*, ue.timestart, ue.timeend, e.customint8 as abandonpunishment + from {user_enrolments} ue + join {enrol} e on e.id = ue.enrolid + join {course} c on c.id = e.courseid + left outer join {course_completions} cc on cc.userid = ue.userid and cc.course = e.courseid + where e.enrol = 'ilbead' + and cc.timecompleted is null + and ue.userid = ? + and ? between ue.timestart and ue.timeend + (e.customint8*86400)"; + $time = time(); + return $DB->get_records_sql($sql, array($USER->id, time())); } /** @@ -644,7 +639,7 @@ class enrol_ilbead_plugin extends enrol_plugin { return false; // We have not a max ongoing, then its never reached } - $ongoing = $this->get_ongoing(); + $ongoing = $this->get_ongoing($instance); if (count($ongoing) >= $instance->customint7) { return true; // Max ongoing reached @@ -652,32 +647,4 @@ class enrol_ilbead_plugin extends enrol_plugin { return false; // Default max not reached } - - /** - * Abandon courses - * Get all abandoned courses in last 'customint8' days - * - * @param stdClass $instance - * @return array of courses - */ - - public function abandon_courses($instance) { - global $DB; - global $USER; - - if ($instance->customint8 == null or $instance->customint8 == 0) { - return null; // No abandon punishment - } - - return $DB->get_records_sql(" - select ue.timecreated, c.fullname - from {user_enrolments} ue - join {enrol} e on e.id = ue.enrolid - join {course} c on c.id = e.courseid - left outer join {course_completions} cc on cc.userid = ue.userid and cc.course = e.courseid - where e.enrol = 'ilbead' - and cc.timecompleted is null - and ue.userid = ? - and ? between ue.timecreated + ? and ue.timecreated + ?", array($USER->id, time(), 60*86400, (60+$instance->customint8)*86400)); - } } diff --git a/locallib.php b/locallib.php index e7394c7..fa1ea3e 100644 --- a/locallib.php +++ b/locallib.php @@ -63,16 +63,6 @@ class enrol_ilbead_enrol_form extends moodleform { } } - if ($plugin->max_ongoing_reached($instance)) { - $ongoing = $plugin->get_ongoing($instance); - $mform->addElement('static', 'notice', '', get_string('maxongoing', 'enrol_ilbead')); - $mform->addElement('static', 'notice', '', get_string('ongoingcourses', 'enrol_ilbead')); - foreach ($ongoing as $course) { - $mform->addElement('static', 'notice', '', $course->fullname); - } - return; - } - if ($instance->password) { // Change the id of ilbead enrolment key input as there can be multiple ilbead enrolment methods. $mform->addElement('passwordunmask', 'enrolpassword', get_string('password', 'enrol_ilbead'),