MDL-26034 myprofile block cleanup
[moodle.git] / blocks / myprofile / block_myprofile.php
CommitLineData
03d9401e 1<?php
03d9401e
MD
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
0ab727fb
PS
18 * Block displaying information about current logged-in user.
19 *
20 * This block can be used as anti cheating measure, you
21 * can easily check the logged-in user matches the person
22 * operating the computer.
03d9401e 23 *
0ab727fb
PS
24 * @package block
25 * @subpackage myprofile
03d9401e
MD
26 * @copyright 2010 Remote-Learner.net
27 * @author Olav Jordan <olav.jordan@remote-learner.ca>
28 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29 */
30
0ab727fb
PS
31defined('MOODLE_INTERNAL') || die();
32
03d9401e 33/**
0ab727fb 34 * Displays the current user's profile information.
03d9401e
MD
35 *
36 * @copyright 2010 Remote-Learner.net
37 * @author Olav Jordan <olav.jordan@remote-learner.ca>
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39 */
40class block_myprofile extends block_base {
41 /**
42 * block initializations
43 */
44 public function init() {
45 $this->title = get_string('pluginname', 'block_myprofile');
03d9401e
MD
46 }
47
48 /**
49 * block contents
50 *
51 * @return object
52 */
53 public function get_content() {
54 global $CFG, $USER, $DB, $OUTPUT, $PAGE;
55
56 if ($this->content !== NULL) {
57 return $this->content;
58 }
59
0ab727fb
PS
60 if (!isloggedin() or isguestuser()) {
61 return ''; // Never useful unless you are logged in as real users
03d9401e
MD
62 }
63
64 $this->content = new stdClass;
65 $this->content->text = '';
66 $this->content->footer = '';
67
68 $course = $this->page->course;
03d9401e
MD
69
70 if (!isset($this->config->display_picture) || $this->config->display_picture == 1) {
71 $this->content->text .= '<div class="myprofileitem picture">';
0ab727fb 72 $this->content->text .= $OUTPUT->user_picture($USER, array('courseid'=>$course->id, 'size'=>'100', 'class'=>'profilepicture')); // The new class makes CSS easier
03d9401e
MD
73 $this->content->text .= '</div>';
74 }
75
0ab727fb 76 $this->content->text .= '<div class="myprofileitem fullname">'.fullname($USER).'</div>';
03d9401e
MD
77
78 if(!isset($this->config->display_country) || $this->config->display_country == 1) {
79 $countries = get_string_manager()->get_list_of_countries();
0ab727fb 80 if (isset($countries[$USER->country])) {
db9a1414 81 $this->content->text .= '<div class="myprofileitem country">';
0ab727fb 82 $this->content->text .= get_string('country') . ': ' . $countries[$USER->country];
db9a1414
DM
83 $this->content->text .= '</div>';
84 }
03d9401e
MD
85 }
86
87 if(!isset($this->config->display_city) || $this->config->display_city == 1) {
88 $this->content->text .= '<div class="myprofileitem city">';
0ab727fb 89 $this->content->text .= get_string('city') . ': ' . format_string($USER->city);
03d9401e
MD
90 $this->content->text .= '</div>';
91 }
92
93 if(!isset($this->config->display_email) || $this->config->display_email == 1) {
94 $this->content->text .= '<div class="myprofileitem email">';
0ab727fb 95 $this->content->text .= obfuscate_mailto($USER->email, '');
03d9401e
MD
96 $this->content->text .= '</div>';
97 }
98
0ab727fb 99 if(!empty($this->config->display_icq) && !empty($USER->icq)) {
03d9401e 100 $this->content->text .= '<div class="myprofileitem icq">';
0ab727fb 101 $this->content->text .= 'ICQ: ' . s($USER->icq);
03d9401e
MD
102 $this->content->text .= '</div>';
103 }
104
0ab727fb 105 if(!empty($this->config->display_skype) && !empty($USER->skype)) {
03d9401e 106 $this->content->text .= '<div class="myprofileitem skype">';
0ab727fb 107 $this->content->text .= 'Skype: ' . s($USER->skype);
03d9401e
MD
108 $this->content->text .= '</div>';
109 }
110
0ab727fb 111 if(!empty($this->config->display_yahoo) && !empty($USER->yahoo)) {
03d9401e 112 $this->content->text .= '<div class="myprofileitem yahoo">';
0ab727fb 113 $this->content->text .= 'Yahoo: ' . s($USER->yahoo);
03d9401e
MD
114 $this->content->text .= '</div>';
115 }
116
0ab727fb 117 if(!empty($this->config->display_aim) && !empty($USER->aim)) {
03d9401e 118 $this->content->text .= '<div class="myprofileitem aim">';
0ab727fb 119 $this->content->text .= 'AIM: ' . s($USER->aim);
03d9401e
MD
120 $this->content->text .= '</div>';
121 }
122
0ab727fb 123 if(!empty($this->config->display_msn) && !empty($USER->msn)) {
03d9401e 124 $this->content->text .= '<div class="myprofileitem msn">';
0ab727fb 125 $this->content->text .= 'MSN: ' . s($USER->msn);
03d9401e
MD
126 $this->content->text .= '</div>';
127 }
128
0ab727fb 129 if(!empty($this->config->display_phone1) && !empty($USER->phone1)) {
03d9401e 130 $this->content->text .= '<div class="myprofileitem phone1">';
0ab727fb 131 $this->content->text .= get_string('phone').': ' . s($USER->phone1);
03d9401e
MD
132 $this->content->text .= '</div>';
133 }
134
0ab727fb 135 if(!empty($this->config->display_phone2) && !empty($USER->phone2)) {
03d9401e 136 $this->content->text .= '<div class="myprofileitem phone2">';
0ab727fb 137 $this->content->text .= get_string('phone').': ' . s($USER->phone2);
03d9401e
MD
138 $this->content->text .= '</div>';
139 }
140
0ab727fb 141 if(!empty($this->config->display_institution) && !empty($USER->institution)) {
03d9401e 142 $this->content->text .= '<div class="myprofileitem institution">';
0ab727fb 143 $this->content->text .= format_string($USER->institution);
03d9401e
MD
144 $this->content->text .= '</div>';
145 }
146
0ab727fb 147 if(!empty($this->config->display_address) && !empty($USER->address)) {
03d9401e 148 $this->content->text .= '<div class="myprofileitem address">';
0ab727fb 149 $this->content->text .= format_string($USER->address);
03d9401e
MD
150 $this->content->text .= '</div>';
151 }
152
0ab727fb 153 if(!empty($this->config->display_firstaccess) && !empty($USER->firstaccess)) {
03d9401e 154 $this->content->text .= '<div class="myprofileitem firstaccess">';
0ab727fb 155 $this->content->text .= get_string('firstaccess').': ' . userdate($USER->firstaccess);
03d9401e
MD
156 $this->content->text .= '</div>';
157 }
158
0ab727fb 159 if(!empty($this->config->display_lastaccess) && !empty($USER->lastaccess)) {
03d9401e 160 $this->content->text .= '<div class="myprofileitem lastaccess">';
0ab727fb 161 $this->content->text .= get_string('lastaccess').': ' . userdate($USER->lastaccess);
03d9401e
MD
162 $this->content->text .= '</div>';
163 }
164
0ab727fb 165 if(!empty($this->config->display_currentlogin) && !empty($USER->currentlogin)) {
03d9401e 166 $this->content->text .= '<div class="myprofileitem currentlogin">';
0ab727fb 167 $this->content->text .= get_string('login').': ' . userdate($USER->currentlogin);
03d9401e
MD
168 $this->content->text .= '</div>';
169 }
170
0ab727fb 171 if(!empty($this->config->display_lastip) && !empty($USER->lastip)) {
03d9401e 172 $this->content->text .= '<div class="myprofileitem lastip">';
0ab727fb 173 $this->content->text .= 'IP: ' . $USER->lastip;
03d9401e
MD
174 $this->content->text .= '</div>';
175 }
176
03d9401e
MD
177 return $this->content;
178 }
179
180 /**
181 * allow the block to have a configuration page
182 *
183 * @return boolean
184 */
185 public function has_config() {
186 return false;
187 }
188
189 /**
190 * allow more than one instance of the block on a page
191 *
192 * @return boolean
193 */
194 public function instance_allow_multiple() {
195 //allow more than one instance on a page
196 return false;
197 }
198
199 /**
200 * allow instances to have their own configuration
201 *
202 * @return boolean
203 */
204 function instance_allow_config() {
205 //allow instances to have their own configuration
206 return false;
207 }
208
209 /**
210 * instance specialisations (must have instance allow config true)
211 *
212 */
213 public function specialization() {
214 }
215
216 /**
217 * displays instance configuration form
218 *
219 * @return boolean
220 */
221 function instance_config_print() {
e43485bb 222 return false;
03d9401e 223
e43485bb 224 /*
03d9401e
MD
225 global $CFG;
226
227 $form = new block_myprofile.phpConfigForm(null, array($this->config));
228 $form->display();
229
230 return true;
e43485bb 231 */
03d9401e
MD
232 }
233
234 /**
235 * locations where block can be displayed
236 *
237 * @return array
238 */
239 public function applicable_formats() {
240 return array('all'=>true);
241 }
242
243 /**
244 * post install configurations
245 *
246 */
247 public function after_install() {
248 }
249
250 /**
251 * post delete configurations
252 *
253 */
254 public function before_delete() {
255 }
256
257}