public function __construct($obj, $eschool)
 {
     parent::__construct($obj, $eschool);
     $this->mdl_enrol = $this->app->selectFromMdlTable('enrol', 'id', $this->obj->enrolid, true);
     $this->course = $this->app->getCourse($this->mdl_enrol->courseid);
     $mdl_user_obj = $this->app->selectFromMdlTable('user', 'id', $this->obj->userid, true);
     $mdl_user = new GcrMdlUser($mdl_user_obj, $this->app);
     $this->user = $mdl_user->getUserOnInstitution();
     $short_name = $this->app->getShortName();
     $sql = 'select * from ' . $short_name . '.mdl_grade_items gi, ' . $short_name . '.mdl_grade_grades gg where gg.userid = ? ' . 'and gi.courseid = ? and gi.itemtype = ? and gg.itemid = gi.id order by gg.timecreated';
     $this->grade_data = $this->app->gcQuery($sql, array($mdl_user->getObject()->id, $this->course->getObject()->id, 'course'), true);
 }
 public function sendEnrolmentEmails($plugin, $mdl_course, $mdl_user_obj)
 {
     $mailstudents = $plugin->get_config('mailstudents');
     $mailteachers = $plugin->get_config('mailteachers');
     $mailadmins = $plugin->get_config('mailadmins');
     $course = new GcrMdlCourse($mdl_course, $this);
     $mdl_user = new GcrMdlUser($mdl_user_obj, $this);
     if (!($mhr_user = $mdl_user->getUserOnInstitution())) {
         return false;
     }
     $mhr_teacher = $course->getInstructor();
     if ($mhr_teacher) {
         $mhr_teacher = $mhr_teacher->getUserOnInstitution();
     }
     $mhr_owner = $this->getOwnerUser();
     if ($mhr_owner) {
         $mhr_owner = $mhr_owner->getUserOnInstitution();
     }
     if (!empty($mailstudents)) {
         $mhr_user_to = $mhr_user;
         if (!($mhr_user_from = $mhr_teacher)) {
             $mhr_user_from = $mhr_owner;
         }
         if ($mhr_user_from) {
             $message_type = 'maharamessage';
             $a = new StdClass();
             $a->coursename = $course->getObject()->fullname;
             $subject = get_string("enrolmentnew", 'enrol_globalclassroom', $course->getObject()->shortname);
             $body = get_string('welcometocoursetext', 'enrol_globalclassroom', $a);
             $this->sendEnrolmentEmailsHelper($subject, $body, $mhr_user_to, $mhr_user_from, $message_type);
         }
     }
     if (!empty($mailteachers)) {
         if ($mhr_user_to = $mhr_teacher) {
             $mhr_user_from = $mhr_user;
             $message_type = 'moodlemessage';
             $a = new StdClass();
             $a->user = $mdl_user->getObject()->firstname . ' ' . $mdl_user->getObject->lastname;
             $a->course = $course->getObject()->fullname;
             $subject = get_string("enrolmentnew", 'enrol_globalclassroom', $course->getObject()->shortname);
             $body = get_string('enrolmentnewuser', 'enrol_globalclassroom', $a);
             $this->sendEnrolmentEmailsHelper($subject, $body, $mhr_user_to, $mhr_user_from, $message_type);
         }
     }
     if (!empty($mailadmins)) {
         $mhr_user_from = $mhr_user;
         if ($mhr_user_to = $mhr_owner) {
             $message_type = 'moodlemessage';
             $a = new StdClass();
             $a->user = $mdl_user->getObject()->firstname . ' ' . $mdl_user->getObject->lastname;
             $a->course = $course->getObject()->fullname;
             $subject = get_string("enrolmentnew", 'enrol_globalclassroom', $course->getObject()->shortname);
             $body = get_string('enrolmentnewuser', 'enrol_globalclassroom', $a);
             $this->sendEnrolmentEmailsHelper($subject, $body, $mhr_user_to, $mhr_user_from, $message_type);
         }
     }
 }
 public function setDeletedUsersOnInstitutionAsDeleted()
 {
     $mdl_users = $this->selectFromMdlTable('user');
     foreach ($mdl_users as $mdl_user_obj) {
         $mdl_user = new GcrMdlUser($mdl_user_obj, $this);
         $mhr_user = $mdl_user->getUserOnInstitution();
         if ($mhr_user) {
             if ($mhr_user->getObject()->deleted == 1) {
                 $this->updateMdlTable('user', array('deleted' => 1), array('id' => $mdl_user_obj->id));
             }
         }
     }
 }
 public static function getInstructorProfileHtml(GcrMdlUser $mdl_user)
 {
     global $CFG;
     $html = '<span class="gc_user_profile">';
     $img = '<img class="gc_user_profile_img" src="' . $mdl_user->getProfileIcon() . '" />';
     $mhr_user = $mdl_user->getUserOnInstitution();
     if ($mhr_user && $mhr_user->getApp()->getShortName() == $CFG->current_app->getShortName()) {
         $html .= '<a class="gc_user_profile_link" href="' . $mhr_user->getHyperlinkToProfile() . '">' . $img . ' <span class="gc_user_profile_fullname">' . GcrInstitutionTable::formatStringSize($mhr_user->getFullnameString(), 22) . '</span></a>';
     } else {
         $html .= $img . ' ' . $mdl_user->getFullnameString();
     }
     $html .= '</span>';
     return $html;
 }