db4ac163c99eeaa0ac7907c1fa1121e1c8ca1a69
[moodle.git] / blocks / mentees / block_mentees.php
1 <?php
3 class block_mentees extends block_base {
5     function init() {
6         $this->title = get_string('blockname', 'block_mentees');
7         $this->version = 2007101509;
8     }
10     function applicable_formats() {
11         return array('all' => true, 'tag' => false);
12     }
14     function specialization() {
15         $this->title = isset($this->config->title) ? $this->config->title : get_string('newmenteesblock', 'block_mentees');
16     }
18     function instance_allow_multiple() {
19         return true;
20     }
22     function get_content() {
23         global $CFG, $USER, $DB;
25         if ($this->content !== NULL) {
26             return $this->content;
27         }
29         // get all the mentees, i.e. users you have a direct assignment to
30         if ($usercontexts = $DB->get_records_sql("SELECT c.instanceid, c.instanceid, u.firstname, u.lastname
31                                                     FROM {role_assignments} ra, {context} c, {user} u
32                                                    WHERE ra.userid = ?
33                                                          AND ra.contextid = c.id
34                                                          AND c.instanceid = u.id
35                                                          AND c.contextlevel = ".CONTEXT_USER, array($USER->id))) {
37             $this->content->text = '<ul>';
38             foreach ($usercontexts as $usercontext) {
39                 $this->content->text .= '<li><a href="'.$CFG->wwwroot.'/user/view.php?id='.$usercontext->instanceid.'&amp;course='.SITEID.'">'.fullname($usercontext).'</a></li>';
40             }
41             $this->content->text .= '</ul>';
42         }
44         $this->content->footer = '';
46         return $this->content;
47     }
48 }