1
+ <?php //$Id: block_userexpire.php,v 1.0 2016-02-22 22:00:00 jrader Exp $
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
+ *
20
+ * @package moodlecore
21
+ * @subpackage block
22
+ * @copyright 2012 Jeff Rader - Sunset Online
23
+ * @author 2012 Jeff Rader <[email protected] >
24
+ * @version 1.0
25
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
+ */
27
+
28
+ class block_userexpire extends block_base {
29
+
30
+ function init () {
31
+ $ this ->title = get_string ('pluginname ' ,'block_userexpire ' );
32
+ }
33
+
34
+ function get_content () {
35
+ global $ CFG , $ OUTPUT , $ USER , $ course , $ DB ;
36
+
37
+ require_once ($ CFG ->dirroot .'/message/lib.php ' );
38
+
39
+ if ($ this ->content !== NULL ) {
40
+ return $ this ->content ;
41
+ }
42
+
43
+ $ this ->content = new stdClass ;
44
+ $ this ->content ->text = '' ;
45
+
46
+ if (isloggedin () && is_object ($ course )) {
47
+ if ($ course ->id != SITEID ) {
48
+ $ sql = 'SELECT ue.id, ue.timestart, ue.timeend
49
+ FROM mdl_user_enrolments ue
50
+ JOIN mdl_enrol e on ue.enrolid = e.id
51
+ WHERE ue.userid = ? AND e.courseid = ? ' ;
52
+
53
+ $ records = $ DB ->get_records_sql ($ sql , array ($ USER ->id , $ course ->id ));
54
+ $ student = reset ($ records );
55
+ if (isset ($ student ->timeend ) && $ student ->timeend >0 ) {
56
+ $ this ->title = get_string ('expiretitle ' , 'block_userexpire ' );
57
+ $ this ->content ->text .= get_string ('expirelabel ' , 'block_userexpire ' ).": " .date (get_string ('strftimedate ' , 'block_userexpire ' ),$ student ->timeend );
58
+ $ this ->content ->text .= " ( " .floor (($ student ->timeend - time ())/(24 *60 *60 ))." " .get_string ('expireday ' , 'block_userexpire ' ).", " .
59
+ floor ((($ student ->timeend - time ())%(24 *60 *60 ))/3600 )." " .get_string ('expirehours ' , 'block_userexpire ' ).") " ;
60
+ } else {
61
+ $ this ->title = get_string ('enrolltitle ' , 'block_userexpire ' );
62
+ $ link = new moodle_url ('/enrol/index.php ' , array ('id ' => $ course ->id ));
63
+ $ this ->content ->text .= '<a href=" ' .$ link ->out ().'"> ' .get_string ('enrolltext ' , 'block_userexpire ' ).'</a> ' ;
64
+ }
65
+ }
66
+ }
67
+
68
+ $ this ->content ->footer = '' ;
69
+ return $ this ->content ;
70
+ }
71
+
72
+ }
73
+ ?>
0 commit comments