/** * Returns a button to enrol a cohort or its users through the manual enrolment plugin. * * This function also adds a quickenrolment JS ui to the page so that users can be enrolled * via AJAX. * * @param course_enrolment_manager $manager * @return enrol_user_button */ public function get_manual_enrol_button(course_enrolment_manager $manager) { $course = $manager->get_course(); if (!$this->can_add_new_instances($course->id)) { return false; } $cohorturl = new moodle_url('/enrol/cohort/edit.php', array('courseid' => $course->id)); $button = new enrol_user_button($cohorturl, get_string('enrolcohort', 'enrol'), 'get'); $button->class .= ' enrol_cohort_plugin'; $button->strings_for_js(array('enrol', 'synced', 'enrolcohort', 'enrolcohortusers'), 'enrol'); $button->strings_for_js(array('ajaxmore', 'cohortsearch'), 'enrol_cohort'); $button->strings_for_js('assignroles', 'role'); $button->strings_for_js('cohort', 'cohort'); $button->strings_for_js('users', 'moodle'); // No point showing this at all if the user cant manually enrol users. $hasmanualinstance = has_capability('enrol/manual:enrol', $manager->get_context()) && $manager->has_instance('manual'); $modules = array('moodle-enrol_cohort-quickenrolment', 'moodle-enrol_cohort-quickenrolment-skin'); $function = 'M.enrol_cohort.quickenrolment.init'; $arguments = array('courseid' => $course->id, 'ajaxurl' => '/enrol/cohort/ajax.php', 'url' => $manager->get_moodlepage()->url->out(false), 'manualEnrolment' => $hasmanualinstance); $button->require_yui_module($modules, $function, array($arguments)); return $button; }
/** * Returns a button to manually enrol users through the manual enrolment plugin. * * By default the first manual enrolment plugin instance available in the course is used. * If no manual enrolment instances exist within the course then false is returned. * * This function also adds a quickenrolment JS ui to the page so that users can be enrolled * via AJAX. * * @param course_enrolment_manager $manager * @return enrol_user_button */ public function get_manual_enrol_button(course_enrolment_manager $manager) { global $CFG; $instance = null; $instances = array(); foreach ($manager->get_enrolment_instances() as $tempinstance) { if ($tempinstance->enrol == 'manual') { if ($instance === null) { $instance = $tempinstance; } $instances[] = array('id' => $tempinstance->id, 'name' => $this->get_instance_name($tempinstance)); } } if (empty($instance)) { return false; } if (!($manuallink = $this->get_manual_enrol_link($instance))) { return false; } $button = new enrol_user_button($manuallink, get_string('enrolusers', 'enrol_manual'), 'get'); $button->class .= ' enrol_manual_plugin'; $startdate = $manager->get_course()->startdate; $startdateoptions = array(); $timeformat = get_string('strftimedatefullshort'); if ($startdate > 0) { $startdateoptions[2] = get_string('coursestart') . ' (' . userdate($startdate, $timeformat) . ')'; } $today = time(); $today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0); $startdateoptions[3] = get_string('today') . ' (' . userdate($today, $timeformat) . ')'; $defaultduration = $instance->enrolperiod > 0 ? $instance->enrolperiod / 86400 : ''; $modules = array('moodle-enrol_manual-quickenrolment', 'moodle-enrol_manual-quickenrolment-skin'); $arguments = array('instances' => $instances, 'courseid' => $instance->courseid, 'ajaxurl' => '/enrol/manual/ajax.php', 'url' => $manager->get_moodlepage()->url->out(false), 'optionsStartDate' => $startdateoptions, 'defaultRole' => $instance->roleid, 'defaultDuration' => $defaultduration, 'disableGradeHistory' => $CFG->disablegradehistory, 'recoverGradesDefault' => ''); if ($CFG->recovergradesdefault) { $arguments['recoverGradesDefault'] = ' checked="checked"'; } $function = 'M.enrol_manual.quickenrolment.init'; $button->require_yui_module($modules, $function, array($arguments)); $button->strings_for_js(array('ajaxoneuserfound', 'ajaxxusersfound', 'ajaxnext25', 'enrol', 'enrolmentoptions', 'enrolusers', 'errajaxfailedenrol', 'errajaxsearch', 'none', 'usersearch', 'unlimitedduration', 'startdatetoday', 'durationdays', 'enrolperiod', 'finishenrollingusers', 'recovergrades'), 'enrol'); $button->strings_for_js('assignroles', 'role'); $button->strings_for_js('startingfrom', 'moodle'); return $button; }
/** * Returns a button to manually enrol users through the manual enrolment plugin. * * By default the first manual enrolment plugin instance available in the course is used. * If no manual enrolment instances exist within the course then false is returned. * * This function also adds a quickenrolment JS ui to the page so that users can be enrolled * via AJAX. * * @param course_enrolment_manager $manager * @return enrol_user_button */ public function get_manual_enrol_button(course_enrolment_manager $manager) { global $CFG; require_once $CFG->dirroot . '/cohort/lib.php'; $instance = null; $instances = array(); foreach ($manager->get_enrolment_instances() as $tempinstance) { if ($tempinstance->enrol == 'manual') { if ($instance === null) { $instance = $tempinstance; } $instances[] = array('id' => $tempinstance->id, 'name' => $this->get_instance_name($tempinstance)); } } if (empty($instance)) { return false; } if (!($manuallink = $this->get_manual_enrol_link($instance))) { return false; } $button = new enrol_user_button($manuallink, get_string('enrolusers', 'enrol_manual'), 'get'); $button->class .= ' enrol_manual_plugin'; $startdate = $manager->get_course()->startdate; if (!($defaultstart = get_config('enrol_manual', 'enrolstart'))) { // Default to now if there is no system setting. $defaultstart = 4; } $startdateoptions = array(); $dateformat = get_string('strftimedatefullshort'); if ($startdate > 0) { $startdateoptions[2] = get_string('coursestart') . ' (' . userdate($startdate, $dateformat) . ')'; } $now = time(); $today = make_timestamp(date('Y', $now), date('m', $now), date('d', $now), 0, 0, 0); $startdateoptions[3] = get_string('today') . ' (' . userdate($today, $dateformat) . ')'; $startdateoptions[4] = get_string('now', 'enrol_manual') . ' (' . userdate($now, get_string('strftimedatetimeshort')) . ')'; $defaultduration = $instance->enrolperiod > 0 ? $instance->enrolperiod / 86400 : ''; $modules = array('moodle-enrol_manual-quickenrolment', 'moodle-enrol_manual-quickenrolment-skin'); $arguments = array('instances' => $instances, 'courseid' => $instance->courseid, 'ajaxurl' => '/enrol/manual/ajax.php', 'url' => $manager->get_moodlepage()->url->out(false), 'optionsStartDate' => $startdateoptions, 'defaultRole' => $instance->roleid, 'defaultDuration' => $defaultduration, 'defaultStartDate' => (int) $defaultstart, 'disableGradeHistory' => $CFG->disablegradehistory, 'recoverGradesDefault' => '', 'cohortsAvailable' => cohort_get_available_cohorts($manager->get_context(), COHORT_WITH_NOTENROLLED_MEMBERS_ONLY, 0, 1) ? true : false); if ($CFG->recovergradesdefault) { $arguments['recoverGradesDefault'] = ' checked="checked"'; } $function = 'M.enrol_manual.quickenrolment.init'; $button->require_yui_module($modules, $function, array($arguments)); $button->strings_for_js(array('ajaxoneuserfound', 'ajaxxusersfound', 'ajaxnext25', 'enrol', 'enrolmentoptions', 'enrolusers', 'enrolxusers', 'errajaxfailedenrol', 'errajaxsearch', 'foundxcohorts', 'none', 'usersearch', 'unlimitedduration', 'startdatetoday', 'durationdays', 'enrolperiod', 'finishenrollingusers', 'recovergrades'), 'enrol'); $button->strings_for_js(array('browseusers', 'browsecohorts'), 'enrol_manual'); $button->strings_for_js('assignroles', 'role'); $button->strings_for_js('startingfrom', 'moodle'); return $button; }