示例#1
0
 function is_capable()
 {
     global $USER;
     $mentors = lookup_mentors($this->obj);
     return in_array($USER->id, array_keys($mentors)) || parent::is_capable();
 }
示例#2
0
文件: lib.php 项目: rrusso/EARS
 function process($data)
 {
     global $CFG, $USER;
     $this->process_referrals();
     // Process Attachment
     $course = get_record('course', 'id', $this->courseid);
     list($attachmentname, $attachment) = $this->process_attachment($course);
     // Outputing info as mtrace in case developers want to report
     // as Moodle cron
     mtrace('<div class="report_wrap">
             <h2 class="">' . get_string('sending', 'block_student_gradeviewer') . '</h2>
             <ul class="student_list">');
     // Set the from here; If the teacher sends anonymously,
     // then send with a no reply
     $from = isset($data->anonymous) ? get_string('noreplyname') : $USER;
     // Foreach user, send report to mentor
     foreach ($this->users as $id => $user) {
         // Find the section the user is enrolled in
         $section = lookup_section($user, $course);
         // Format section: DEPT 1001 - 001
         $a->course = get_string('format_section', 'block_courseprefs', $section);
         // Format User's fullname: Firstname Lastname
         $a->user = fullname($user);
         // DEPT 1001 - 001 Report For Firstname Lastname
         $subject = get_string('subject_report', 'block_student_gradeviewer', $a);
         // Mentee link in student_grade viewer
         $grade_link = $CFG->wwwroot . '/blocks/student_gradeviewer/mentee.php?id=' . $id . ($this->courseid ? '&amp;courseid=' . $this->courseid : '');
         // Grades Overview for Firstname Lastname:
         $mentee = get_string('grade_link', 'block_student_gradeviewer', $a);
         $body = $data->report;
         mtrace('<li><h2>' . $a->user . '</h2>
                 <ul class="student_list">');
         // Get this user's mentors to email, if any at all
         $mentors = lookup_mentors($user);
         if (!$mentors) {
             mtrace('<li>' . get_string('no_mentor', 'block_student_gradeviewer', $a) . '</li></ul></li>');
             continue;
         }
         // If any mentors email them what the teacher said
         foreach ($mentors as $mentor) {
             $code = 'success';
             mtrace('<li>' . get_string('mentor', 'block_student_gradeviewer', $mentor));
             $result = email_to_user($mentor, $from, $subject, format_text_email($body . "\n" . $mentee . $grade_link, 1), format_text($body . "<br/>" . $mentee . '<a href="' . $grade_link . '">' . $grade_link . '</a>', 1), $attachment, $attachmentname);
             // Email failed
             if (!$result) {
                 $code = 'fail';
             }
             mtrace(get_string($code, 'block_student_gradeviewer') . '</li>');
         }
         mtrace('</ul></li>');
     }
     mtrace('  </ul>');
     if ($this->courseid) {
         print_continue($CFG->wwwroot . '/course/view.php?id=' . $this->courseid);
     }
     mtrace('</div>');
 }