|
| 1 | +<?php |
| 2 | + |
| 3 | +// This file is part of Moodle - http://moodle.org/ |
| 4 | +// |
| 5 | +// Moodle is free software: you can redistribute it and/or modify |
| 6 | +// it under the terms of the GNU General Public License as published by |
| 7 | +// the Free Software Foundation, either version 3 of the License, or |
| 8 | +// (at your option) any later version. |
| 9 | +// |
| 10 | +// Moodle is distributed in the hope that it will be useful, |
| 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +// GNU General Public License for more details. |
| 14 | +// |
| 15 | +// You should have received a copy of the GNU General Public License |
| 16 | +// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +/** |
| 19 | + * Main code for Enrolment duration image block. |
| 20 | + * |
| 21 | + * @package block_enrol_duration |
| 22 | + * @copyright 2012 Nathan Robbins (https://github.com/nrobbins) |
| 23 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 24 | + */ |
| 25 | + |
| 26 | +class block_enrol_duration extends block_base { |
| 27 | + |
| 28 | + function init() { |
| 29 | + $this->title = get_string('pluginname', 'block_enrol_duration'); |
| 30 | + } |
| 31 | + |
| 32 | + function applicable_formats() { |
| 33 | + return array( |
| 34 | + 'all' => false, |
| 35 | + 'course' => true |
| 36 | + ); |
| 37 | + } |
| 38 | + |
| 39 | + function specialization() { |
| 40 | + $this->title = isset($this->config->title) ? format_string($this->config->title) : format_string(get_string('pluginname', 'block_enrol_duration')); |
| 41 | + } |
| 42 | + |
| 43 | + function instance_allow_multiple() { |
| 44 | + return false; |
| 45 | + } |
| 46 | + |
| 47 | + function get_content() { |
| 48 | + global $CFG, $USER, $DB; |
| 49 | + require_once('lib.php'); |
| 50 | + |
| 51 | + if ($this->content !== null) { |
| 52 | + return $this->content; |
| 53 | + } |
| 54 | + |
| 55 | + $userid = $USER->id; |
| 56 | + $courseid = $this->page->course->id; |
| 57 | + |
| 58 | + $duration = $DB->get_record_sql('SELECT ue.timeend '. |
| 59 | + 'FROM {user_enrolments} ue, {enrol} e '. |
| 60 | + 'WHERE ue.userid = ? '. |
| 61 | + 'AND ue.enrolid = e.id '. |
| 62 | + 'AND e.courseid= ?', array($userid, $courseid)); |
| 63 | + |
| 64 | + $this->content = new stdClass; |
| 65 | + |
| 66 | + if ($duration && ($duration->timeend > time())) { |
| 67 | + $days = ceil(($duration->timeend - time())/ 86400); |
| 68 | + $weeks = $days / 7; |
| 69 | + $date = getdate($duration->timeend); |
| 70 | + /* Future support for international date formats |
| 71 | + if($this->config->dateformat = 'mdy'){ |
| 72 | + $fulldate = $date['month'] .' '. $date['mday'] .', '. $date['year']; |
| 73 | + } else { |
| 74 | + $fulldate = $date['mday'] .' '. $date['month'] .', '. $date['year']; |
| 75 | + } |
| 76 | + */ |
| 77 | + setlocale(LC_ALL,'pt_BR'); |
| 78 | + $fulldate = $date['mday'] . ' de '. strftime('%B',$duration->timeend) .' de '. $date['year']; |
| 79 | + $coursename = $this->page->course->fullname; |
| 80 | + |
| 81 | + $this->content->text = '<p>'.get_string('enrolmentin', 'block_enrol_duration').' <em>'.$coursename.'</em> '. |
| 82 | + get_string('expiresin', 'block_enrol_duration').'<br>'; |
| 83 | + $this->content->text .= '<strong>'.$days.' '.get_string('days', 'block_enrol_duration').'</strong>'; |
| 84 | + $this->content->text .= ': '.$fulldate.'.</p>'.'<p>Horário de Brasília, DF.</p>'; |
| 85 | + } else { |
| 86 | + $this->content->text = '<p>'.get_string('enrolmentin', 'block_enrol_duration').' <em>'.$this->page->course->fullname. |
| 87 | + '</em> '.get_string('noexpiration', 'block_enrol_duration').'.</p>'.'<p>Horário de Brasília, DF.</p>'; |
| 88 | + } |
| 89 | + $this->content->footer = ''; |
| 90 | + |
| 91 | + return $this->content; |
| 92 | + } |
| 93 | +} |
0 commit comments