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);
 }
 function __construct()
 {
     global $USER, $CFG;
     parent::__construct($USER, $CFG->current_app);
     $this->getRoleManager()->setPermissionsOnRoles();
     if ($this->getRoleManager()->hasPrivilege('Student')) {
         $this->updateProfilePicture();
     }
 }
Example #3
0
 /**
  * Returns a list of teachers that should be grading given submission
  *
  * @param object $user
  * @return array
  */
 function get_graders($user)
 {
     global $DB;
     //potential graders
     list($enrolledsql, $params) = get_enrolled_sql($this->context, 'mod/assignment:grade', 0, true);
     $sql = "SELECT u.*\n                  FROM {user} u\n                  JOIN ({$enrolledsql}) je ON je.id = u.id";
     $potgraders = $DB->get_records_sql($sql, $params);
     $graders = array();
     if (groups_get_activity_groupmode($this->cm) == SEPARATEGROUPS) {
         // Separate groups are being used
         if ($groups = groups_get_all_groups($this->course->id, $user->id)) {
             // Try to find all groups
             foreach ($groups as $group) {
                 foreach ($potgraders as $t) {
                     if ($t->id == $user->id) {
                         continue;
                         // do not send self
                     }
                     if (groups_is_member($group->id, $t->id)) {
                         $graders[$t->id] = $t;
                     }
                 }
             }
         } else {
             // user not in group, try to find graders without group
             foreach ($potgraders as $t) {
                 if ($t->id == $user->id) {
                     continue;
                     // do not send self
                 }
                 if (!groups_get_all_groups($this->course->id, $t->id)) {
                     //ugly hack
                     $graders[$t->id] = $t;
                 }
             }
         }
     } else {
         // OVERWRITE 1: replacement, changed from:
         //foreach ($potgraders as $t) {
         // changed to:
         global $CFG;
         $course_context = get_context_instance(CONTEXT_COURSE, $this->course->id);
         foreach ($potgraders as $t) {
             $mdl_user = new GcrMdlUser($t, $CFG->current_app);
             if (!$mdl_user->getRoles($course_context)) {
                 continue;
             }
             // END OVERWRITE 1
             if ($t->id == $user->id) {
                 continue;
                 // do not send self
             }
             $graders[$t->id] = $t;
         }
     }
     return $graders;
 }
 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);
         }
     }
 }
Example #5
0
 public static function add_to_course($values)
 {
     global $CFG;
     $params = array();
     $eschool = Doctrine::getTable('GcrEschool')->findOneById($values['eschoolid']);
     $mdl_course = $eschool->getCourse($values['courseid']);
     if (!$mdl_course) {
         $CFG->current_app->gcError('Course with id: ' . $values['courseid'] . ' not found', 'gcdatabaseerror');
     }
     try {
         foreach ($values['potentialusers'] as $key => $userid) {
             $mdl_user_obj = $eschool->selectFromMdlTable('user', 'id', $userid, true);
             $mdl_user = new GcrMdlUser($mdl_user_obj, $eschool);
             $mdl_user->enrolUserinCourse($mdl_course, $eschool, $values['roleid']);
         }
         return true;
     } catch (Exception $e) {
         $CFG->current_app->gcError('something wen\'t wrong with adding users to course. ' . $e);
     }
     return false;
 }
function remove_submit(Pieform $form, $values)
{
    $eschool = Doctrine::getTable('GcrEschool')->findOneById($values['eschoolid']);
    $owner = $eschool->getOwnerUser();
    ArtefactTypeEschooladmin::authorize_eschool($eschool);
    foreach ($values['users'] as $user) {
        if ($user != $owner->getObject()->username) {
            $mdl_user_obj = $eschool->selectFromMdlTable('user', 'username', $user, true);
            if ($mdl_user_obj) {
                $mdl_user = new GcrMdlUser($mdl_user_obj, $eschool);
                $mdl_user->removeAccess();
            }
        }
    }
    redirect("/artefact/eschooladmin/migrateusers.php?eschoolid=" . $values['eschoolid']);
}
 public function setUser($mhr_user, $system_roles = array())
 {
     if (!($host_id = $this->getMnetHostId($mhr_user->getApp()))) {
         global $CFG;
         $CFG->current_app->gcError('User from unknown host ' . $mhr_user->getApp()->getShortName() . ', cannot add.', 'gcdatabaseerror');
     }
     $mhr_user_object = $mhr_user->getObject();
     if (!($mdl_user = $this->getUser($mhr_user))) {
         $params = array('auth' => 'mnet', 'confirmed' => 1, 'mnethostid' => $host_id, 'username' => $mhr_user_object->username, 'firstname' => $mhr_user_object->firstname, 'lastname' => $mhr_user_object->lastname, 'email' => $mhr_user_object->email);
         $mdl_user_object = $this->insertIntoMdlTable('user', $params);
         $mdl_user = new GcrMdlUser($mdl_user_object, $this);
     }
     foreach ($system_roles as $system_role) {
         $this->setMdlRoleAssignment($system_role, 1, $mdl_user->getObject()->id);
     }
     return $mdl_user;
 }
 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;
 }
 public function isInstructor(GcrMdlUser $user)
 {
     foreach ($this->getMdlInstructors() as $mdl_user) {
         if ($mdl_user->id == $user->getObject()->instructorid) {
             return true;
         }
     }
     return false;
 }