public static function authorizeCourseAccess(GcrMdlCourse $course)
 {
     global $CFG;
     $eschool = $course->getApp();
     $open_access = $eschool->getConfigVar('forcelogin') == 0;
     $visible = $course->isVisible();
     $authorized = false;
     if ($CFG->current_app->hasPrivilege('Student')) {
         $current_user = $CFG->current_app->getCurrentUser();
         if ($current_user->hasAccess($eschool)) {
             $authorized = $CFG->current_app->hasPrivilege('GCStaff');
             if (!$authorized && $CFG->current_app->hasPrivilege('EschoolStaff')) {
                 $authorized = $eschool->getInstitution()->getId() == $CFG->current_app->getInstitution()->getId();
             }
             if (!$authorized) {
                 $authorized = $visible;
                 if (!$authorized) {
                     $mdl_user = $current_user->getUserOnEschool($eschool);
                     $authorized = $mdl_user && $course->isInstructor($mdl_user);
                 }
             }
         }
     } else {
         $authorized = $visible && $open_access;
     }
     return $authorized;
 }
 public function configure()
 {
     $courseArray = array();
     $userArray = array();
     $purchase = false;
     $app = false;
     $key = false;
     if ($this->getObject()->getId()) {
         $purchase = $this->getObject();
     }
     $institution = $this->getOption('eschool');
     $eschools = $institution->getMnetCourses();
     foreach ($eschools as $short_name => $eschool_courses) {
         $eschool = Doctrine::getTable('GcrEschool')->findOneByShortName($short_name);
         foreach ($eschool_courses as $mdl_course) {
             if ($mdl_course->id > 1) {
                 $course = new GcrMdlCourse($mdl_course, $eschool);
                 $cost = number_format($course->getCost(), 2, '.', '');
                 if ($cost) {
                     $cost = '$' . $cost;
                 }
                 $course_fullname = trim($mdl_course->fullname);
                 if (strlen($course_fullname) > 54) {
                     $course_fullname = substr($course_fullname, 0, 50) . '...';
                 }
                 if ($purchase) {
                     $app = $purchase->getPurchaseTypeApp();
                 }
                 if ($purchase && $app && $app->getShortName() == $eschool->getShortName() && $mdl_course->id == $purchase->getPurchaseTypeId()) {
                     $key = $eschool->getShortName() . '#' . $mdl_course->id;
                     $value = $eschool->getShortName() . ': ' . $course_fullname . ' (' . $mdl_course->shortname . ') ' . $cost;
                 } else {
                     $courseArray[$eschool->getShortName() . '#' . $mdl_course->id] = $eschool->getShortName() . ': ' . $course_fullname . ' (' . $mdl_course->shortname . ') ' . $cost;
                 }
             }
         }
     }
     asort($courseArray);
     if ($purchase && $key) {
         $courseArray = array($key => $value) + $courseArray;
     }
     $users = $institution->selectFromMhrTable('usr');
     foreach ($users as $mhr_user) {
         if ($mhr_user->deleted < 1) {
             if ($lastname = trim($mhr_user->lastname)) {
                 $lastname = $lastname . ', ';
             }
             $userArray[$mhr_user->id] = $lastname . $mhr_user->firstname . ' (' . $mhr_user->email . ')';
         }
     }
     asort($userArray);
     $userArray = array(0 => 'Select a User') + $userArray;
     $this->setWidgets(array('id' => new sfWidgetFormInputHidden(), 'purchase_type_id' => new sfWidgetFormSelect(array('choices' => $courseArray), array('style' => 'max-width:50%')), 'amount_field' => new sfWidgetFormInputText(), 'profile_id' => new sfWidgetFormInputText(), 'purchase_type_quantity' => new sfWidgetFormInputText(), 'purchase_user_field' => new sfWidgetFormSelect(array('choices' => $userArray), array('style' => 'max-width:50%')), 'purchase_type_description' => new sfWidgetFormTextArea(), 'bill_cycle' => new sfWidgetFormInputHidden(), 'trans_time' => new sfWidgetFormDate(array('format' => '%month%/%day%/%year%')), 'user_institution_id' => new sfWidgetFormInputHidden(), 'purchase_type_eschool_id' => new sfWidgetFormInputHidden(), 'seller_id' => new sfWidgetFormInputHidden(), 'user_id' => new sfWidgetFormInputHidden(), 'amount' => new sfWidgetFormInputHidden(), 'gc_fee' => new sfWidgetFormInputHidden(), 'owner_fee' => new sfWidgetFormInputHidden(), 'commission_fee' => new sfWidgetFormInputHidden(), 'purchase_type' => new sfWidgetFormInputHidden()));
     $this->widgetSchema->setLabels(array('purchase_type_id' => 'Course:', 'amount_field' => 'Payment Amount:', 'profile_id' => 'Check Number/Paypal TID:', 'purchase_type_quantity' => 'Quantity (# of enrollments):', 'purchase_user_field' => 'Purchasing User:'******'purchase_type_description' => 'Description:', 'trans_time' => 'Date of Transaction:'));
     if ($purchase) {
         $this->widgetSchema->setDefaults(array('purchase_user_field' => $purchase->getUserId(), 'amount_field' => number_format($purchase->getAmount(), 2, '.', '')));
     }
     $this->setValidators(array('id' => new sfValidatorDoctrineChoice(array('model' => $this->getModelName(), 'column' => 'id', 'required' => false)), 'purchase_type_id' => new sfValidatorInteger(array('required' => true, 'min' => 1), array('min' => 'Required.')), 'amount_field' => new sfValidatorNumber(array('required' => true, 'min' => 0), array('min' => 'Invalid Amount.')), 'profile_id' => new sfValidatorString(array('required' => true)), 'purchase_type_description' => new sfValidatorString(array('required' => true)), 'purchase_type_quantity' => new sfValidatorInteger(array('required' => true, 'min' => 1), array('min' => 'Required.')), 'purchase_user_field' => new sfValidatorInteger(array('required' => true, 'min' => 1), array('min' => 'Required.')), 'bill_cycle' => new sfValidatorString(array('required' => true)), 'profile_id' => new sfValidatorString(array('required' => false)), 'trans_time' => new sfValidatorString(array('required' => true)), 'user_institution_id' => new sfValidatorString(array('required' => false)), 'purchase_type_eschool_id' => new sfValidatorString(array('required' => false)), 'purchase_type' => new sfValidatorString(array('required' => false)), 'user_id' => new sfValidatorInteger(array('required' => false)), 'seller_id' => new sfValidatorInteger(array('required' => false)), 'amount' => new sfValidatorNumber(array('required' => false)), 'gc_fee' => new sfValidatorNumber(array('required' => false)), 'owner_fee' => new sfValidatorNumber(array('required' => false)), 'commission_fee' => new sfValidatorNumber(array('required' => false))));
 }
 public function setObject()
 {
     $arr = explode('_', $this->id);
     $this->object = GcrEschoolTable::getEschool($arr[0]);
     $this->mdl_course = $this->object->selectFromMdlTable('course', 'id', $arr[1], true);
     $course = new GcrMdlCourse($this->mdl_course, $this->object);
     if ($course->isRepresented()) {
         $this->mdl_course = $course->getCourseCollection()->getRepresentativeCourse()->getObject();
     }
 }
 protected function setRepresentedCourses(GcrMdlCourse $course)
 {
     $course_collection = $course->getCourseCollection();
     if ($course_collection) {
         $representative = $course_collection->getRepresentativeCourse();
         foreach ($course_collection->getCourses() as $course_instance) {
             if ($course_instance->getObject()->id != $representative->getObject()->id) {
                 $this->represented_courses[$course_instance->getApp()->getShortName() . '-' . $course_instance->getObject()->id] = 1;
             }
         }
     }
 }
 function get_content()
 {
     global $CFG, $COURSE, $USER, $DB;
     if ($this->content !== NULL) {
         return $this->content;
     }
     $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $course = new GcrMdlCourse($COURSE, $CFG->current_app);
     $can_edit = has_capability('block/course_profile:edit', $context);
     $block_course_profile = $course->getBlockCourseProfile();
     if (!$block_course_profile && $can_edit) {
         $parent_block_course_profile = $course->getRepresentativeBlockCourseProfile();
         if ($parent_block_course_profile) {
             $this->copyFromBlock($parent_block_course_profile, $course);
             $block_course_profile = $course->getBlockCourseProfile();
         }
     }
     if (!$block_course_profile) {
         if ($can_edit) {
             redirect($CFG->wwwroot . '/blocks/course_profile/edit.php?courseid=' . $COURSE->id);
         } else {
             return false;
         }
     }
     $img_src = $block_course_profile->getCourseIconUrl();
     $instructor_text = 'Instructor: None';
     $instructor = $block_course_profile->getInstructor();
     if ($instructor) {
         $user = $instructor->getUserOnInstitution();
         $institution = $CFG->current_app->getInstitution();
         if ($user && $user->getApp()->getShortName() == $institution->getShortName()) {
             $user_obj = $user->getObject();
             $user_profile_url = $institution->getAppUrl() . 'user/view.php?id=' . $user_obj->id;
         } else {
             $user = $instructor;
             $user_obj = $instructor->getObject();
             $user_profile_url = $CFG->current_app->getAppUrl() . '/user/view?id=' . $user_obj->id . '&course=' . $COURSE->id;
         }
         $instructor_text = 'Instructor: <a href="' . $user_profile_url . '">' . $user->getFullnameString() . '</a>';
     }
     $img = '<div class="gc_course_list_item_icon"><img src="' . $img_src . '" /></div>';
     $this->content->items[] = $img;
     $this->content->items[] = $instructor_text;
     if ($can_edit) {
         $this->content->items[] = '<a href="' . $CFG->wwwroot . '/blocks/course_profile/edit.php?courseid=' . $COURSE->id . '"><button style="cursor:pointer">Edit</button></a>';
     }
     return $this->content;
 }
 public function checkConstraints()
 {
     global $CFG, $COURSE;
     if ($CFG->current_app->isMoodle()) {
         if (isset($COURSE->id)) {
             $course = new GcrMdlCourse($COURSE, $CFG->current_app);
             $context = $course->getContext();
             if ($context) {
                 return $CFG->current_app->hasPrivilege('EschoolAdmin') || $CFG->current_app->hasCapability('moodle/site:viewreports', $context);
             }
         }
     }
     return false;
 }
 protected function getEnrolmentStatus(GcrMdlCourse $course)
 {
     global $CFG;
     $current_user = $CFG->current_app->getCurrentUser();
     if ($current_user->getRoleManager()->hasPrivilege('Student')) {
         $mdl_roles = $course->getRoleAssignments($current_user);
         return $mdl_roles && count($mdl_roles > 0);
     }
     return false;
 }
Пример #8
0
require_once "{$CFG->dirroot}/blocks/course_profile/edit_form.php";
$CFG->current_app->requireLogin();
$courseid = required_param('courseid', PARAM_INT);
global $COURSE, $PAGE;
//  Load the course
$course = $DB->get_record('course', array('id' => $courseid));
$COURSE = $course;
$context = get_context_instance(CONTEXT_COURSE, $courseid);
require_capability('block/course_profile:edit', $context);
$PAGE->set_context($context);
$PAGE->set_url('/blocks/course_profile/edit.php', array('courseid' => $courseid));
$title = get_string('editcourseprofile', 'block_course_profile');
$link[] = array('name' => $title, 'link' => '', 'type' => 'misc');
$link = build_navigation($link);
print_header_simple($title, $title, $link);
$mdl_course = new GcrMdlCourse($course, $CFG->current_app);
// Build list of potential instructors
$teacher_list = $mdl_course->getMdlInstructors();
$teacher_array = array();
foreach ($teacher_list as $mdl_user_obj) {
    $teacher = $mdl_user_obj->getObject();
    $teacher_array[$teacher->id] = $teacher->firstname . ' ' . $teacher->lastname . ' (' . $teacher->email . ')';
}
asort($teacher_array);
$mform = new block_course_profile_form(null, array('teacher_list' => $teacher_array, 'courseid' => $courseid));
if ($mform->is_cancelled()) {
    redirect(new moodle_url('/course/view.php?id=' . $courseid));
} else {
    if ($formdata = $mform->get_data()) {
        $fs = get_file_storage();
        $filename = $mform->get_new_filename('userfile');
 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;
 }