function copyFromBlock(GcrMdlBlockCourseProfile $parent_block, GcrMdlCourse $course) { $obj = $parent_block->getObject(); // If the instructor set on the parent block also has a teaching role // on this course, copy that instructorid. Otherwise, set it to the // default instructor of this course. $instructorid = 0; $courseid = $course->getObject()->id; $course_context_id = $course->getContext()->id; $instructor = $parent_block->getApp()->getUserById($obj->instructorid); if ($instructor && $course->isInstructor($instructor)) { $instructorid = $obj->instructorid; } else { $instructor = $course->getInstructor(); if ($instructor) { $instructorid = $instructor->getObject()->id; } else { return false; } } $fs = get_file_storage(); $existing_file = $fs->get_file($course_context_id, 'block_course_profile', 'courseicon', 0, '/', $courseid); if ($existing_file) { $existing_file->delete(); } $file = $fs->get_file($parent_block->getContext()->id, 'block_course_profile', 'courseicon', 0, '/', $obj->courseid); $file_record = array('contextid' => $course_context_id, 'component' => 'block_course_profile', 'filearea' => 'courseicon', 'itemid' => 0, 'filepath' => '/', 'filename' => $courseid, 'userid' => $instructorid); $fs->create_file_from_storedfile($file_record, $file); $data = array('courseid' => $courseid, 'instructorid' => $instructorid, 'courseicon' => $obj->courseicon); $course->getApp()->upsertIntoMdlTable('block_course_profile', $data, array('courseid' => $courseid)); }
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); } } }
protected function compareStartDate(GcrMdlCourse $course) { $result = 0; $course_start_date = $course->getObject()->startdate; $start_date = $this->representative_course->getObject()->startdate; $now = time(); // If one start date is already past, we pick the one in // the future. if ($start_date > $now && $course_start_date <= $now) { $result = -1; } else { if ($course_start_date > $now && $start_date <= $now) { $result = 1; } } if ($result == 0) { // Both dates are in the future, we pick the soonest one. if ($start_date < $course_start_date) { $result = -1; } else { if ($course_start_date < $start_date) { $result = 1; } } // Both dates are in past, pick most recent. $result = $start_date < $now ? $result * -1 : $result; } return $result; }