protected function process_block($data) { global $DB; $data = (object) $data; $restore = $this->get_setting_value('restore_quickmail_history'); $overwrite = $this->get_setting_value('overwrite_quickmail_history'); // Delete current history, if any if ($overwrite) { $params = array('courseid' => $this->get_courseid()); $DB->delete_records('block_quickmail_log', $params); } if ($restore and isset($data->emaillogs['log'])) { global $DB; $current = context_course::instance($this->get_courseid()); $params = array('backupid' => $this->get_restoreid(), 'itemname' => 'context', 'newitemid' => $current->id); $id = $DB->get_record('backup_ids_temp', $params)->itemid; foreach ($data->emaillogs['log'] as $log) { $this->process_log($log, $id, $current); } } if (isset($data->emaillogs['block_level_setting'])) { foreach ($data->emaillogs['block_level_setting'] as $block_level_setting) { $this->process_block_level_setting($block_level_setting, $this->get_courseid()); } } }
public function get_content() { global $COURSE, $USER; if ($this->content !== null) { return $this->content; } $this->content = new stdClass(); $this->content->text = var_export($this->context, true); $coursecontext = context_course::instance($COURSE->id); if (has_capability('block/demostudent:addinstance', $coursecontext)) { // If DemoStudent has not yet been enrolled, allow user to create/enrol one. $demostudentusername = generate_demostudent_name($USER->username); $demostudentuser = get_complete_user_data('username', $demostudentusername); if (!$demostudentuser || !is_enrolled($coursecontext, $demostudentuser)) { $this->render_view('firstuse'); } else { $this->render_view('instructor'); } } else { if (has_capability('block/demostudent:seedemostudentblock', $coursecontext)) { $this->render_view('demostudent'); } else { // If the user does not need to see the block, do not display it at all. $this->content->text = ''; $this->content->footer = ''; } } return $this->content; }
/** * Tests that the filter applies the required changes. * * @return void */ public function test_filter() { $this->resetAfterTest(true); $this->setAdminUser(); filter_manager::reset_caches(); filter_set_global_state('data', TEXTFILTER_ON); $course1 = $this->getDataGenerator()->create_course(); $coursecontext1 = context_course::instance($course1->id); $course2 = $this->getDataGenerator()->create_course(); $coursecontext2 = context_course::instance($course2->id); $sitecontext = context_course::instance(SITEID); $site = get_site(); $this->add_simple_database_instance($site, array('SiteEntry')); $this->add_simple_database_instance($course1, array('CourseEntry')); $html = '<p>I like CourseEntry and SiteEntry</p>'; // Testing at course level (both site and course). $filtered = format_text($html, FORMAT_HTML, array('context' => $coursecontext1)); $this->assertRegExp('/title=(\'|")CourseEntry(\'|")/', $filtered); $this->assertRegExp('/title=(\'|")SiteEntry(\'|")/', $filtered); // Testing at site level (only site). $filtered = format_text($html, FORMAT_HTML, array('context' => $sitecontext)); $this->assertNotRegExp('/title=(\'|")CourseEntry(\'|")/', $filtered); $this->assertRegExp('/title=(\'|")SiteEntry(\'|")/', $filtered); // Changing to another course to test the caches invalidation (only site). $filtered = format_text($html, FORMAT_HTML, array('context' => $coursecontext2)); $this->assertNotRegExp('/title=(\'|")CourseEntry(\'|")/', $filtered); $this->assertRegExp('/title=(\'|")SiteEntry(\'|")/', $filtered); }
private function init() { if (!$this->isInit) { $this->isInit = true; // Discover location of editor plugin. $editor_plugin = WIRISpluginWrapper::get_wiris_plugin(); $this->installed = !empty($editor_plugin); // Return if editor plugin is not installed. if (!$this->installed) { global $COURSE, $PAGE; $coursecontext = context_course::instance($COURSE->id); if (has_capability('moodle/site:config', $coursecontext)) { // Display missing WIRIS editor plugin dependency error $PAGE->requires->js('/filter/wiris/js/message.js', false); } return null; } // Init haxe environment. if (!class_exists('com_wiris_system_CallWrapper')) { require_once $editor_plugin->path . '/integration/lib/com/wiris/system/CallWrapper.class.php'; } com_wiris_system_CallWrapper::getInstance()->init($editor_plugin->path . '/integration'); // Start haxe environment. $this->begin(); // Create PluginBuilder with Moodle specific configuration. require_once 'MoodleConfigurationUpdater.php'; $this->moodleConfig = new com_wiris_plugin_configuration_MoodleConfigurationUpdater($editor_plugin); $this->instance = com_wiris_plugin_api_PluginBuilder::getInstance(); $this->instance->addConfigurationUpdater($this->moodleConfig); $this->instance->addConfigurationUpdater(new com_wiris_plugin_web_PhpConfigurationUpdater()); // Stop haxe environment. $this->end(); } }
/** * Returns the document associated with this course. * * @param stdClass $record * @param array $options * @return \core_search\document */ public function get_document($record, $options = array()) { try { $context = \context_course::instance($record->id); } catch (\moodle_exception $ex) { // Notify it as we run here as admin, we should see everything. debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' . $ex->getMessage(), DEBUG_DEVELOPER); return false; } // Prepare associative array with data from DB. $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname); $doc->set('title', content_to_text($record->fullname, false)); $doc->set('content', content_to_text($record->summary, $record->summaryformat)); $doc->set('contextid', $context->id); $doc->set('courseid', $record->id); $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID); $doc->set('modified', $record->timemodified); $doc->set('description1', $record->shortname); // Check if this document should be considered new. if (isset($options['lastindexedtime']) && $options['lastindexedtime'] < $record->timecreated) { // If the document was created after the last index time, it must be new. $doc->set_is_new(true); } return $doc; }
/** * Create the event from course record. * * @param \stdClass $course * @return course_module_instance_list_viewed */ public static function create_from_course(\stdClass $course) { $params = array('context' => \context_course::instance($course->id)); $event = \mod_book\event\course_module_instance_list_viewed::create($params); $event->add_record_snapshot('course', $course); return $event; }
function get_content() { global $CFG, $DB, $OUTPUT, $COURSE; if ($this->content !== null) { return $this->content; } $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; if (empty($this->instance)) { return $this->content; } if (!has_capability('block/course_files_license:viewlist', context_course::instance($COURSE->id))) { return $this->content; } $context = context_course::instance($COURSE->id); $contextcheck = $context->path . '/%'; // Get the top file files used on the course by size. $filelist = block_course_files_license_get_coursefilelist(); if ($filelist) { $this->content->text = '<p class="justify">' . get_string('files_to_idenfity', 'block_course_files_license') . '</p>'; $this->content->text .= '<a class="btn btn-block btn-danger btn-sm" href="'; $this->content->text .= new moodle_url('/blocks/course_files_license/view.php', array('courseid' => $COURSE->id)) . '">'; $this->content->text .= '<i class="fa fa-exclamation-triangle"></i> '; $this->content->text .= get_string('filelist', 'block_course_files_license') . '</a>'; } else { $this->content->text = '<p class="justify">' . get_string('all_files_idenfitied', 'block_course_files_license') . '</p>'; $this->content->text = '<a class="btn btn-block btn-success btn-sm" href="'; $this->content->text .= new moodle_url('/blocks/course_files_license/view.php', array('courseid' => $COURSE->id)) . '">'; $this->content->text .= '<i class="fa fa-info-circle"></i> '; $this->content->text .= get_string('filelist', 'block_course_files_license') . '</a>'; } return $this->content; }
/** * Return self-enrolment instance information. * * @param int $instanceid instance id of self enrolment plugin. * @return array instance information. * @throws moodle_exception */ public static function get_instance_info($instanceid) { global $DB, $CFG; require_once $CFG->libdir . '/enrollib.php'; $params = self::validate_parameters(self::get_instance_info_parameters(), array('instanceid' => $instanceid)); // Retrieve self enrolment plugin. $enrolplugin = enrol_get_plugin('self'); if (empty($enrolplugin)) { throw new moodle_exception('invaliddata', 'error'); } // Note that we can't use validate_context because the user is not enrolled in the course. require_login(null, false, null, false, true); $enrolinstance = $DB->get_record('enrol', array('id' => $params['instanceid']), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $enrolinstance->courseid), '*', MUST_EXIST); $context = context_course::instance($course->id); if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) { throw new moodle_exception('coursehidden'); } $instanceinfo = (array) $enrolplugin->get_enrol_info($enrolinstance); if (isset($instanceinfo['requiredparam']->enrolpassword)) { $instanceinfo['enrolpassword'] = $instanceinfo['requiredparam']->enrolpassword; } unset($instanceinfo->requiredparam); return $instanceinfo; }
/** * Definition of the form */ function definition() { global $USER, $CFG, $COURSE; $coursecontext = context_course::instance($COURSE->id); $mform =& $this->_form; $editoroptions = $this->_customdata['editoroptions']; $mform->addElement('header', 'general', get_string('general', 'form')); $mform->addElement('text', 'name', get_string('groupname', 'group'), 'maxlength="254" size="50"'); $mform->addRule('name', get_string('required'), 'required', null, 'client'); $mform->setType('name', PARAM_TEXT); $mform->addElement('text', 'idnumber', get_string('idnumbergroup'), 'maxlength="100" size="10"'); $mform->addHelpButton('idnumber', 'idnumbergroup'); $mform->setType('idnumber', PARAM_RAW); $mform->setAdvanced('idnumber'); if (!has_capability('moodle/course:changeidnumber', $coursecontext)) { $mform->hardFreeze('idnumber'); } $mform->addElement('editor', 'description_editor', get_string('groupdescription', 'group'), null, $editoroptions); $mform->setType('description_editor', PARAM_RAW); $mform->addElement('passwordunmask', 'enrolmentkey', get_string('enrolmentkey', 'group'), 'maxlength="254" size="24"', get_string('enrolmentkey', 'group')); $mform->addHelpButton('enrolmentkey', 'enrolmentkey', 'group'); $mform->setType('enrolmentkey', PARAM_RAW); if (!empty($CFG->gdversion)) { $options = array(get_string('no'), get_string('yes')); $mform->addElement('select', 'hidepicture', get_string('hidepicture'), $options); $mform->addElement('filepicker', 'imagefile', get_string('newpicture', 'group')); $mform->addHelpButton('imagefile', 'newpicture', 'group'); } $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'courseid'); $mform->setType('courseid', PARAM_INT); $this->add_action_buttons(); }
protected function specific_definition($mform) { global $CFG, $PAGE, $COURSE; $mform->addElement('header', 'configheader', get_string('blocksettings', 'block')); $mform->addElement('text', 'config_title', get_string('configspottitle', 'block_informationspot')); $mform->setType('config_title', PARAM_TEXT); $fileoptions = array('subdirs' => false, 'maxfiles' => 1, 'maxbytes' => $COURSE->maxbytes, 'accepted_types' => 'web_image', 'return_types' => FILE_INTERNAL); $mform->addElement('filemanager', 'config_imagespot', get_string('configspotfile', 'block_informationspot'), $fileoptions); $mform->addElement('editor', 'config_text', get_string('configspottext', 'block_informationspot')); $mform->setType('config_text', PARAM_RAW); $mform->addElement('text', 'config_buttontext', get_string('configspotbutton', 'block_informationspot')); $mform->setType('config_buttontext', PARAM_TEXT); $mform->addElement('text', 'config_buttonlink', get_string('configspotlink', 'block_informationspot')); $mform->setType('config_buttonlink', PARAM_URL); $choices = array(); $choices['always'] = get_string('always', 'block_informationspot'); if ($PAGE->context === context_course::instance(SITEID)) { $choices['beforelogin'] = get_string('beforelogin', 'block_informationspot'); $choices['afterlogin'] = get_string('afterlogin', 'block_informationspot'); //$choices['onetimebefore'] = get_string('onetimebefore', 'block_informationspot'); //$choices['onetimeafter'] = get_string('onetimeafter', 'block_informationspot'); } else { // $choices['onetime'] = get_string('onetime', 'block_informationspot'); } if (count($choices) > 1) { $mform->addElement('select', 'config_showspot', get_string('configshowspot', 'block_informationspot'), $choices, 'always'); } else { $mform->addElement('hidden', 'config_showspot', 'always'); $mform->setType('configshowsspot', PARAM_TEXT); } }
public function print_badges_list($badges, $userid, $profile = false, $external = false) { global $USER, $CFG; foreach ($badges as $badge) { if (!$external) { $context = ($badge->type == BADGE_TYPE_SITE) ? context_system::instance() : context_course::instance($badge->courseid); $bname = $badge->name; $imageurl = moodle_url::make_pluginfile_url($context->id, 'badges', 'badgeimage', $badge->id, '/', 'f1', false); } else { $bname = $badge->assertion->badge->name; $imageurl = $badge->imageUrl; } $name = html_writer::tag('span', $bname, array('class' => 'badge-name')); $image = html_writer::empty_tag('img', array('src' => $imageurl, 'class' => 'badge-image')); if (!empty($badge->dateexpire) && $badge->dateexpire < time()) { $image .= $this->output->pix_icon('i/expired', get_string('expireddate', 'badges', userdate($badge->dateexpire)), 'moodle', array('class' => 'expireimage')); $name .= '(' . get_string('expired', 'badges') . ')'; } $download = $status = $push = ''; if (($userid == $USER->id) && !$profile) { $url = new moodle_url('mybadges.php', array('download' => $badge->id, 'hash' => $badge->uniquehash, 'sesskey' => sesskey())); $notexpiredbadge = (empty($badge->dateexpire) || $badge->dateexpire > time()); $backpackexists = badges_user_has_backpack($USER->id); if (!empty($CFG->badges_allowexternalbackpack) && $notexpiredbadge && $backpackexists) { $assertion = new moodle_url('/badges/assertion.php', array('b' => $badge->uniquehash)); $action = new component_action('click', 'addtobackpack', array('assertion' => $assertion->out(false))); $push = $this->output->action_icon(new moodle_url('#'), new pix_icon('t/backpack', get_string('addtobackpack', 'badges')), $action); } $download = $this->output->action_icon($url, new pix_icon('t/download', get_string('download'))); if ($badge->visible) { $url = new moodle_url('mybadges.php', array('hide' => $badge->issuedid, 'sesskey' => sesskey())); $status = $this->output->action_icon($url, new pix_icon('t/hide', get_string('makeprivate', 'badges'))); } else { $url = new moodle_url('mybadges.php', array('show' => $badge->issuedid, 'sesskey' => sesskey())); $status = $this->output->action_icon($url, new pix_icon('t/show', get_string('makepublic', 'badges'))); } } if (!$profile) { $url = new moodle_url('badge.php', array('hash' => $badge->uniquehash)); } else { if (!$external) { $url = new moodle_url('/badges/badge.php', array('hash' => $badge->uniquehash)); } else { $hash = hash('md5', $badge->hostedUrl); $url = new moodle_url('/badges/external.php', array('hash' => $hash, 'user' => $userid)); } } $actions = html_writer::tag('div', $push . $download . $status, array('class' => 'badge-actions')); $items[] = html_writer::link($url, $image . $actions . $name, array('title' => $bname)); } return html_writer::alist($items, array('class' => 'badges')); }
public static function create_from_course(\stdClass $course) { $params = array('context' => \context_course::instance($course->id)); $event = self::create($params); $event->add_record_snapshot('course', $course); return $event; }
function definition() { global $CFG, $DB; $mform = $this->_form; list($instance, $plugin, $course) = $this->_customdata; $coursecontext = context_course::instance($course->id); $enrol = enrol_get_plugin('cohort'); $groups = array(0 => get_string('none')); foreach (groups_get_all_groups($course->id) as $group) { $groups[$group->id] = format_string($group->name, true, array('context' => $coursecontext)); } $mform->addElement('header', 'general', get_string('pluginname', 'enrol_cohort')); $mform->addElement('text', 'name', get_string('custominstancename', 'enrol')); $mform->setType('name', PARAM_TEXT); $options = array(ENROL_INSTANCE_ENABLED => get_string('yes'), ENROL_INSTANCE_DISABLED => get_string('no')); $mform->addElement('select', 'status', get_string('status', 'enrol_cohort'), $options); if ($instance->id) { if ($cohort = $DB->get_record('cohort', array('id' => $instance->customint1))) { $cohorts = array($instance->customint1 => format_string($cohort->name, true, array('context' => context::instance_by_id($cohort->contextid)))); } else { $cohorts = array($instance->customint1 => get_string('error')); } $mform->addElement('select', 'customint1', get_string('cohort', 'cohort'), $cohorts); $mform->setConstant('customint1', $instance->customint1); $mform->hardFreeze('customint1', $instance->customint1); } else { $cohorts = array('' => get_string('choosedots')); $allcohorts = cohort_get_available_cohorts($coursecontext, 0, 0, 0); foreach ($allcohorts as $c) { $cohorts[$c->id] = format_string($c->name); } $mform->addElement('select', 'customint1', get_string('cohort', 'cohort'), $cohorts); $mform->addRule('customint1', get_string('required'), 'required', null, 'client'); } $roles = get_assignable_roles($coursecontext); $roles[0] = get_string('none'); $roles = array_reverse($roles, true); // Descending default sortorder. $mform->addElement('select', 'roleid', get_string('assignrole', 'enrol_cohort'), $roles); $mform->setDefault('roleid', $enrol->get_config('roleid')); if ($instance->id and !isset($roles[$instance->roleid])) { if ($role = $DB->get_record('role', array('id' => $instance->roleid))) { $roles = role_fix_names($roles, $coursecontext, ROLENAME_ALIAS, true); $roles[$instance->roleid] = role_get_name($role, $coursecontext); } else { $roles[$instance->roleid] = get_string('error'); } } $mform->addElement('select', 'customint2', get_string('addgroup', 'enrol_cohort'), $groups); $mform->addElement('hidden', 'courseid', null); $mform->setType('courseid', PARAM_INT); $mform->addElement('hidden', 'id', null); $mform->setType('id', PARAM_INT); if ($instance->id) { $this->add_action_buttons(true); } else { $this->add_action_buttons(true, get_string('addinstance', 'enrol')); } $this->set_data($instance); }
/** * Define structure. */ protected function define_structure() { global $DB; $userinfo = $this->get_setting_value('users'); // Define each element separated. $xpconfig = new backup_nested_element('config', array('courseid'), array('enabled', 'enablelog', 'keeplogs', 'levels', 'lastlogpurge', 'enableladder', 'enableinfos', 'levelsdata', 'enablelevelupnotif', 'enablecustomlevelbadges', 'maxactionspertime', 'timeformaxactions', 'timebetweensameactions', 'identitymode', 'rankmode', 'neighbours')); $xpfilters = new backup_nested_element('filters'); $xpfilter = new backup_nested_element('filter', array('courseid'), array('ruledata', 'points', 'sortorder')); $xplevels = new backup_nested_element('xps'); $xplevel = new backup_nested_element('xp', array('courseid'), array('userid', 'xp', 'lvl')); $xplogs = new backup_nested_element('logs'); $xplog = new backup_nested_element('log', array('courseid'), array('userid', 'eventname', 'xp', 'time')); // Prepare the structure. $xp = $this->prepare_block_structure($xpconfig); $xpfilters->add_child($xpfilter); $xp->add_child($xpfilters); if ($userinfo) { $xplevels->add_child($xplevel); $xp->add_child($xplevels); $xplogs->add_child($xplog); $xp->add_child($xplogs); } // Define sources. $xpconfig->set_source_table('block_xp_config', array('courseid' => backup::VAR_COURSEID)); $xpfilter->set_source_table('block_xp_filters', array('courseid' => backup::VAR_COURSEID)); $xplevel->set_source_table('block_xp', array('courseid' => backup::VAR_COURSEID)); $xplog->set_source_table('block_xp_log', array('courseid' => backup::VAR_COURSEID)); // Annotations. $xplevel->annotate_ids('user', 'userid'); $xplog->annotate_ids('user', 'userid'); $xp->annotate_files('block_xp', 'badges', null, context_course::instance($this->get_courseid())->id); // Return the root element. return $xp; }
function definition() { global $CFG, $DB; $mform = $this->_form; $course = $this->_customdata; $coursecontext = context_course::instance($course->id); $enrol = enrol_get_plugin('cohort'); $cohorts = array('' => get_string('choosedots')); list($sqlparents, $params) = $DB->get_in_or_equal(get_parent_contexts($coursecontext)); $sql = "SELECT id, name, contextid\n FROM {cohort}\n WHERE contextid {$sqlparents}\n ORDER BY name ASC"; $rs = $DB->get_recordset_sql($sql, $params); foreach ($rs as $c) { $context = get_context_instance_by_id($c->contextid); if (!has_capability('moodle/cohort:view', $context)) { continue; } $cohorts[$c->id] = format_string($c->name); } $rs->close(); $roles = get_assignable_roles($coursecontext); $roles[0] = get_string('none'); $roles = array_reverse($roles, true); // descending default sortorder $mform->addElement('header', 'general', get_string('pluginname', 'enrol_cohort')); $mform->addElement('select', 'cohortid', get_string('cohort', 'cohort'), $cohorts); $mform->addRule('cohortid', get_string('required'), 'required', null, 'client'); $mform->addElement('select', 'roleid', get_string('role'), $roles); $mform->addRule('roleid', get_string('required'), 'required', null, 'client'); $mform->setDefault('roleid', $enrol->get_config('roleid')); $mform->addElement('hidden', 'id', null); $mform->setType('id', PARAM_INT); $this->add_action_buttons(true, get_string('addinstance', 'enrol')); $this->set_data(array('id' => $course->id)); }
/** * Create all the steps that will be part of this task */ public function build() { // Define the task contextid (the course one) $this->contextid = context_course::instance($this->get_courseid())->id; // Executed conditionally if restoring to new course or if overwrite_conf setting is enabled if ($this->get_target() == backup::TARGET_NEW_COURSE || $this->get_setting_value('overwrite_conf') == true) { $this->add_step(new restore_course_structure_step('course_info', 'course.xml')); } // Restore course role assignments and overrides (internally will observe the role_assignments setting) $this->add_step(new restore_ras_and_caps_structure_step('course_ras_and_caps', 'roles.xml')); // Restore course enrolments (plugins and membership). Conditionally prevented for any IMPORT/HUB operation if ($this->plan->get_mode() != backup::MODE_IMPORT && $this->plan->get_mode() != backup::MODE_HUB) { $this->add_step(new restore_enrolments_structure_step('course_enrolments', 'enrolments.xml')); } // Restore course filters (conditionally) if ($this->get_setting_value('filters')) { $this->add_step(new restore_filters_structure_step('course_filters', 'filters.xml')); } // Restore course comments (conditionally) if ($this->get_setting_value('comments')) { $this->add_step(new restore_comments_structure_step('course_comments', 'comments.xml')); } // Calendar events (conditionally) if ($this->get_setting_value('calendarevents')) { $this->add_step(new restore_calendarevents_structure_step('course_calendar', 'calendar.xml')); } // At the end, mark it as built $this->built = true; }
protected function process_enrollments(&$courselist) { global $DB; // Locate and annotate any courses that have existing. // Enrollments. $strhasenrollments = get_string('hasenrollments', 'block_iomad_company_admin'); $strsharedhasenrollments = get_string('sharedhasenrollments', 'block_iomad_company_admin'); foreach ($courselist as $id => $course) { if ($DB->get_record_sql("SELECT id\n FROM {iomad_courses}\n WHERE courseid={$id}\n AND shared = 0")) { // Deal with own courses. $context = context_course::instance($id); if (count_enrolled_users($context) > 0) { $courselist[$id]->hasenrollments = true; $courselist[$id]->fullname = "<span class=\"hasenrollments\">\n {$course->fullname} ({$strhasenrollments})</span>"; $this->hasenrollments = true; } } if ($DB->get_record_sql("SELECT id\n FROM {iomad_courses}\n WHERE courseid={$id}\n AND shared = 2")) { // Deal with closed shared courses. if ($companygroup = company::get_company_group($this->companyid, $id)) { if ($DB->get_records('groups_members', array('groupid' => $companygroup->id))) { $courselist[$id]->hasenrollments = true; $courselist[$id]->fullname = "<span class=\"hasenrollments\">\n {$course->fullname} ({$strsharedhasenrollments})</span>"; $this->hasenrollments = true; } } } } }
/** * Create basic setup for test cases * @return bool */ public function setup() { global $CFG; $this->resetAfterTest(true); // Read settings from config.json. $configdata = file_get_contents($CFG->dirroot . '/local/onenote/tests/phpu_config_data.json'); if (!$configdata) { echo 'Please provide PHPUnit testing configs in a config.json file'; return false; } $this->config = json_decode($configdata, false); $this->user = $this->getDataGenerator()->create_user(); $this->user1 = $this->getDataGenerator()->create_user(); $this->course1 = $this->getDataGenerator()->create_course(); $this->course2 = $this->getDataGenerator()->create_course(); // Setting user and enrolling to the courses created with teacher role. $this->setUser($this->user->id); $c1ctx = context_course::instance($this->course1->id); $c2ctx = context_course::instance($this->course2->id); $this->getDataGenerator()->enrol_user($this->user->id, $this->course1->id, 3); $this->getDataGenerator()->enrol_user($this->user->id, $this->course2->id, 3); $this->assertCount(2, enrol_get_my_courses()); $courses = enrol_get_my_courses(); // Student enrollment. $this->setUser($this->user1->id); $this->getDataGenerator()->enrol_user($this->user1->id, $this->course1->id, 5); $this->getDataGenerator()->enrol_user($this->user1->id, $this->course2->id, 5); $this->assertCount(2, get_enrolled_users($c1ctx)); }
/** * Returns the block manager for a given course. */ private function get_block_manager($course) { $page = new \moodle_page(); $page->set_context(\context_course::instance($course->id)); $page->set_pagetype('course-view-*'); return new \block_manager($page); }
/** * Return guest enrolment instance information. * * @param int $instanceid instance id of guest enrolment plugin. * @return array warnings and instance information. * @since Moodle 3.1 */ public static function get_instance_info($instanceid) { global $DB; $params = self::validate_parameters(self::get_instance_info_parameters(), array('instanceid' => $instanceid)); $warnings = array(); // Retrieve guest enrolment plugin. $enrolplugin = enrol_get_plugin('guest'); if (empty($enrolplugin)) { throw new moodle_exception('invaliddata', 'error'); } require_login(null, false, null, false, true); $enrolinstance = $DB->get_record('enrol', array('id' => $params['instanceid']), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $enrolinstance->courseid), '*', MUST_EXIST); $context = context_course::instance($course->id); if (!$course->visible and !has_capability('moodle/course:viewhiddencourses', $context)) { throw new moodle_exception('coursehidden'); } $instanceinfo = $enrolplugin->get_enrol_info($enrolinstance); // Specific instance information. $instanceinfo->passwordrequired = $instanceinfo->requiredparam->passwordrequired; unset($instanceinfo->requiredparam); $result = array(); $result['instanceinfo'] = $instanceinfo; $result['warnings'] = $warnings; return $result; }
/** * Generate the edit controls of a section * * @param stdClass $course The course entry from DB * @param stdClass $section The course_section entry from DB * @param bool $onsectionpage true if being printed on a section page * @return array of links with edit controls */ protected function section_edit_controls($course, $section, $onsectionpage = false) { global $PAGE; if (!$PAGE->user_is_editing()) { return array(); } $coursecontext = context_course::instance($course->id); if ($onsectionpage) { $url = course_get_url($course, $section->section); } else { $url = course_get_url($course); } $url->param('sesskey', sesskey()); $isstealth = $section->section > $course->numsections; $controls = array(); if (!$isstealth && has_capability('moodle/course:setcurrentsection', $coursecontext)) { if ($course->marker == $section->section) { // Show the "light globe" on/off. $url->param('marker', 0); $controls[] = html_writer::link($url, html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/marked'), 'class' => 'icon ', 'alt' => get_string('markedthistopic'))), array('title' => get_string('markedthistopic'), 'class' => 'editing_highlight')); } else { $url->param('marker', $section->section); $controls[] = html_writer::link($url, html_writer::empty_tag('img', array('src' => $this->output->pix_url('i/marker'), 'class' => 'icon', 'alt' => get_string('markthistopic'))), array('title' => get_string('markthistopic'), 'class' => 'editing_highlight')); } } return array_merge($controls, parent::section_edit_controls($course, $section, $onsectionpage)); }
/** * Form definition */ function definition() { global $USER, $CFG, $COURSE; $coursecontext = context_course::instance($COURSE->id); $mform =& $this->_form; $editoroptions = $this->_customdata['editoroptions']; $mform->addElement('header', 'general', get_string('general', 'form')); $mform->addElement('text', 'name', get_string('groupingname', 'group'), 'maxlength="254" size="50"'); $mform->addRule('name', get_string('required'), 'required', null, 'server'); $mform->setType('name', PARAM_MULTILANG); $mform->addElement('text', 'idnumber', get_string('idnumbergrouping'), 'maxlength="100" size="10"'); $mform->addHelpButton('idnumber', 'idnumbergrouping'); $mform->setType('idnumber', PARAM_RAW); $mform->setAdvanced('idnumber'); if (!has_capability('moodle/course:changeidnumber', $coursecontext)) { $mform->hardFreeze('idnumber'); } $mform->addElement('editor', 'description_editor', get_string('groupingdescription', 'group'), null, $editoroptions); $mform->setType('description_editor', PARAM_RAW); $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'courseid'); $mform->setType('courseid', PARAM_INT); $this->add_action_buttons(); }
/** * Generate the edit control items of a section * * @param stdClass $course The course entry from DB * @param stdClass $section The course_section entry from DB * @param bool $onsectionpage true if being printed on a section page * @return array of edit control items */ protected function section_edit_control_items($course, $section, $onsectionpage = false) { global $PAGE; if (!$PAGE->user_is_editing()) { return array(); } $coursecontext = context_course::instance($course->id); if ($onsectionpage) { $url = course_get_url($course, $section->section); } else { $url = course_get_url($course); } $url->param('sesskey', sesskey()); $isstealth = $section->section > $course->numsections; $controls = array(); if (!$isstealth && $section->section && has_capability('moodle/course:setcurrentsection', $coursecontext)) { if ($course->marker == $section->section) { // Show the "light globe" on/off. $url->param('marker', 0); $markedthistopic = get_string('markedthistopic'); $highlightoff = get_string('highlightoff'); $controls[] = array("url" => $url, "icon" => 'i/marked', "name" => $highlightoff, 'pixattr' => array('class' => '', 'alt' => $markedthistopic), "attr" => array('class' => 'editing_highlight', 'title' => $markedthistopic)); } else { $url->param('marker', $section->section); $markthistopic = get_string('markthistopic'); $highlight = get_string('highlight'); $controls[] = array("url" => $url, "icon" => 'i/marker', "name" => $highlight, 'pixattr' => array('class' => '', 'alt' => $markthistopic), "attr" => array('class' => 'editing_highlight', 'title' => $markthistopic)); } } return array_merge($controls, parent::section_edit_control_items($course, $section, $onsectionpage)); }
/** * Returns shortname of activities in course * * @param int $courseid id of course for which activity shortname is needed * @return string|bool list of child shortname */ function block_course_overview_get_child_shortnames($courseid) { global $DB; $ctxselect = context_helper::get_preload_record_columns_sql('ctx'); $sql = "SELECT c.id, c.shortname, {$ctxselect}\n FROM {enrol} e\n JOIN {course} c ON (c.id = e.customint1)\n JOIN {context} ctx ON (ctx.instanceid = e.customint1)\n WHERE e.courseid = :courseid AND e.enrol = :method AND ctx.contextlevel = :contextlevel ORDER BY e.sortorder"; $params = array('method' => 'meta', 'courseid' => $courseid, 'contextlevel' => CONTEXT_COURSE); if ($results = $DB->get_records_sql($sql, $params)) { $shortnames = array(); // Preload the context we will need it to format the category name shortly. foreach ($results as $res) { context_helper::preload_from_record($res); $context = context_course::instance($res->id); $shortnames[] = format_string($res->shortname, true, $context); } $total = count($shortnames); $suffix = ''; if ($total > 10) { $shortnames = array_slice($shortnames, 0, 10); $diff = $total - count($shortnames); if ($diff > 1) { $suffix = get_string('shortnamesufixprural', 'block_course_overview', $diff); } else { $suffix = get_string('shortnamesufixsingular', 'block_course_overview', $diff); } } $shortnames = get_string('shortnameprefix', 'block_course_overview', implode('; ', $shortnames)); $shortnames .= $suffix; } return isset($shortnames) ? $shortnames : false; }
/** * Execute the request for this resource. * * @param mod_lti\local\ltiservice\response $response Response object for this request. */ public function execute($response) { global $CFG, $DB; $params = $this->parse_template(); $role = optional_param('role', '', PARAM_TEXT); $limitnum = optional_param('limit', 0, PARAM_INT); $limitfrom = optional_param('from', 0, PARAM_INT); if ($limitnum <= 0) { $limitfrom = 0; } try { if (!$this->get_service()->check_tool_proxy($params['product_code'])) { throw new \Exception(null, 401); } if (!($course = $DB->get_record('course', array('id' => $params['context_id']), 'id', IGNORE_MISSING))) { throw new \Exception(null, 404); } if (!($context = \context_course::instance($course->id))) { throw new \Exception(null, 404); } if (!($tool = $DB->get_record('lti_types', array('id' => $params['tool_code']), 'toolproxyid,enabledcapability,parameter', IGNORE_MISSING))) { throw new \Exception(null, 404); } $toolproxy = $DB->get_record('lti_tool_proxies', array('id' => $tool->toolproxyid), 'guid', IGNORE_MISSING); if (!$toolproxy || $toolproxy->guid !== $this->get_service()->get_tool_proxy()->guid) { throw new \Exception(null, 400); } $json = memberships::get_users_json($this, $context, $course->id, $tool, $role, $limitfrom, $limitnum, null, null); $response->set_content_type($this->formats[0]); $response->set_body($json); } catch (\Exception $e) { $response->set_code($e->getCode()); } }
/** * block contents * * @return object */ public function get_content() { global $CFG, $COURSE, $USER, $PAGE; if ($this->content !== NULL) { return $this->content; } if ($COURSE->id == SITEID) { $context = context_system::instance(); } else { $context = context_course::instance($COURSE->id); } $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; $mymoodle = 0; if (strcmp('my-index', $PAGE->pagetype) == 0) { $mymoodle = 1; } if (has_capability('block/enrolsurvey:edit', $context)) { $editpage = get_string('editpage', 'block_enrolsurvey'); $this->content->text .= "<a\nhref=\"{$CFG->wwwroot}/blocks/enrolsurvey/edit_survey.php?id={$this->instance->id}&courseid={$COURSE->id}&mymoodle={$mymoodle}\">{$editpage}</a><br\n/>"; } if (has_capability('block/enrolsurvey:take', $context) && cm_get_crlmuserid($USER->id) !== false) { // MUST have ELIS user record to take survey! if (!empty($this->config->force_user) && !is_survey_taken($USER->id, $this->instance->id)) { redirect("{$CFG->wwwroot}/blocks/enrolsurvey/survey.php?id={$this->instance->id}"); } $takepage = get_string('takepage', 'block_enrolsurvey'); $this->content->text .= "<a\nhref=\"{$CFG->wwwroot}/blocks/enrolsurvey/survey.php?id={$this->instance->id}&courseid={$COURSE->id}&mymoodle={$mymoodle}\">{$takepage}</a><br\n/>"; } // $this->content->text .= "<br/> crontime = {$this->config->cron_time}"; return $this->content; }
function moodleform_mod($current, $section, $cm, $course) { global $CFG; $this->current = $current; $this->_instance = $current->instance; $this->_section = $section; $this->_cm = $cm; if ($this->_cm) { $this->context = context_module::instance($this->_cm->id); } else { $this->context = context_course::instance($course->id); } // Set the course format. require_once $CFG->dirroot . '/course/format/lib.php'; $this->courseformat = course_get_format($course); // Guess module name $matches = array(); if (!preg_match('/^mod_([^_]+)_mod_form$/', get_class($this), $matches)) { debugging('Use $modname parameter or rename form to mod_xx_mod_form, where xx is name of your module'); print_error('unknownmodulename'); } $this->_modname = $matches[1]; $this->init_features(); parent::moodleform('modedit.php'); }
/** * Returns list of courses that we offer to the caller for remote enrolment of their users * * Since Moodle 2.0, courses are made available for MNet peers by creating an instance * of enrol_mnet plugin for the course. Hidden courses are not returned. If there are two * instances - one specific for the host and one for 'All hosts', the setting of the specific * one is used. The id of the peer is kept in customint1, no other custom fields are used. * * @uses mnet_remote_client Callable via XML-RPC only * @return array */ public function available_courses() { global $CFG, $DB; require_once $CFG->libdir . '/filelib.php'; if (!($client = get_mnet_remote_client())) { die('Callable via XML-RPC only'); } // we call our id as 'remoteid' because it will be sent to the peer // the column aliases are required by MNet protocol API for clients 1.x and 2.0 $sql = "SELECT c.id AS remoteid, c.fullname, c.shortname, c.idnumber, c.summary, c.summaryformat,\n c.sortorder, c.startdate, cat.id AS cat_id, cat.name AS cat_name,\n cat.description AS cat_description, cat.descriptionformat AS cat_descriptionformat,\n e.cost, e.currency, e.roleid AS defaultroleid, r.name AS defaultrolename,\n e.customint1\n FROM {enrol} e\n INNER JOIN {course} c ON c.id = e.courseid\n INNER JOIN {course_categories} cat ON cat.id = c.category\n INNER JOIN {role} r ON r.id = e.roleid\n WHERE e.enrol = 'mnet'\n AND (e.customint1 = 0 OR e.customint1 = ?)\n AND c.visible = 1\n ORDER BY cat.sortorder, c.sortorder, c.shortname"; $rs = $DB->get_recordset_sql($sql, array($client->id)); $courses = array(); foreach ($rs as $course) { // use the record if it does not exist yet or is host-specific if (empty($courses[$course->remoteid]) or $course->customint1 > 0) { unset($course->customint1); // the client does not need to know this $context = context_course::instance($course->remoteid); // Rewrite file URLs so that they are correct $course->summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course', 'summary', false); $courses[$course->remoteid] = $course; } } $rs->close(); return array_values($courses); // can not use keys for backward compatibility }
function get_content() { global $CFG, $OUTPUT; require_once $CFG->libdir . '/filelib.php'; if ($this->content !== NULL) { return $this->content; } if (empty($this->instance)) { return ''; } $this->content = new stdClass(); $options = new stdClass(); $options->noclean = true; // Don't clean Javascripts etc $options->overflowdiv = true; $context = context_course::instance($this->page->course->id); $this->page->course->summary = file_rewrite_pluginfile_urls($this->page->course->summary, 'pluginfile.php', $context->id, 'course', 'summary', NULL); $this->content->text = format_text($this->page->course->summary, $this->page->course->summaryformat, $options); if ($this->page->user_is_editing()) { if ($this->page->course->id == SITEID) { $editpage = $CFG->wwwroot . '/' . $CFG->admin . '/settings.php?section=frontpagesettings'; } else { $editpage = $CFG->wwwroot . '/course/edit.php?id=' . $this->page->course->id; } $this->content->text .= "<div class=\"editbutton\"><a href=\"{$editpage}\"><img src=\"" . $OUTPUT->pix_url('t/edit') . "\" alt=\"" . get_string('edit') . "\" /></a></div>"; } $this->content->footer = ''; return $this->content; }
/** * Renders course info box. * * @param stdClass $course * @return string */ public function course_info_box(stdClass $course) { global $CFG; $context = context_course::instance($course->id); $content = ''; $content .= $this->output->box_start('generalbox info'); $summary = file_rewrite_pluginfile_urls($course->summary, 'pluginfile.php', $context->id, 'course', 'summary', null); $content .= format_text($summary, $course->summaryformat, array('overflowdiv' => true), $course->id); if (!empty($CFG->coursecontact)) { $coursecontactroles = explode(',', $CFG->coursecontact); foreach ($coursecontactroles as $roleid) { if ($users = get_role_users($roleid, $context, true)) { foreach ($users as $teacher) { $role = new stdClass(); $role->id = $teacher->roleid; $role->name = $teacher->rolename; $role->shortname = $teacher->roleshortname; $role->coursealias = $teacher->rolecoursealias; $fullname = fullname($teacher, has_capability('moodle/site:viewfullnames', $context)); $namesarray[] = role_get_name($role, $context) . ': <a href="' . $CFG->wwwroot . '/user/view.php?id=' . $teacher->id . '&course=' . SITEID . '">' . $fullname . '</a>'; } } } if (!empty($namesarray)) { $content .= "<ul class=\"teachers\">\n<li>"; $content .= implode('</li><li>', $namesarray); $content .= "</li></ul>"; } } $content .= $this->output->box_end(); return $content; }