Merge branch 'master' of https://github.com/moodle/moodle
Conflicts: files/externallib.php
This commit is contained in:
+44
-7
@@ -23,12 +23,15 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
define('NO_OUTPUT_BUFFERING', true);
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
$action = required_param('action', PARAM_ALPHANUMEXT);
|
||||
$enrol = required_param('enrol', PARAM_PLUGIN);
|
||||
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
$migrate = optional_param('migrate', 0, PARAM_BOOL);
|
||||
|
||||
$PAGE->set_url('/admin/enrol.php');
|
||||
$PAGE->set_context(context_system::instance());
|
||||
@@ -94,24 +97,58 @@ switch ($action) {
|
||||
break;
|
||||
|
||||
case 'uninstall':
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(get_string('enrolments', 'enrol'));
|
||||
|
||||
if (get_string_manager()->string_exists('pluginname', 'enrol_'.$enrol)) {
|
||||
$strplugin = get_string('pluginname', 'enrol_'.$enrol);
|
||||
} else {
|
||||
$strplugin = $enrol;
|
||||
}
|
||||
|
||||
echo $PAGE->set_title($strplugin);
|
||||
echo $OUTPUT->header();
|
||||
|
||||
if (!$confirm) {
|
||||
$uurl = new moodle_url('/admin/enrol.php', array('action'=>'uninstall', 'enrol'=>$enrol, 'sesskey'=>sesskey(), 'confirm'=>1));
|
||||
echo $OUTPUT->confirm(get_string('uninstallconfirm', 'enrol', $strplugin), $uurl, $return);
|
||||
echo $OUTPUT->heading(get_string('enrolments', 'enrol'));
|
||||
|
||||
$deleteurl = new moodle_url('/admin/enrol.php', array('action'=>'uninstall', 'enrol'=>$enrol, 'sesskey'=>sesskey(), 'confirm'=>1, 'migrate'=>0));
|
||||
$migrateurl = new moodle_url('/admin/enrol.php', array('action'=>'uninstall', 'enrol'=>$enrol, 'sesskey'=>sesskey(), 'confirm'=>1, 'migrate'=>1));
|
||||
|
||||
$migrate = new single_button($migrateurl, get_string('uninstallmigrate', 'enrol'));
|
||||
$delete = new single_button($deleteurl, get_string('uninstalldelete', 'enrol'));
|
||||
$cancel = new single_button($return, get_string('cancel'), 'get');
|
||||
|
||||
$buttons = $OUTPUT->render($delete) . $OUTPUT->render($cancel);
|
||||
if ($enrol !== 'manual') {
|
||||
$buttons = $OUTPUT->render($migrate) . $buttons;
|
||||
}
|
||||
|
||||
echo $OUTPUT->box_start('generalbox', 'notice');
|
||||
echo html_writer::tag('p', markdown_to_html(get_string('uninstallconfirm', 'enrol', $strplugin)));
|
||||
echo html_writer::tag('div', $buttons, array('class' => 'buttons'));
|
||||
echo $OUTPUT->box_end();
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
exit;
|
||||
|
||||
} else { // Delete everything!!
|
||||
} else {
|
||||
// This may take a long time.
|
||||
set_time_limit(0);
|
||||
|
||||
// Disable plugin to prevent concurrent cron execution.
|
||||
unset($enabled[$enrol]);
|
||||
set_config('enrol_plugins_enabled', implode(',', array_keys($enabled)));
|
||||
|
||||
if ($migrate) {
|
||||
echo $OUTPUT->heading(get_string('uninstallmigrating', 'enrol', 'enrol_'.$enrol));
|
||||
|
||||
require_once("$CFG->dirroot/enrol/manual/locallib.php");
|
||||
enrol_manual_migrate_plugin_enrolments($enrol);
|
||||
|
||||
echo $OUTPUT->notification(get_string('success'), 'notifysuccess');
|
||||
}
|
||||
|
||||
// Delete everything!!
|
||||
uninstall_plugin('enrol', $enrol);
|
||||
$syscontext->mark_dirty(); // resets all enrol caches
|
||||
$syscontext->mark_dirty(); // Resets all enrol caches.
|
||||
|
||||
$a = new stdClass();
|
||||
$a->plugin = $strplugin;
|
||||
|
||||
+4
-4
@@ -933,7 +933,7 @@ class override_permissions_table_advanced extends capability_table_with_risks {
|
||||
global $DB;
|
||||
|
||||
/// Get the capabilities from the parent context, so that can be shown in the interface.
|
||||
$parentcontext = get_context_instance_by_id(get_parent_contextid($this->context));
|
||||
$parentcontext = context::instance_by_id(get_parent_contextid($this->context));
|
||||
$this->parentpermissions = role_context_capabilities($this->roleid, $parentcontext);
|
||||
}
|
||||
|
||||
@@ -996,7 +996,7 @@ abstract class role_assign_user_selector_base extends user_selector_base {
|
||||
if (isset($options['context'])) {
|
||||
$this->context = $options['context'];
|
||||
} else {
|
||||
$this->context = get_context_instance_by_id($options['contextid']);
|
||||
$this->context = context::instance_by_id($options['contextid']);
|
||||
}
|
||||
$options['accesscontext'] = $this->context;
|
||||
parent::__construct($name, $options);
|
||||
@@ -1230,7 +1230,7 @@ class existing_role_holders extends role_assign_user_selector_base {
|
||||
}
|
||||
|
||||
protected function parent_con_group_name($search, $contextid) {
|
||||
$context = get_context_instance_by_id($contextid);
|
||||
$context = context::instance_by_id($contextid);
|
||||
$contextname = print_context_name($context, true, true);
|
||||
if ($search) {
|
||||
$a = new stdClass;
|
||||
@@ -1477,7 +1477,7 @@ class role_allow_switch_page extends role_allow_role_page {
|
||||
function roles_get_potential_user_selector($context, $name, $options) {
|
||||
$blockinsidecourse = false;
|
||||
if ($context->contextlevel == CONTEXT_BLOCK) {
|
||||
$parentcontext = get_context_instance_by_id(get_parent_contextid($context));
|
||||
$parentcontext = context::instance_by_id(get_parent_contextid($context));
|
||||
$blockinsidecourse = in_array($parentcontext->contextlevel, array(CONTEXT_MODULE, CONTEXT_COURSE));
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ $string['conversioncomplete'] = 'Assignment converted';
|
||||
$string['conversionfailed'] = 'The assignment conversion was not successful. The log from the upgrade was: <br />{$a}';
|
||||
$string['listnotupgraded'] = 'List assignments that have not been upgraded';
|
||||
$string['listnotupgraded_desc'] = 'You can upgrade individual assignments from here';
|
||||
$string['noassignmentsselected'] = 'No assignments selected';
|
||||
$string['noassignmentstoupgrade'] = 'There are no assignments that require upgrading';
|
||||
$string['notsupported'] = '';
|
||||
$string['notupgradedintro'] = 'This page lists the assignments created with an older version of Moodle that have not been upgraded to the new assignment module in Moodle 2.3. Not all assignments can be upgraded - if they were created with a custom assignment subtype, then that subtype will need to be upgraded to the new assignment plugin format in order to complete the upgrade.';
|
||||
|
||||
@@ -42,8 +42,8 @@ M.tool_assignmentupgrade = {
|
||||
}
|
||||
});
|
||||
|
||||
var batchform = Y.one('.tool_assignmentupgrade_batchform form');
|
||||
batchform.on('submit', function(e) {
|
||||
var upgradeselectedbutton = Y.one('#id_upgradeselected');
|
||||
upgradeselectedbutton.on('click', function(e) {
|
||||
checkboxes = Y.all('td.c0 input');
|
||||
var selectedassignments = [];
|
||||
checkboxes.each(function(node) {
|
||||
@@ -56,7 +56,7 @@ M.tool_assignmentupgrade = {
|
||||
assignmentsinput = Y.one('input.selectedassignments');
|
||||
assignmentsinput.set('value', selectedassignments.join(','));
|
||||
if (selectedassignments.length == 0) {
|
||||
alert(M.str.assign.noassignmentsselected);
|
||||
alert(M.str.tool_assignmentupgrade.noassignmentsselected);
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -119,7 +119,7 @@ class tool_assignmentupgrade_renderer extends plugin_renderer_base {
|
||||
$output = '';
|
||||
$output .= $this->header();
|
||||
$this->page->requires->js_init_call('M.tool_assignmentupgrade.init_upgrade_table', array());
|
||||
|
||||
$this->page->requires->string_for_js('noassignmentsselected', 'tool_assignmentupgrade');
|
||||
|
||||
$output .= $this->heading(get_string('notupgradedtitle', 'tool_assignmentupgrade'));
|
||||
$output .= $this->box(get_string('notupgradedintro', 'tool_assignmentupgrade'));
|
||||
|
||||
@@ -45,7 +45,7 @@ foreach ($allcohorts as $c) {
|
||||
// external cohorts can not be modified
|
||||
continue;
|
||||
}
|
||||
$context = get_context_instance_by_id($c->contextid);
|
||||
$context = context::instance_by_id($c->contextid);
|
||||
if (!has_capability('moodle/cohort:assign', $context)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -522,9 +522,12 @@ class backup_enrolments_structure_step extends backup_structure_step {
|
||||
$enrol = new backup_nested_element('enrol', array('id'), array(
|
||||
'enrol', 'status', 'sortorder', 'name', 'enrolperiod', 'enrolstartdate',
|
||||
'enrolenddate', 'expirynotify', 'expirytreshold', 'notifyall',
|
||||
'password', 'cost', 'currency', 'roleid', 'customint1', 'customint2', 'customint3',
|
||||
'customint4', 'customchar1', 'customchar2', 'customdec1', 'customdec2',
|
||||
'customtext1', 'customtext2', 'timecreated', 'timemodified'));
|
||||
'password', 'cost', 'currency', 'roleid',
|
||||
'customint1', 'customint2', 'customint3', 'customint4', 'customint5', 'customint6', 'customint7', 'customint8',
|
||||
'customchar1', 'customchar2', 'customchar3',
|
||||
'customdec1', 'customdec2',
|
||||
'customtext1', 'customtext2', 'customtext3', 'customtext4',
|
||||
'timecreated', 'timemodified'));
|
||||
|
||||
$userenrolments = new backup_nested_element('user_enrolments');
|
||||
|
||||
@@ -1002,7 +1005,7 @@ class backup_groups_structure_step extends backup_structure_step {
|
||||
$members = new backup_nested_element('group_members');
|
||||
|
||||
$member = new backup_nested_element('group_member', array('id'), array(
|
||||
'userid', 'timeadded'));
|
||||
'userid', 'timeadded', 'component', 'itemid'));
|
||||
|
||||
$groupings = new backup_nested_element('groupings');
|
||||
|
||||
|
||||
@@ -270,7 +270,14 @@ class restore_gradebook_structure_step extends restore_structure_step {
|
||||
|
||||
$data->contextid = context_course::instance($this->get_courseid())->id;
|
||||
|
||||
$newitemid = $DB->insert_record('grade_letters', $data);
|
||||
$gradeletter = (array)$data;
|
||||
unset($gradeletter['id']);
|
||||
if (!$DB->record_exists('grade_letters', $gradeletter)) {
|
||||
$newitemid = $DB->insert_record('grade_letters', $data);
|
||||
} else {
|
||||
$newitemid = $data->id;
|
||||
}
|
||||
|
||||
$this->set_mapping('grade_letter', $oldid, $newitemid);
|
||||
}
|
||||
protected function process_grade_setting($data) {
|
||||
@@ -773,6 +780,17 @@ class restore_groups_structure_step extends restore_structure_step {
|
||||
// map user newitemid and insert if not member already
|
||||
if ($data->userid = $this->get_mappingid('user', $data->userid)) {
|
||||
if (!$DB->record_exists('groups_members', array('groupid' => $data->groupid, 'userid' => $data->userid))) {
|
||||
// Check the componment, if any, exists
|
||||
if (!empty($data->component)) {
|
||||
$dir = get_component_directory($data->component);
|
||||
if (!$dir || !is_dir($dir)) {
|
||||
// Component does not exist on restored system; clear
|
||||
// component and itemid
|
||||
unset($data->component);
|
||||
unset($data->itemid);
|
||||
}
|
||||
}
|
||||
|
||||
$DB->insert_record('groups_members', $data);
|
||||
}
|
||||
}
|
||||
@@ -2399,17 +2417,21 @@ class restore_activity_grades_structure_step extends restore_structure_step {
|
||||
|
||||
/**
|
||||
* process activity grade_letters. Note that, while these are possible,
|
||||
* because grade_letters are contextid based, in proctice, only course
|
||||
* because grade_letters are contextid based, in practice, only course
|
||||
* context letters can be defined. So we keep here this method knowing
|
||||
* it won't be executed ever. gradebook restore will restore course letters.
|
||||
*/
|
||||
protected function process_grade_letter($data) {
|
||||
global $DB;
|
||||
|
||||
$data = (object)$data;
|
||||
$data['contextid'] = $this->task->get_contextid();
|
||||
$gradeletter = (object)$data;
|
||||
|
||||
$data->contextid = $this->task->get_contextid();
|
||||
$newitemid = $DB->insert_record('grade_letters', $data);
|
||||
// Check if it exists before adding it
|
||||
unset($data['id']);
|
||||
if (!$DB->record_exists('grade_letters', $data)) {
|
||||
$newitemid = $DB->insert_record('grade_letters', $gradeletter);
|
||||
}
|
||||
// no need to save any grade_letter mapping
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ class block_community extends block_list {
|
||||
function user_can_edit() {
|
||||
// Don't allow people to edit the block if they can't even use it
|
||||
if (!has_capability('moodle/community:add',
|
||||
get_context_instance_by_id($this->instance->parentcontextid))) {
|
||||
context::instance_by_id($this->instance->parentcontextid))) {
|
||||
return false;
|
||||
}
|
||||
return parent::user_can_edit();
|
||||
@@ -52,7 +52,7 @@ class block_community extends block_list {
|
||||
function get_content() {
|
||||
global $CFG, $OUTPUT, $USER;
|
||||
|
||||
$coursecontext = get_context_instance_by_id($this->instance->parentcontextid);
|
||||
$coursecontext = context::instance_by_id($this->instance->parentcontextid);
|
||||
|
||||
if (!has_capability('moodle/community:add', $coursecontext)
|
||||
or $this->content !== NULL) {
|
||||
|
||||
@@ -87,7 +87,7 @@ class block_edit_form extends moodleform {
|
||||
|
||||
$regionoptions = $this->page->theme->get_all_block_regions();
|
||||
|
||||
$parentcontext = get_context_instance_by_id($this->block->instance->parentcontextid);
|
||||
$parentcontext = context::instance_by_id($this->block->instance->parentcontextid);
|
||||
$mform->addElement('hidden', 'bui_parentcontextid', $parentcontext->id);
|
||||
|
||||
$mform->addElement('static', 'bui_homecontext', get_string('createdat', 'block'), print_context_name($parentcontext));
|
||||
|
||||
@@ -29,6 +29,10 @@ class block_html extends block_base {
|
||||
$this->title = get_string('pluginname', 'block_html');
|
||||
}
|
||||
|
||||
function has_config() {
|
||||
return true;
|
||||
}
|
||||
|
||||
function applicable_formats() {
|
||||
return array('all' => true);
|
||||
}
|
||||
@@ -104,7 +108,7 @@ class block_html extends block_base {
|
||||
function content_is_trusted() {
|
||||
global $SCRIPT;
|
||||
|
||||
if (!$context = get_context_instance_by_id($this->instance->parentcontextid)) {
|
||||
if (!$context = context::instance_by_id($this->instance->parentcontextid, IGNORE_MISSING)) {
|
||||
return false;
|
||||
}
|
||||
//find out if this block is on the profile page
|
||||
@@ -138,10 +142,14 @@ class block_html extends block_base {
|
||||
* @return array
|
||||
*/
|
||||
function html_attributes() {
|
||||
global $CFG;
|
||||
|
||||
$attributes = parent::html_attributes();
|
||||
|
||||
if (!empty($this->config->classes)) {
|
||||
$attributes['class'] .= ' '.$this->config->classes;
|
||||
if (!empty($CFG->block_html_allowcssclasses)) {
|
||||
if (!empty($this->config->classes)) {
|
||||
$attributes['class'] .= ' '.$this->config->classes;
|
||||
}
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
*/
|
||||
class block_html_edit_form extends block_edit_form {
|
||||
protected function specific_definition($mform) {
|
||||
global $CFG;
|
||||
|
||||
// Fields for editing HTML block title and contents.
|
||||
$mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
|
||||
|
||||
@@ -42,9 +44,11 @@ class block_html_edit_form extends block_edit_form {
|
||||
$mform->addRule('config_text', null, 'required', null, 'client');
|
||||
$mform->setType('config_text', PARAM_RAW); // XSS is prevented when printing the block contents and serving files
|
||||
|
||||
$mform->addElement('text', 'config_classes', get_string('configclasses', 'block_html'));
|
||||
$mform->setType('config_classes', PARAM_TEXT);
|
||||
$mform->addHelpButton('config_classes', 'configclasses', 'block_html');
|
||||
if (!empty($CFG->block_html_allowcssclasses)) {
|
||||
$mform->addElement('text', 'config_classes', get_string('configclasses', 'block_html'));
|
||||
$mform->setType('config_classes', PARAM_TEXT);
|
||||
$mform->addHelpButton('config_classes', 'configclasses', 'block_html');
|
||||
}
|
||||
}
|
||||
|
||||
function set_data($defaults) {
|
||||
|
||||
@@ -23,7 +23,9 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['configclasses'] = 'Additional HTML classes';
|
||||
$string['allowadditionalcssclasses'] = 'Allow additional CSS classes';
|
||||
$string['configallowadditionalcssclasses'] = 'Adds a configuration option to HTML block instances allowing additional CSS classes to be set.';
|
||||
$string['configclasses'] = 'Additional CSS classes';
|
||||
$string['configclasses_help'] = 'The purpose of this configuration is to aid with theming by helping distinguish HTML blocks from each other. Any CSS classes entered here (space delimited) will be appended to the block\'s default classes.';
|
||||
$string['configcontent'] = 'Content';
|
||||
$string['configtitle'] = 'Block title';
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@ function block_html_pluginfile($course, $birecord_or_cm, $context, $filearea, $a
|
||||
send_file_not_found();
|
||||
}
|
||||
|
||||
if ($parentcontext = get_context_instance_by_id($birecord_or_cm->parentcontextid)) {
|
||||
if ($parentcontext = context::instance_by_id($birecord_or_cm->parentcontextid, IGNORE_MISSING)) {
|
||||
if ($parentcontext->contextlevel == CONTEXT_USER) {
|
||||
// force download on all personal pages including /my/
|
||||
//because we do not have reliable way to find out from where this is used
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
if ($ADMIN->fulltree) {
|
||||
$settings->add(new admin_setting_configcheckbox('block_html_allowcssclasses', get_string('allowadditionalcssclasses', 'block_html'),
|
||||
get_string('configallowadditionalcssclasses', 'block_html'), 0));
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ class block_quiz_results extends block_base {
|
||||
if (empty($this->instance->parentcontextid)) {
|
||||
return 0;
|
||||
}
|
||||
$parentcontext = get_context_instance_by_id($this->instance->parentcontextid);
|
||||
$parentcontext = context::instance_by_id($this->instance->parentcontextid);
|
||||
if ($parentcontext->contextlevel != CONTEXT_MODULE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ $id = required_param('id', PARAM_INT);
|
||||
require_login();
|
||||
|
||||
$cohort = $DB->get_record('cohort', array('id'=>$id), '*', MUST_EXIST);
|
||||
$context = get_context_instance_by_id($cohort->contextid, MUST_EXIST);
|
||||
$context = context::instance_by_id($cohort->contextid, MUST_EXIST);
|
||||
|
||||
require_capability('moodle/cohort:assign', $context);
|
||||
|
||||
|
||||
+2
-2
@@ -40,9 +40,9 @@ require_login();
|
||||
$category = null;
|
||||
if ($id) {
|
||||
$cohort = $DB->get_record('cohort', array('id'=>$id), '*', MUST_EXIST);
|
||||
$context = get_context_instance_by_id($cohort->contextid, MUST_EXIST);
|
||||
$context = context::instance_by_id($cohort->contextid, MUST_EXIST);
|
||||
} else {
|
||||
$context = get_context_instance_by_id($contextid, MUST_EXIST);
|
||||
$context = context::instance_by_id($contextid, MUST_EXIST);
|
||||
if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
|
||||
print_error('invalidcontext');
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ class cohort_edit_form extends moodleform {
|
||||
}
|
||||
// always add current - this is not likely, but if the logic gets changed it might be a problem
|
||||
if (!isset($options[$currentcontextid])) {
|
||||
$context = get_context_instance_by_id($currentcontextid, MUST_EXIST);
|
||||
$context = context::instance_by_id($currentcontextid, MUST_EXIST);
|
||||
$options[$context->id] = print_context_name($syscontext);
|
||||
}
|
||||
return $options;
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ $searchquery = optional_param('search', '', PARAM_RAW);
|
||||
require_login();
|
||||
|
||||
if ($contextid) {
|
||||
$context = get_context_instance_by_id($contextid, MUST_EXIST);
|
||||
$context = context::instance_by_id($contextid, MUST_EXIST);
|
||||
} else {
|
||||
$context = context_system::instance();
|
||||
}
|
||||
|
||||
@@ -155,6 +155,18 @@ function cohort_remove_member($cohortid, $userid) {
|
||||
events_trigger('cohort_member_removed', (object)array('cohortid'=>$cohortid, 'userid'=>$userid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this user a cohort member?
|
||||
* @param int $cohortid
|
||||
* @param int $userid
|
||||
* @return bool
|
||||
*/
|
||||
function cohort_is_member($cohortid, $userid) {
|
||||
global $DB;
|
||||
|
||||
return $DB->record_exists('cohort_members', array('cohortid'=>$cohortid, 'userid'=>$userid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of visible cohorts in course.
|
||||
*
|
||||
|
||||
+1
-1
@@ -120,7 +120,7 @@ class comment {
|
||||
$this->contextid = $this->context->id;
|
||||
} else if(!empty($options->contextid)) {
|
||||
$this->contextid = $options->contextid;
|
||||
$this->context = get_context_instance_by_id($this->contextid);
|
||||
$this->context = context::instance_by_id($this->contextid);
|
||||
} else {
|
||||
print_error('invalidcontext');
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ class comment_manager {
|
||||
*/
|
||||
private function setup_plugin($comment) {
|
||||
global $DB;
|
||||
$this->context = get_context_instance_by_id($comment->contextid);
|
||||
$this->context = context::instance_by_id($comment->contextid, IGNORE_MISSING);
|
||||
if (!$this->context) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ class editsection_form extends moodleform {
|
||||
$course = $this->_customdata['course'];
|
||||
|
||||
if (!empty($CFG->enableavailability)) {
|
||||
$mform->addElement('header', '', get_string('availabilityconditions', 'condition'));
|
||||
// String used by conditions more than once
|
||||
$strcondnone = get_string('none', 'condition');
|
||||
// Grouping conditions - only if grouping is enabled at site level
|
||||
@@ -51,7 +52,6 @@ class editsection_form extends moodleform {
|
||||
$grouping->name, true, array('context' => $context));
|
||||
}
|
||||
}
|
||||
$mform->addElement('header', '', get_string('availabilityconditions', 'condition'));
|
||||
$mform->addElement('select', 'groupingid', get_string('groupingsection', 'group'), $options);
|
||||
$mform->addHelpButton('groupingid', 'groupingsection', 'group');
|
||||
}
|
||||
|
||||
+18
-15
@@ -531,10 +531,19 @@ function print_mnet_log($hostid, $course, $user=0, $date=0, $order="l.time ASC",
|
||||
|
||||
function print_log_csv($course, $user, $date, $order='l.time DESC', $modname,
|
||||
$modid, $modaction, $groupid) {
|
||||
global $DB;
|
||||
global $DB, $CFG;
|
||||
|
||||
$text = get_string('course')."\t".get_string('time')."\t".get_string('ip_address')."\t".
|
||||
get_string('fullnameuser')."\t".get_string('action')."\t".get_string('info');
|
||||
require_once($CFG->libdir . '/csvlib.class.php');
|
||||
|
||||
$csvexporter = new csv_export_writer('tab');
|
||||
|
||||
$header = array();
|
||||
$header[] = get_string('course');
|
||||
$header[] = get_string('time');
|
||||
$header[] = get_string('ip_address');
|
||||
$header[] = get_string('fullnameuser');
|
||||
$header[] = get_string('action');
|
||||
$header[] = get_string('info');
|
||||
|
||||
if (!$logs = build_logs_array($course, $user, $date, $order, '', '',
|
||||
$modname, $modid, $modaction, $groupid)) {
|
||||
@@ -561,16 +570,10 @@ function print_log_csv($course, $user, $date, $order='l.time DESC', $modname,
|
||||
|
||||
$strftimedatetime = get_string("strftimedatetime");
|
||||
|
||||
$filename = 'logs_'.userdate(time(),get_string('backupnameformat', 'langconfig'),99,false);
|
||||
$filename .= '.txt';
|
||||
header("Content-Type: application/download\n");
|
||||
header("Content-Disposition: attachment; filename=\"$filename\"");
|
||||
header("Expires: 0");
|
||||
header("Cache-Control: must-revalidate,post-check=0,pre-check=0");
|
||||
header("Pragma: public");
|
||||
|
||||
echo get_string('savedat').userdate(time(), $strftimedatetime)."\n";
|
||||
echo $text."\n";
|
||||
$csvexporter->set_filename('logs', '.txt');
|
||||
$title = array(get_string('savedat').userdate(time(), $strftimedatetime));
|
||||
$csvexporter->add_data($title);
|
||||
$csvexporter->add_data($header);
|
||||
|
||||
if (empty($logs['logs'])) {
|
||||
return true;
|
||||
@@ -600,9 +603,9 @@ function print_log_csv($course, $user, $date, $order='l.time DESC', $modname,
|
||||
$firstField = format_string($courses[$log->course], true, array('context' => $coursecontext));
|
||||
$fullname = fullname($log, has_capability('moodle/site:viewfullnames', $coursecontext));
|
||||
$row = array($firstField, userdate($log->time, $strftimedatetime), $log->ip, $fullname, $log->module.' '.$log->action, $log->info);
|
||||
$text = implode("\t", $row);
|
||||
echo $text." \n";
|
||||
$csvexporter->add_data($row);
|
||||
}
|
||||
$csvexporter->download_file();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,13 +61,13 @@ class course_reset_form extends moodleform {
|
||||
if ($allmods = $DB->get_records('modules') ) {
|
||||
foreach ($allmods as $mod) {
|
||||
$modname = $mod->name;
|
||||
if (!$DB->count_records($modname, array('course'=>$COURSE->id))) {
|
||||
continue; // skip mods with no instances
|
||||
}
|
||||
$modfile = $CFG->dirroot."/mod/$modname/lib.php";
|
||||
$mod_reset_course_form_definition = $modname.'_reset_course_form_definition';
|
||||
$mod_reset__userdata = $modname.'_reset_userdata';
|
||||
if (file_exists($modfile)) {
|
||||
if (!$DB->count_records($modname, array('course'=>$COURSE->id))) {
|
||||
continue; // Skip mods with no instances
|
||||
}
|
||||
include_once($modfile);
|
||||
if (function_exists($mod_reset_course_form_definition)) {
|
||||
$mod_reset_course_form_definition($mform);
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ if ($component !== 'user' or $filearea !== 'draft') {
|
||||
send_file_not_found();
|
||||
}
|
||||
|
||||
$context = get_context_instance_by_id($contextid);
|
||||
$context = context::instance_by_id($contextid);
|
||||
if ($context->contextlevel != CONTEXT_USER) {
|
||||
send_file_not_found();
|
||||
}
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ switch ($action) {
|
||||
case 'unenrol':
|
||||
$ue = $DB->get_record('user_enrolments', array('id'=>required_param('ue', PARAM_INT)), '*', MUST_EXIST);
|
||||
list ($instance, $plugin) = $manager->get_user_enrolment_components($ue);
|
||||
if (!$instance || !$plugin || !$plugin->allow_unenrol_user($instance, $ue) || !has_capability("enrol/$instance->enrol:unenrol", $manager->get_context()) || !$manager->unenrol_user($ue)) {
|
||||
if (!$instance || !$plugin || !enrol_is_enabled($instance->enrol) || !$plugin->allow_unenrol_user($instance, $ue) || !has_capability("enrol/$instance->enrol:unenrol", $manager->get_context()) || !$manager->unenrol_user($ue)) {
|
||||
throw new enrol_ajax_exception('unenrolnotpermitted');
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -45,8 +45,8 @@ class enrol_category_handler {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Only category level roles are interesting.
|
||||
$parentcontext = get_context_instance_by_id($ra->contextid);
|
||||
//only category level roles are interesting
|
||||
$parentcontext = context::instance_by_id($ra->contextid);
|
||||
if ($parentcontext->contextlevel != CONTEXT_COURSECAT) {
|
||||
return true;
|
||||
}
|
||||
@@ -102,8 +102,8 @@ class enrol_category_handler {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Only category level roles are interesting.
|
||||
$parentcontext = get_context_instance_by_id($ra->contextid);
|
||||
// only category level roles are interesting
|
||||
$parentcontext = context::instance_by_id($ra->contextid);
|
||||
if ($parentcontext->contextlevel != CONTEXT_COURSECAT) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ class enrol_cohort_addinstance_form extends moodleform {
|
||||
ORDER BY name ASC";
|
||||
$rs = $DB->get_recordset_sql($sql, $params);
|
||||
foreach ($rs as $c) {
|
||||
$context = get_context_instance_by_id($c->contextid);
|
||||
$context = context::instance_by_id($c->contextid);
|
||||
if (!has_capability('moodle/cohort:view', $context)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ class enrol_cohort_plugin extends enrol_plugin {
|
||||
ORDER BY name ASC";
|
||||
$cohorts = $DB->get_records_sql($sql, $params);
|
||||
foreach ($cohorts as $c) {
|
||||
$context = get_context_instance_by_id($c->contextid);
|
||||
$context = context::instance_by_id($c->contextid);
|
||||
if (has_capability('moodle/cohort:view', $context)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -368,7 +368,7 @@ function enrol_cohort_get_cohorts(course_enrolment_manager $manager) {
|
||||
ORDER BY name ASC";
|
||||
$rs = $DB->get_recordset_sql($sql, $params);
|
||||
foreach ($rs as $c) {
|
||||
$context = get_context_instance_by_id($c->contextid);
|
||||
$context = context::instance_by_id($c->contextid);
|
||||
if (!has_capability('moodle/cohort:view', $context)) {
|
||||
continue;
|
||||
}
|
||||
@@ -394,7 +394,7 @@ function enrol_cohort_can_view_cohort($cohortid) {
|
||||
global $DB;
|
||||
$cohort = $DB->get_record('cohort', array('id' => $cohortid), 'id, contextid');
|
||||
if ($cohort) {
|
||||
$context = get_context_instance_by_id($cohort->contextid);
|
||||
$context = context::instance_by_id($cohort->contextid);
|
||||
if (has_capability('moodle/cohort:view', $context)) {
|
||||
return true;
|
||||
}
|
||||
@@ -457,7 +457,7 @@ function enrol_cohort_search_cohorts(course_enrolment_manager $manager, $offset
|
||||
// Track offset
|
||||
$offset++;
|
||||
// Check capabilities
|
||||
$context = get_context_instance_by_id($c->contextid);
|
||||
$context = context::instance_by_id($c->contextid);
|
||||
if (!has_capability('moodle/cohort:view', $context)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -381,7 +381,7 @@ class core_role_external extends external_api {
|
||||
|
||||
foreach ($params['assignments'] as $assignment) {
|
||||
// Ensure the current user is allowed to run this function in the enrolment context
|
||||
$context = get_context_instance_by_id($assignment['contextid']);
|
||||
$context = context::instance_by_id($assignment['contextid'], IGNORE_MISSING);
|
||||
self::validate_context($context);
|
||||
require_capability('moodle/role:assign', $context);
|
||||
|
||||
@@ -445,7 +445,7 @@ class core_role_external extends external_api {
|
||||
|
||||
foreach ($params['unassignments'] as $unassignment) {
|
||||
// Ensure the current user is allowed to run this function in the unassignment context
|
||||
$context = get_context_instance_by_id($unassignment['contextid']);
|
||||
$context = context::instance_by_id($unassignment['contextid'], IGNORE_MISSING);
|
||||
self::validate_context($context);
|
||||
require_capability('moodle/role:assign', $context);
|
||||
|
||||
|
||||
@@ -702,7 +702,8 @@ function process_membership_tag($tagcontents){
|
||||
}
|
||||
// Add the user-to-group association if it doesn't already exist
|
||||
if($member->groupid) {
|
||||
groups_add_member($member->groupid, $memberstoreobj->userid);
|
||||
groups_add_member($member->groupid, $memberstoreobj->userid,
|
||||
'enrol_imsenterprise', $einstance->id);
|
||||
}
|
||||
} // End of group-enrolment (from member.role.extension.cohort tag)
|
||||
|
||||
@@ -793,6 +794,19 @@ function load_role_mappings() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called whenever anybody tries (from the normal interface) to remove a group
|
||||
* member which is registered as being created by this component. (Not called
|
||||
* when deleting an entire group or course at once.)
|
||||
* @param int $itemid Item ID that was stored in the group_members entry
|
||||
* @param int $groupid Group ID
|
||||
* @param int $userid User ID being removed from group
|
||||
* @return bool True if the remove is permitted, false to give an error
|
||||
*/
|
||||
function enrol_imsenterprise_allow_group_member_remove($itemid, $groupid, $userid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // end of class
|
||||
|
||||
|
||||
|
||||
+42
-11
@@ -97,6 +97,7 @@ class course_enrolment_manager {
|
||||
private $_instances = null;
|
||||
private $_inames = null;
|
||||
private $_plugins = null;
|
||||
private $_allplugins = null;
|
||||
private $_roles = null;
|
||||
private $_assignableroles = null;
|
||||
private $_assignablerolesothers = null;
|
||||
@@ -397,11 +398,13 @@ class course_enrolment_manager {
|
||||
/**
|
||||
* Returns all of the enrolment instances for this course.
|
||||
*
|
||||
* NOTE: since 2.4 it includes instances of disabled plugins too.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_enrolment_instances() {
|
||||
if ($this->_instances === null) {
|
||||
$this->_instances = enrol_get_instances($this->course->id, true);
|
||||
$this->_instances = enrol_get_instances($this->course->id, false);
|
||||
}
|
||||
return $this->_instances;
|
||||
}
|
||||
@@ -409,12 +412,14 @@ class course_enrolment_manager {
|
||||
/**
|
||||
* Returns the names for all of the enrolment instances for this course.
|
||||
*
|
||||
* NOTE: since 2.4 it includes instances of disabled plugins too.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_enrolment_instance_names() {
|
||||
if ($this->_inames === null) {
|
||||
$instances = $this->get_enrolment_instances();
|
||||
$plugins = $this->get_enrolment_plugins();
|
||||
$plugins = $this->get_enrolment_plugins(false);
|
||||
foreach ($instances as $key=>$instance) {
|
||||
if (!isset($plugins[$instance->enrol])) {
|
||||
// weird, some broken stuff in plugin
|
||||
@@ -430,13 +435,29 @@ class course_enrolment_manager {
|
||||
/**
|
||||
* Gets all of the enrolment plugins that are active for this course.
|
||||
*
|
||||
* @param bool $onlyenabled return only enabled enrol plugins
|
||||
* @return array
|
||||
*/
|
||||
public function get_enrolment_plugins() {
|
||||
public function get_enrolment_plugins($onlyenabled = true) {
|
||||
if ($this->_plugins === null) {
|
||||
$this->_plugins = enrol_get_plugins(true);
|
||||
}
|
||||
return $this->_plugins;
|
||||
|
||||
if ($onlyenabled) {
|
||||
return $this->_plugins;
|
||||
}
|
||||
|
||||
if ($this->_allplugins === null) {
|
||||
// Make sure we have the same objects in _allplugins and _plugins.
|
||||
$this->_allplugins = $this->_plugins;
|
||||
foreach (enrol_get_plugins(false) as $name=>$plugin) {
|
||||
if (!isset($this->_allplugins[$name])) {
|
||||
$this->_allplugins[$name] = $plugin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_allplugins;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -522,7 +543,7 @@ class course_enrolment_manager {
|
||||
$userenrolment = $DB->get_record('user_enrolments', array('id'=>(int)$userenrolment));
|
||||
}
|
||||
$instances = $this->get_enrolment_instances();
|
||||
$plugins = $this->get_enrolment_plugins();
|
||||
$plugins = $this->get_enrolment_plugins(false);
|
||||
if (!$userenrolment || !isset($instances[$userenrolment->enrolid])) {
|
||||
return array(false, false);
|
||||
}
|
||||
@@ -675,7 +696,7 @@ class course_enrolment_manager {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the enrolments this user has in the course
|
||||
* Gets the enrolments this user has in the course - including all suspended plugins and instances.
|
||||
*
|
||||
* @global moodle_database $DB
|
||||
* @param int $userid
|
||||
@@ -687,7 +708,7 @@ class course_enrolment_manager {
|
||||
$params['userid'] = $userid;
|
||||
$userenrolments = $DB->get_records_select('user_enrolments', "enrolid $instancessql AND userid = :userid", $params);
|
||||
$instances = $this->get_enrolment_instances();
|
||||
$plugins = $this->get_enrolment_plugins();
|
||||
$plugins = $this->get_enrolment_plugins(false);
|
||||
$inames = $this->get_enrolment_instance_names();
|
||||
foreach ($userenrolments as &$ue) {
|
||||
$ue->enrolmentinstance = $instances[$ue->enrolid];
|
||||
@@ -829,6 +850,8 @@ class course_enrolment_manager {
|
||||
$url = new moodle_url($pageurl, $this->get_url_params());
|
||||
$extrafields = get_extra_user_fields($context);
|
||||
|
||||
$enabledplugins = $this->get_enrolment_plugins(true);
|
||||
|
||||
$userdetails = array();
|
||||
foreach ($users as $user) {
|
||||
$details = $this->prepare_user_for_display($user, $extrafields, $now);
|
||||
@@ -849,7 +872,15 @@ class course_enrolment_manager {
|
||||
// Enrolments
|
||||
$details['enrolments'] = array();
|
||||
foreach ($this->get_user_enrolments($user->id) as $ue) {
|
||||
if ($ue->timestart and $ue->timeend) {
|
||||
if (!isset($enabledplugins[$ue->enrolmentinstance->enrol])) {
|
||||
$details['enrolments'][$ue->id] = array(
|
||||
'text' => $ue->enrolmentinstancename,
|
||||
'period' => null,
|
||||
'dimmed' => true,
|
||||
'actions' => array()
|
||||
);
|
||||
continue;
|
||||
} else if ($ue->timestart and $ue->timeend) {
|
||||
$period = get_string('periodstartend', 'enrol', array('start'=>userdate($ue->timestart), 'end'=>userdate($ue->timeend)));
|
||||
$periodoutside = ($ue->timestart && $ue->timeend && $now < $ue->timestart && $now > $ue->timeend);
|
||||
} else if ($ue->timestart) {
|
||||
@@ -909,7 +940,7 @@ class course_enrolment_manager {
|
||||
}
|
||||
|
||||
public function get_manual_enrol_buttons() {
|
||||
$plugins = $this->get_enrolment_plugins();
|
||||
$plugins = $this->get_enrolment_plugins(true); // Skip disabled plugins.
|
||||
$buttons = array();
|
||||
foreach ($plugins as $plugin) {
|
||||
$newbutton = $plugin->get_manual_enrol_button($this);
|
||||
@@ -941,7 +972,7 @@ class course_enrolment_manager {
|
||||
*/
|
||||
public function get_filtered_enrolment_plugin() {
|
||||
$instances = $this->get_enrolment_instances();
|
||||
$plugins = $this->get_enrolment_plugins();
|
||||
$plugins = $this->get_enrolment_plugins(false);
|
||||
|
||||
if (empty($this->instancefilter) || !array_key_exists($this->instancefilter, $instances)) {
|
||||
return false;
|
||||
@@ -965,7 +996,7 @@ class course_enrolment_manager {
|
||||
global $DB;
|
||||
|
||||
$instances = $this->get_enrolment_instances();
|
||||
$plugins = $this->get_enrolment_plugins();
|
||||
$plugins = $this->get_enrolment_plugins(false);
|
||||
|
||||
if (!empty($this->instancefilter)) {
|
||||
$instancesql = ' = :instanceid';
|
||||
|
||||
@@ -20,8 +20,7 @@
|
||||
* The general idea behind this file is that any errors should throw exceptions
|
||||
* which will be returned and acted upon by the calling AJAX script.
|
||||
*
|
||||
* @package enrol
|
||||
* @subpackage manual
|
||||
* @package enrol_manual
|
||||
* @copyright 2010 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@@ -32,8 +31,7 @@ require('../../config.php');
|
||||
require_once($CFG->dirroot.'/enrol/locallib.php');
|
||||
require_once($CFG->dirroot.'/group/lib.php');
|
||||
|
||||
// Must have the sesskey
|
||||
$id = required_param('id', PARAM_INT); // course id
|
||||
$id = required_param('id', PARAM_INT); // Course id.
|
||||
$action = required_param('action', PARAM_ALPHANUMEXT);
|
||||
|
||||
$PAGE->set_url(new moodle_url('/enrol/ajax.php', array('id'=>$id, 'action'=>$action)));
|
||||
@@ -49,7 +47,7 @@ require_login($course);
|
||||
require_capability('moodle/course:enrolreview', $context);
|
||||
require_sesskey();
|
||||
|
||||
echo $OUTPUT->header(); // send headers
|
||||
echo $OUTPUT->header(); // Send headers.
|
||||
|
||||
$manager = new course_enrolment_manager($PAGE, $course);
|
||||
|
||||
@@ -113,11 +111,14 @@ switch ($action) {
|
||||
|
||||
$user = $DB->get_record('user', array('id'=>$userid), '*', MUST_EXIST);
|
||||
$instances = $manager->get_enrolment_instances();
|
||||
$plugins = $manager->get_enrolment_plugins();
|
||||
$plugins = $manager->get_enrolment_plugins(true); // Do not allow actions on disabled plugins.
|
||||
if (!array_key_exists($enrolid, $instances)) {
|
||||
throw new enrol_ajax_exception('invalidenrolinstance');
|
||||
}
|
||||
$instance = $instances[$enrolid];
|
||||
if (!isset($plugins[$instance->enrol])) {
|
||||
throw new enrol_ajax_exception('enrolnotpermitted');
|
||||
}
|
||||
$plugin = $plugins[$instance->enrol];
|
||||
if ($plugin->allow_enrol($instance) && has_capability('enrol/'.$plugin->get_name().':enrol', $context)) {
|
||||
$plugin->enrol_user($instance, $user->id, $roleid, $timestart, $timeend);
|
||||
@@ -135,4 +136,4 @@ switch ($action) {
|
||||
throw new enrol_ajax_exception('unknowajaxaction');
|
||||
}
|
||||
|
||||
echo json_encode($outcome);
|
||||
echo json_encode($outcome);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@@ -18,8 +17,7 @@
|
||||
/**
|
||||
* This file contains form for bulk changing user enrolments.
|
||||
*
|
||||
* @package core
|
||||
* @subpackage enrol
|
||||
* @package enrol_manual
|
||||
* @copyright 2011 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@@ -29,7 +27,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
require_once("$CFG->dirroot/enrol/bulkchange_forms.php");
|
||||
|
||||
/**
|
||||
* The form to collect required information when bulk editing users enrolments
|
||||
* The form to collect required information when bulk editing users enrolments.
|
||||
*
|
||||
* @copyright 2011 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
|
||||
@@ -26,6 +26,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$capabilities = array(
|
||||
|
||||
/* Add, edit or remove manual enrol instance. */
|
||||
'enrol/manual:config' => array(
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_COURSE,
|
||||
@@ -34,6 +35,7 @@ $capabilities = array(
|
||||
)
|
||||
),
|
||||
|
||||
/* Enrol anybody. */
|
||||
'enrol/manual:enrol' => array(
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_COURSE,
|
||||
@@ -43,6 +45,7 @@ $capabilities = array(
|
||||
)
|
||||
),
|
||||
|
||||
/* Manage enrolments of users. */
|
||||
'enrol/manual:manage' => array(
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_COURSE,
|
||||
@@ -52,6 +55,7 @@ $capabilities = array(
|
||||
)
|
||||
),
|
||||
|
||||
/* Unenrol anybody (including self) - watch out for data loss. */
|
||||
'enrol/manual:unenrol' => array(
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_COURSE,
|
||||
@@ -61,6 +65,7 @@ $capabilities = array(
|
||||
)
|
||||
),
|
||||
|
||||
/* Unenrol self - watch out for data loss. */
|
||||
'enrol/manual:unenrolself' => array(
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_COURSE,
|
||||
@@ -69,4 +74,3 @@ $capabilities = array(
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@@ -18,8 +17,7 @@
|
||||
/**
|
||||
* Manual enrol plugin installation script
|
||||
*
|
||||
* @package enrol
|
||||
* @subpackage manual
|
||||
* @package enrol_manual
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@@ -19,8 +18,7 @@
|
||||
* Adds new instance of enrol_manual to specified course
|
||||
* or edits current instance.
|
||||
*
|
||||
* @package enrol
|
||||
* @subpackage manual
|
||||
* @package enrol_manual
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@@ -49,14 +47,14 @@ $plugin = enrol_get_plugin('manual');
|
||||
if ($instances = $DB->get_records('enrol', array('courseid'=>$course->id, 'enrol'=>'manual'), 'id ASC')) {
|
||||
$instance = array_shift($instances);
|
||||
if ($instances) {
|
||||
// oh - we allow only one instance per course!!
|
||||
// Oh - we allow only one instance per course!!
|
||||
foreach ($instances as $del) {
|
||||
$plugin->delete_instance($del);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
require_capability('moodle/course:enrolconfig', $context);
|
||||
// no instance yet, we have to add new instance
|
||||
// No instance yet, we have to add new instance.
|
||||
navigation_node::override_active_url(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));
|
||||
$instance = new stdClass();
|
||||
$instance->id = null;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@@ -19,8 +18,7 @@
|
||||
* Adds new instance of enrol_manual to specified course
|
||||
* or edits current instance.
|
||||
*
|
||||
* @package enrol
|
||||
* @subpackage manual
|
||||
* @package enrol_manual
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@@ -62,4 +60,4 @@ class enrol_manual_edit_form extends moodleform {
|
||||
|
||||
$this->set_data($instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,46 +20,42 @@
|
||||
* This page allows the current user to edit a manual user enrolment.
|
||||
* It is not compatible with the frontpage.
|
||||
*
|
||||
* @package enrol
|
||||
* @subpackage manual
|
||||
* @package enrol_manual
|
||||
* @copyright 2011 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require('../../config.php');
|
||||
require_once("$CFG->dirroot/enrol/locallib.php");
|
||||
require_once("$CFG->dirroot/enrol/renderer.php"); // Required for the course enrolment manager table
|
||||
require_once("$CFG->dirroot/enrol/renderer.php"); // Required for the course enrolment manager table.
|
||||
require_once("$CFG->dirroot/enrol/manual/editenrolment_form.php");
|
||||
|
||||
$ueid = required_param('ue', PARAM_INT); // user enrolment id
|
||||
$ueid = required_param('ue', PARAM_INT); // User enrolment id.
|
||||
$filter = optional_param('ifilter', 0, PARAM_INT);
|
||||
|
||||
// Get the user enrolment object
|
||||
$ue = $DB->get_record('user_enrolments', array('id' => $ueid), '*', MUST_EXIST);
|
||||
// Get the user for whom the enrolment is
|
||||
$user = $DB->get_record('user', array('id'=>$ue->userid), '*', MUST_EXIST);
|
||||
// Get the course the enrolment is to
|
||||
list($ctxsql, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
|
||||
$sql = "SELECT c.* $ctxsql
|
||||
// Get the user enrolment object.
|
||||
$ue = $DB->get_record('user_enrolments', array('id' => $ueid), '*', MUST_EXIST);
|
||||
// Get the user for whom the enrolment is.
|
||||
$user = $DB->get_record('user', array('id'=>$ue->userid), '*', MUST_EXIST);
|
||||
// Get the course the enrolment is to.
|
||||
$sql = "SELECT c.*
|
||||
FROM {course} c
|
||||
LEFT JOIN {enrol} e ON e.courseid = c.id
|
||||
$ctxjoin
|
||||
JOIN {enrol} e ON e.courseid = c.id
|
||||
WHERE e.id = :enrolid";
|
||||
$params = array('enrolid' => $ue->enrolid);
|
||||
$course = $DB->get_record_sql($sql, $params, MUST_EXIST);
|
||||
context_instance_preload($course);
|
||||
|
||||
// Make sure its not the front page course
|
||||
// Make sure its not the front page course.
|
||||
if ($course->id == SITEID) {
|
||||
redirect(new moodle_url('/'));
|
||||
}
|
||||
|
||||
// Obviously
|
||||
// Obviously.
|
||||
require_login($course);
|
||||
// Make sure the user can manage manual enrolments for this course
|
||||
// Make sure the user can manage manual enrolments for this course.
|
||||
require_capability("enrol/manual:manage", context_course::instance($course->id, MUST_EXIST));
|
||||
|
||||
// Get the enrolment manager for this course
|
||||
// Get the enrolment manager for this course.
|
||||
$manager = new course_enrolment_manager($PAGE, $course, $filter);
|
||||
// Get an enrolment users table object. Doign this will automatically retrieve the the URL params
|
||||
// relating to table the user was viewing before coming here, and allows us to return the user to the
|
||||
@@ -70,7 +66,7 @@ $table = new course_enrolment_users_table($manager, $PAGE);
|
||||
$usersurl = new moodle_url('/enrol/users.php', array('id' => $course->id));
|
||||
// The URl to return the user too after this screen.
|
||||
$returnurl = new moodle_url($usersurl, $manager->get_url_params()+$table->get_url_params());
|
||||
// The URL of this page
|
||||
// The URL of this page.
|
||||
$url = new moodle_url('/enrol/manual/editenrolment.php', $returnurl->params());
|
||||
|
||||
$PAGE->set_url($url);
|
||||
@@ -88,9 +84,7 @@ $mform->set_data($PAGE->url->params());
|
||||
// Check the form hasn't been cancelled
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect($returnurl);
|
||||
} else if ($mform->is_submitted() && $mform->is_validated() && confirm_sesskey()) {
|
||||
// The forms been submit, validated and the sesskey has been checked ... edit the enrolment.
|
||||
$data = $mform->get_data();
|
||||
} else if ($data = $mform->get_data()) {
|
||||
if ($manager->edit_enrolment($ue, $data)) {
|
||||
redirect($returnurl);
|
||||
}
|
||||
@@ -107,4 +101,4 @@ $PAGE->navbar->add($fullname);
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($fullname);
|
||||
$mform->display();
|
||||
echo $OUTPUT->footer();
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@@ -18,8 +17,7 @@
|
||||
/**
|
||||
* Contains the form used to edit manual enrolments for a user.
|
||||
*
|
||||
* @package enrol
|
||||
* @subpackage manual
|
||||
* @package enrol_manual
|
||||
* @copyright 2011 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@@ -80,4 +78,4 @@ class enrol_manual_user_enrolment_form extends moodleform {
|
||||
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
/**
|
||||
* External course participation api.
|
||||
*
|
||||
@@ -32,7 +31,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
require_once("$CFG->libdir/externallib.php");
|
||||
|
||||
/**
|
||||
* Manual enrolment external functions
|
||||
* Manual enrolment external functions.
|
||||
*
|
||||
* @package enrol_manual
|
||||
* @category external
|
||||
@@ -43,7 +42,7 @@ require_once("$CFG->libdir/externallib.php");
|
||||
class enrol_manual_external extends external_api {
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* Returns description of method parameters.
|
||||
*
|
||||
* @return external_function_parameters
|
||||
* @since Moodle 2.2
|
||||
@@ -68,7 +67,7 @@ class enrol_manual_external extends external_api {
|
||||
}
|
||||
|
||||
/**
|
||||
* Enrolment of users
|
||||
* Enrolment of users.
|
||||
*
|
||||
* Function throw an exception at the first error encountered.
|
||||
* @param array $enrolments An array of user enrolment
|
||||
@@ -82,24 +81,24 @@ class enrol_manual_external extends external_api {
|
||||
$params = self::validate_parameters(self::enrol_users_parameters(),
|
||||
array('enrolments' => $enrolments));
|
||||
|
||||
$transaction = $DB->start_delegated_transaction(); //rollback all enrolment if an error occurs
|
||||
//(except if the DB doesn't support it)
|
||||
$transaction = $DB->start_delegated_transaction(); // Rollback all enrolment if an error occurs
|
||||
// (except if the DB doesn't support it).
|
||||
|
||||
//retrieve the manual enrolment plugin
|
||||
// Retrieve the manual enrolment plugin.
|
||||
$enrol = enrol_get_plugin('manual');
|
||||
if (empty($enrol)) {
|
||||
throw new moodle_exception('manualpluginnotinstalled', 'enrol_manual');
|
||||
}
|
||||
|
||||
foreach ($params['enrolments'] as $enrolment) {
|
||||
// Ensure the current user is allowed to run this function in the enrolment context
|
||||
// Ensure the current user is allowed to run this function in the enrolment context.
|
||||
$context = context_course::instance($enrolment['courseid'], IGNORE_MISSING);
|
||||
self::validate_context($context);
|
||||
|
||||
//check that the user has the permission to manual enrol
|
||||
// Check that the user has the permission to manual enrol.
|
||||
require_capability('enrol/manual:enrol', $context);
|
||||
|
||||
//throw an exception if user is not able to assign the role
|
||||
// Throw an exception if user is not able to assign the role.
|
||||
$roles = get_assignable_roles($context);
|
||||
if (!key_exists($enrolment['roleid'], $roles)) {
|
||||
$errorparams = new stdClass();
|
||||
@@ -109,7 +108,7 @@ class enrol_manual_external extends external_api {
|
||||
throw new moodle_exception('wsusercannotassign', 'enrol_manual', '', $errorparams);
|
||||
}
|
||||
|
||||
//check manual enrolment plugin instance is enabled/exist
|
||||
// Check manual enrolment plugin instance is enabled/exist.
|
||||
$enrolinstances = enrol_get_instances($enrolment['courseid'], true);
|
||||
foreach ($enrolinstances as $courseenrolinstance) {
|
||||
if ($courseenrolinstance->enrol == "manual") {
|
||||
@@ -123,7 +122,7 @@ class enrol_manual_external extends external_api {
|
||||
throw new moodle_exception('wsnoinstance', 'enrol_manual', $errorparams);
|
||||
}
|
||||
|
||||
//check that the plugin accept enrolment (it should always the case, it's hard coded in the plugin)
|
||||
// Check that the plugin accept enrolment (it should always the case, it's hard coded in the plugin).
|
||||
if (!$enrol->allow_enrol($instance)) {
|
||||
$errorparams = new stdClass();
|
||||
$errorparams->roleid = $enrolment['roleid'];
|
||||
@@ -132,7 +131,7 @@ class enrol_manual_external extends external_api {
|
||||
throw new moodle_exception('wscannotenrol', 'enrol_manual', '', $errorparams);
|
||||
}
|
||||
|
||||
//finally proceed the enrolment
|
||||
// Finally proceed the enrolment.
|
||||
$enrolment['timestart'] = isset($enrolment['timestart']) ? $enrolment['timestart'] : 0;
|
||||
$enrolment['timeend'] = isset($enrolment['timeend']) ? $enrolment['timeend'] : 0;
|
||||
$enrolment['status'] = (isset($enrolment['suspend']) && !empty($enrolment['suspend'])) ?
|
||||
@@ -147,7 +146,7 @@ class enrol_manual_external extends external_api {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* Returns description of method result value.
|
||||
*
|
||||
* @return null
|
||||
* @since Moodle 2.2
|
||||
@@ -159,7 +158,7 @@ class enrol_manual_external extends external_api {
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated manual enrolment external functions
|
||||
* Deprecated manual enrolment external functions.
|
||||
*
|
||||
* @package enrol_manual
|
||||
* @copyright 2011 Jerome Mouneyrac
|
||||
@@ -172,7 +171,7 @@ class enrol_manual_external extends external_api {
|
||||
class moodle_enrol_manual_external extends external_api {
|
||||
|
||||
/**
|
||||
* Returns description of method parameters
|
||||
* Returns description of method parameters.
|
||||
*
|
||||
* @return external_function_parameters
|
||||
* @since Moodle 2.0
|
||||
@@ -199,7 +198,7 @@ class moodle_enrol_manual_external extends external_api {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of method result value
|
||||
* Returns description of method result value.
|
||||
*
|
||||
* @return nul
|
||||
* @since Moodle 2.0
|
||||
|
||||
+11
-13
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@@ -18,8 +17,7 @@
|
||||
/**
|
||||
* Manual enrolment plugin main library file.
|
||||
*
|
||||
* @package enrol
|
||||
* @subpackage manual
|
||||
* @package enrol_manual
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@@ -29,22 +27,22 @@ defined('MOODLE_INTERNAL') || die();
|
||||
class enrol_manual_plugin extends enrol_plugin {
|
||||
|
||||
public function roles_protected() {
|
||||
// users may tweak the roles later
|
||||
// Users may tweak the roles later.
|
||||
return false;
|
||||
}
|
||||
|
||||
public function allow_enrol(stdClass $instance) {
|
||||
// users with enrol cap may unenrol other users manually manually
|
||||
// Users with enrol cap may unenrol other users manually manually.
|
||||
return true;
|
||||
}
|
||||
|
||||
public function allow_unenrol(stdClass $instance) {
|
||||
// users with unenrol cap may unenrol other users manually manually
|
||||
// Users with unenrol cap may unenrol other users manually manually.
|
||||
return true;
|
||||
}
|
||||
|
||||
public function allow_manage(stdClass $instance) {
|
||||
// users with manage cap may tweak period and status
|
||||
// Users with manage cap may tweak period and status.
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -52,7 +50,7 @@ class enrol_manual_plugin extends enrol_plugin {
|
||||
* Returns link to manual enrol UI if exists.
|
||||
* Does the access control tests automatically.
|
||||
*
|
||||
* @param object $instance
|
||||
* @param stdClass $instance
|
||||
* @return moodle_url
|
||||
*/
|
||||
public function get_manual_enrol_link($instance) {
|
||||
@@ -96,7 +94,7 @@ class enrol_manual_plugin extends enrol_plugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns edit icons for the page with list of instances
|
||||
* Returns edit icons for the page with list of instances.
|
||||
* @param stdClass $instance
|
||||
* @return array
|
||||
*/
|
||||
@@ -145,7 +143,7 @@ class enrol_manual_plugin extends enrol_plugin {
|
||||
|
||||
/**
|
||||
* Add new instance of enrol plugin with default settings.
|
||||
* @param object $course
|
||||
* @param stdClass $course
|
||||
* @return int id of new instance, null if can not be created
|
||||
*/
|
||||
public function add_default_instance($course) {
|
||||
@@ -155,7 +153,7 @@ class enrol_manual_plugin extends enrol_plugin {
|
||||
|
||||
/**
|
||||
* Add new instance of enrol plugin.
|
||||
* @param object $course
|
||||
* @param stdClass $course
|
||||
* @param array instance fields
|
||||
* @return int id of new instance, null if can not be created
|
||||
*/
|
||||
@@ -260,7 +258,7 @@ class enrol_manual_plugin extends enrol_plugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of the user enrolment actions
|
||||
* Gets an array of the user enrolment actions.
|
||||
*
|
||||
* @param course_enrolment_manager $manager
|
||||
* @param stdClass $ue A user enrolment object
|
||||
@@ -284,7 +282,7 @@ class enrol_manual_plugin extends enrol_plugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* The manual plugin has several bulk operations that can be performed
|
||||
* The manual plugin has several bulk operations that can be performed.
|
||||
* @param course_enrolment_manager $manager
|
||||
* @return array
|
||||
*/
|
||||
|
||||
+110
-14
@@ -17,8 +17,7 @@
|
||||
/**
|
||||
* Auxiliary manual user enrolment lib, the main purpose is to lower memory requirements...
|
||||
*
|
||||
* @package enrol
|
||||
* @subpackage manual
|
||||
* @package enrol_manual
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@@ -30,7 +29,7 @@ require_once($CFG->dirroot . '/enrol/locallib.php');
|
||||
|
||||
|
||||
/**
|
||||
* Enrol candidates
|
||||
* Enrol candidates.
|
||||
*/
|
||||
class enrol_manual_potential_participant extends user_selector_base {
|
||||
protected $enrolid;
|
||||
@@ -42,12 +41,12 @@ class enrol_manual_potential_participant extends user_selector_base {
|
||||
|
||||
/**
|
||||
* Candidate users
|
||||
* @param <type> $search
|
||||
* @param string $search
|
||||
* @return array
|
||||
*/
|
||||
public function find_users($search) {
|
||||
global $DB;
|
||||
//by default wherecondition retrieves all users except the deleted, not confirmed and guest
|
||||
// By default wherecondition retrieves all users except the deleted, not confirmed and guest.
|
||||
list($wherecondition, $params) = $this->search_sql($search, 'u');
|
||||
$params['enrolid'] = $this->enrolid;
|
||||
|
||||
@@ -92,7 +91,7 @@ class enrol_manual_potential_participant extends user_selector_base {
|
||||
}
|
||||
|
||||
/**
|
||||
* Enroled users
|
||||
* Enrolled users.
|
||||
*/
|
||||
class enrol_manual_current_participant extends user_selector_base {
|
||||
protected $courseid;
|
||||
@@ -105,12 +104,12 @@ class enrol_manual_current_participant extends user_selector_base {
|
||||
|
||||
/**
|
||||
* Candidate users
|
||||
* @param <type> $search
|
||||
* @param string $search
|
||||
* @return array
|
||||
*/
|
||||
public function find_users($search) {
|
||||
global $DB;
|
||||
//by default wherecondition retrieves all users except the deleted, not confirmed and guest
|
||||
// By default wherecondition retrieves all users except the deleted, not confirmed and guest.
|
||||
list($wherecondition, $params) = $this->search_sql($search, 'u');
|
||||
$params['enrolid'] = $this->enrolid;
|
||||
|
||||
@@ -182,7 +181,6 @@ class enrol_manual_editselectedusers_operation extends enrol_bulk_enrolment_oper
|
||||
/**
|
||||
* Processes the bulk operation request for the given userids with the provided properties.
|
||||
*
|
||||
* @global moodle_database $DB
|
||||
* @param course_enrolment_manager $manager
|
||||
* @param array $userids
|
||||
* @param stdClass $properties The data returned by the form.
|
||||
@@ -194,7 +192,7 @@ class enrol_manual_editselectedusers_operation extends enrol_bulk_enrolment_oper
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get all of the user enrolment id's
|
||||
// Get all of the user enrolment id's.
|
||||
$ueids = array();
|
||||
$instances = array();
|
||||
foreach ($users as $user) {
|
||||
@@ -237,15 +235,15 @@ class enrol_manual_editselectedusers_operation extends enrol_bulk_enrolment_oper
|
||||
return true;
|
||||
}
|
||||
|
||||
// Update the modifierid
|
||||
// Update the modifierid.
|
||||
$updatesql[] = 'modifierid = :modifierid';
|
||||
$params['modifierid'] = (int)$USER->id;
|
||||
|
||||
// Update the time modified
|
||||
// Update the time modified.
|
||||
$updatesql[] = 'timemodified = :timemodified';
|
||||
$params['timemodified'] = time();
|
||||
|
||||
// Build the SQL statement
|
||||
// Build the SQL statement.
|
||||
$updatesql = join(', ', $updatesql);
|
||||
$sql = "UPDATE {user_enrolments}
|
||||
SET $updatesql
|
||||
@@ -353,4 +351,102 @@ class enrol_manual_deleteselectedusers_operation extends enrol_bulk_enrolment_op
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrates all enrolments of the given plugin to enrol_manual plugin,
|
||||
* this is used for example during plugin uninstallation.
|
||||
*
|
||||
* NOTE: this function does not trigger role and enrolment related events.
|
||||
*
|
||||
* @param string $enrol The enrolment method.
|
||||
*/
|
||||
function enrol_manual_migrate_plugin_enrolments($enrol) {
|
||||
global $DB;
|
||||
|
||||
if ($enrol === 'manual') {
|
||||
// We can not migrate to self.
|
||||
return;
|
||||
}
|
||||
|
||||
$manualplugin = enrol_get_plugin('manual');
|
||||
|
||||
$params = array('enrol'=>$enrol);
|
||||
$sql = "SELECT e.id, e.courseid, e.status, MIN(me.id) AS mid, COUNT(ue.id) AS cu
|
||||
FROM {enrol} e
|
||||
JOIN {user_enrolments} ue ON (ue.enrolid = e.id)
|
||||
JOIN {course} c ON (c.id = e.courseid)
|
||||
LEFT JOIN {enrol} me ON (me.courseid = e.courseid AND me.enrol='manual')
|
||||
WHERE e.enrol = :enrol
|
||||
GROUP BY e.id, e.courseid, e.status
|
||||
ORDER BY e.id";
|
||||
$rs = $DB->get_recordset_sql($sql, $params);
|
||||
|
||||
foreach($rs as $e) {
|
||||
$minstance = false;
|
||||
if (!$e->mid) {
|
||||
// Manual instance does not exist yet, add a new one.
|
||||
$course = $DB->get_record('course', array('id'=>$e->courseid), '*', MUST_EXIST);
|
||||
if ($minstance = $DB->get_record('enrol', array('courseid'=>$course->id, 'enrol'=>'manual'))) {
|
||||
// Already created by previous iteration.
|
||||
$e->mid = $minstance->id;
|
||||
} else if ($e->mid = $manualplugin->add_default_instance($course)) {
|
||||
$minstance = $DB->get_record('enrol', array('id'=>$e->mid));
|
||||
if ($e->status != ENROL_INSTANCE_ENABLED) {
|
||||
$DB->set_field('enrol', 'status', ENROL_INSTANCE_DISABLED, array('id'=>$e->mid));
|
||||
$minstance->status = ENROL_INSTANCE_DISABLED;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$minstance = $DB->get_record('enrol', array('id'=>$e->mid));
|
||||
}
|
||||
|
||||
if (!$minstance) {
|
||||
// This should never happen unless adding of default instance fails unexpectedly.
|
||||
continue;
|
||||
}
|
||||
|
||||
// First delete potential role duplicates.
|
||||
$params = array('id'=>$e->id, 'component'=>'enrol_'.$enrol, 'empty'=>$DB->sql_empty());
|
||||
$sql = "SELECT ra.id
|
||||
FROM {role_assignments} ra
|
||||
JOIN {role_assignments} mra ON (mra.contextid = ra.contextid AND mra.userid = ra.userid AND mra.roleid = ra.roleid AND mra.component = :empty AND mra.itemid = 0)
|
||||
WHERE ra.component = :component AND ra.itemid = :id";
|
||||
$ras = $DB->get_records_sql($sql, $params);
|
||||
$ras = array_keys($ras);
|
||||
$DB->delete_records_list('role_assignments', 'id', $ras);
|
||||
unset($ras);
|
||||
|
||||
// Migrate roles.
|
||||
$sql = "UPDATE {role_assignments}
|
||||
SET itemid = 0, component = :empty
|
||||
WHERE itemid = :id AND component = :component";
|
||||
$params = array('empty'=>$DB->sql_empty(), 'id'=>$e->id, 'component'=>'enrol_'.$enrol);
|
||||
$DB->execute($sql, $params);
|
||||
|
||||
// Delete potential enrol duplicates.
|
||||
$params = array('id'=>$e->id, 'mid'=>$e->mid);
|
||||
$sql = "SELECT ue.id
|
||||
FROM {user_enrolments} ue
|
||||
JOIN {user_enrolments} mue ON (mue.userid = ue.userid AND mue.enrolid = :mid)
|
||||
WHERE ue.enrolid = :id";
|
||||
$ues = $DB->get_records_sql($sql, $params);
|
||||
$ues = array_keys($ues);
|
||||
$DB->delete_records_list('user_enrolments', 'id', $ues);
|
||||
unset($ues);
|
||||
|
||||
// Migrate to manual enrol instance.
|
||||
$params = array('id'=>$e->id, 'mid'=>$e->mid);
|
||||
if ($e->status != ENROL_INSTANCE_ENABLED and $minstance->status == ENROL_INSTANCE_ENABLED) {
|
||||
$status = ", status = :disabled";
|
||||
$params['disabled'] = ENROL_USER_SUSPENDED;
|
||||
} else {
|
||||
$status = "";
|
||||
}
|
||||
$sql = "UPDATE {user_enrolments}
|
||||
SET enrolid = :mid $status
|
||||
WHERE enrolid = :id";
|
||||
$DB->execute($sql, $params);
|
||||
}
|
||||
$rs->close();
|
||||
}
|
||||
|
||||
@@ -17,8 +17,7 @@
|
||||
/**
|
||||
* Manual user enrolment UI.
|
||||
*
|
||||
* @package enrol
|
||||
* @subpackage manual
|
||||
* @package enrol_manual
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@@ -47,7 +46,7 @@ $roles = get_assignable_roles($context);
|
||||
$roles = array('0'=>get_string('none')) + $roles;
|
||||
|
||||
if (!isset($roles[$roleid])) {
|
||||
// weird - security always first!
|
||||
// Weird - security always first!
|
||||
$roleid = 0;
|
||||
}
|
||||
|
||||
@@ -88,14 +87,14 @@ $timeformat = get_string('strftimedatefullshort');
|
||||
$today = time();
|
||||
$today = make_timestamp(date('Y', $today), date('m', $today), date('d', $today), 0, 0, 0);
|
||||
|
||||
// enrolment start
|
||||
// Enrolment start.
|
||||
$basemenu = array();
|
||||
if ($course->startdate > 0) {
|
||||
$basemenu[2] = get_string('coursestart') . ' (' . userdate($course->startdate, $timeformat) . ')';
|
||||
}
|
||||
$basemenu[3] = get_string('today') . ' (' . userdate($today, $timeformat) . ')' ;
|
||||
|
||||
// process add and removes
|
||||
// Process add and removes.
|
||||
if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
|
||||
$userstoassign = $potentialuserselector->get_selected_users();
|
||||
if (!empty($userstoassign)) {
|
||||
@@ -126,7 +125,7 @@ if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
|
||||
}
|
||||
}
|
||||
|
||||
// Process incoming role unassignments
|
||||
// Process incoming role unassignments.
|
||||
if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
|
||||
$userstounassign = $currentuserselector->get_selected_users();
|
||||
if (!empty($userstounassign)) {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@@ -18,8 +17,7 @@
|
||||
/**
|
||||
* Manual enrolment plugin settings and presets.
|
||||
*
|
||||
* @package enrol
|
||||
* @subpackage manual
|
||||
* @package enrol_manual
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@@ -55,4 +53,3 @@ if ($ADMIN->fulltree) {
|
||||
get_string('defaultrole', 'role'), '', $student->id, $options));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Manual enrolment tests.
|
||||
*
|
||||
* @package enrol_manual
|
||||
* @category phpunit
|
||||
* @copyright 2012 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
|
||||
/**
|
||||
* Manual enrolment tests.
|
||||
*
|
||||
* @package enrol_manual
|
||||
* @category phpunit
|
||||
* @copyright 2012 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class enrol_manual_lib_testcase extends advanced_testcase {
|
||||
/**
|
||||
* Test enrol migration function used when uninstalling enrol plugins.
|
||||
*/
|
||||
public function test_migrate_plugin_enrolments() {
|
||||
global $DB, $CFG;
|
||||
require_once($CFG->dirroot.'/enrol/manual/locallib.php');
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$manplugin = enrol_get_plugin('manual');
|
||||
|
||||
// Setup a few courses and users.
|
||||
|
||||
$studentrole = $DB->get_record('role', array('shortname'=>'student'));
|
||||
$this->assertNotEmpty($studentrole);
|
||||
$teacherrole = $DB->get_record('role', array('shortname'=>'teacher'));
|
||||
$this->assertNotEmpty($teacherrole);
|
||||
|
||||
$course1 = $this->getDataGenerator()->create_course();
|
||||
$course2 = $this->getDataGenerator()->create_course();
|
||||
$course3 = $this->getDataGenerator()->create_course();
|
||||
$course4 = $this->getDataGenerator()->create_course();
|
||||
$course5 = $this->getDataGenerator()->create_course();
|
||||
|
||||
$context1 = context_course::instance($course1->id);
|
||||
$context2 = context_course::instance($course2->id);
|
||||
$context3 = context_course::instance($course3->id);
|
||||
$context4 = context_course::instance($course4->id);
|
||||
|
||||
$user1 = $this->getDataGenerator()->create_user();
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
$user3 = $this->getDataGenerator()->create_user();
|
||||
$user4 = $this->getDataGenerator()->create_user();
|
||||
|
||||
// We expect manual, self and guest instances to be created by default.
|
||||
|
||||
$this->assertEquals(5, $DB->count_records('enrol', array('enrol'=>'manual')));
|
||||
$this->assertEquals(5, $DB->count_records('enrol', array('enrol'=>'self')));
|
||||
$this->assertEquals(5, $DB->count_records('enrol', array('enrol'=>'guest')));
|
||||
$this->assertEquals(15, $DB->count_records('enrol', array()));
|
||||
|
||||
$this->assertEquals(0, $DB->count_records('user_enrolments', array()));
|
||||
|
||||
// Enrol some users to manual instances.
|
||||
|
||||
$maninstance1 = $DB->get_record('enrol', array('courseid'=>$course1->id, 'enrol'=>'manual'), '*', MUST_EXIST);
|
||||
$DB->set_field('enrol', 'status', ENROL_INSTANCE_DISABLED, array('id'=>$maninstance1->id));
|
||||
$maninstance1 = $DB->get_record('enrol', array('courseid'=>$course1->id, 'enrol'=>'manual'), '*', MUST_EXIST);
|
||||
$maninstance2 = $DB->get_record('enrol', array('courseid'=>$course2->id, 'enrol'=>'manual'), '*', MUST_EXIST);
|
||||
$DB->delete_records('enrol', array('courseid'=>$course3->id, 'enrol'=>'manual'));
|
||||
$DB->delete_records('enrol', array('courseid'=>$course4->id, 'enrol'=>'manual'));
|
||||
$DB->delete_records('enrol', array('courseid'=>$course5->id, 'enrol'=>'manual'));
|
||||
|
||||
$manplugin->enrol_user($maninstance1, $user1->id, $studentrole->id);
|
||||
$manplugin->enrol_user($maninstance1, $user2->id, $studentrole->id);
|
||||
$manplugin->enrol_user($maninstance1, $user3->id, $teacherrole->id);
|
||||
$manplugin->enrol_user($maninstance2, $user3->id, $teacherrole->id);
|
||||
|
||||
$this->assertEquals(4, $DB->count_records('user_enrolments', array()));
|
||||
|
||||
// Set up some bogus enrol plugin instances and enrolments.
|
||||
|
||||
$xxxinstance1 = $DB->insert_record('enrol', array('courseid'=>$course1->id, 'enrol'=>'xxx', 'status'=>ENROL_INSTANCE_ENABLED));
|
||||
$xxxinstance1 = $DB->get_record('enrol', array('id'=>$xxxinstance1));
|
||||
$xxxinstance3 = $DB->insert_record('enrol', array('courseid'=>$course3->id, 'enrol'=>'xxx', 'status'=>ENROL_INSTANCE_DISABLED));
|
||||
$xxxinstance3 = $DB->get_record('enrol', array('id'=>$xxxinstance3));
|
||||
$xxxinstance4 = $DB->insert_record('enrol', array('courseid'=>$course4->id, 'enrol'=>'xxx', 'status'=>ENROL_INSTANCE_ENABLED));
|
||||
$xxxinstance4 = $DB->get_record('enrol', array('id'=>$xxxinstance4));
|
||||
$xxxinstance4b = $DB->insert_record('enrol', array('courseid'=>$course4->id, 'enrol'=>'xxx', 'status'=>ENROL_INSTANCE_DISABLED));
|
||||
$xxxinstance4b = $DB->get_record('enrol', array('id'=>$xxxinstance4b));
|
||||
|
||||
|
||||
$DB->insert_record('user_enrolments', array('enrolid'=>$xxxinstance1->id, 'userid'=>$user1->id, 'status'=>ENROL_USER_SUSPENDED));
|
||||
role_assign($studentrole->id, $user1->id, $context1->id, 'enrol_xxx', $xxxinstance1->id);
|
||||
role_assign($teacherrole->id, $user1->id, $context1->id, 'enrol_xxx', $xxxinstance1->id);
|
||||
$DB->insert_record('user_enrolments', array('enrolid'=>$xxxinstance1->id, 'userid'=>$user4->id, 'status'=>ENROL_USER_ACTIVE));
|
||||
role_assign($studentrole->id, $user4->id, $context1->id, 'enrol_xxx', $xxxinstance1->id);
|
||||
$this->assertEquals(2, $DB->count_records('user_enrolments', array('enrolid'=>$xxxinstance1->id)));
|
||||
$this->assertEquals(6, $DB->count_records('role_assignments', array('contextid'=>$context1->id)));
|
||||
|
||||
|
||||
$DB->insert_record('user_enrolments', array('enrolid'=>$xxxinstance3->id, 'userid'=>$user1->id, 'status'=>ENROL_USER_ACTIVE));
|
||||
role_assign($studentrole->id, $user1->id, $context3->id, 'enrol_xxx', $xxxinstance3->id);
|
||||
$DB->insert_record('user_enrolments', array('enrolid'=>$xxxinstance3->id, 'userid'=>$user2->id, 'status'=>ENROL_USER_SUSPENDED));
|
||||
$this->assertEquals(2, $DB->count_records('user_enrolments', array('enrolid'=>$xxxinstance3->id)));
|
||||
$this->assertEquals(1, $DB->count_records('role_assignments', array('contextid'=>$context3->id)));
|
||||
|
||||
$DB->insert_record('user_enrolments', array('enrolid'=>$xxxinstance4->id, 'userid'=>$user1->id, 'status'=>ENROL_USER_ACTIVE));
|
||||
role_assign($studentrole->id, $user1->id, $context4->id, 'enrol_xxx', $xxxinstance4->id);
|
||||
$DB->insert_record('user_enrolments', array('enrolid'=>$xxxinstance4->id, 'userid'=>$user2->id, 'status'=>ENROL_USER_ACTIVE));
|
||||
role_assign($studentrole->id, $user2->id, $context4->id, 'enrol_xxx', $xxxinstance4->id);
|
||||
$DB->insert_record('user_enrolments', array('enrolid'=>$xxxinstance4b->id, 'userid'=>$user1->id, 'status'=>ENROL_USER_SUSPENDED));
|
||||
role_assign($teacherrole->id, $user1->id, $context4->id, 'enrol_xxx', $xxxinstance4b->id);
|
||||
$DB->insert_record('user_enrolments', array('enrolid'=>$xxxinstance4b->id, 'userid'=>$user4->id, 'status'=>ENROL_USER_ACTIVE));
|
||||
role_assign($teacherrole->id, $user4->id, $context4->id, 'enrol_xxx', $xxxinstance4b->id);
|
||||
$this->assertEquals(2, $DB->count_records('user_enrolments', array('enrolid'=>$xxxinstance4->id)));
|
||||
$this->assertEquals(2, $DB->count_records('user_enrolments', array('enrolid'=>$xxxinstance4b->id)));
|
||||
$this->assertEquals(4, $DB->count_records('role_assignments', array('contextid'=>$context4->id)));
|
||||
|
||||
// Finally do the migration.
|
||||
|
||||
enrol_manual_migrate_plugin_enrolments('xxx');
|
||||
|
||||
// Verify results.
|
||||
|
||||
$this->assertEquals(1, $DB->count_records('enrol', array('courseid'=>$course1->id, 'enrol'=>'manual')));
|
||||
$this->assertEquals(1, $DB->count_records('enrol', array('courseid'=>$course1->id, 'enrol'=>'xxx')));
|
||||
$maninstance1 = $DB->get_record('enrol', array('courseid'=>$course1->id, 'enrol'=>'manual'), '*', MUST_EXIST);
|
||||
$this->assertEquals(ENROL_INSTANCE_DISABLED, $maninstance1->status);
|
||||
$this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$maninstance1->id, 'userid'=>$user1->id, 'status'=>ENROL_USER_ACTIVE)));
|
||||
$this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$maninstance1->id, 'userid'=>$user2->id, 'status'=>ENROL_USER_ACTIVE)));
|
||||
$this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$maninstance1->id, 'userid'=>$user3->id, 'status'=>ENROL_USER_ACTIVE)));
|
||||
$this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$maninstance1->id, 'userid'=>$user4->id, 'status'=>ENROL_USER_ACTIVE)));
|
||||
$this->assertEquals(4, $DB->count_records('user_enrolments', array('enrolid'=>$maninstance1->id)));
|
||||
$this->assertEquals(0, $DB->count_records('user_enrolments', array('enrolid'=>$xxxinstance1->id)));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>$DB->sql_empty(), 'userid'=>$user1->id, 'roleid'=>$studentrole->id, 'contextid'=>$context1->id)));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>$DB->sql_empty(), 'userid'=>$user1->id, 'roleid'=>$teacherrole->id, 'contextid'=>$context1->id)));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>$DB->sql_empty(), 'userid'=>$user2->id, 'roleid'=>$studentrole->id, 'contextid'=>$context1->id)));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>$DB->sql_empty(), 'userid'=>$user3->id, 'roleid'=>$teacherrole->id, 'contextid'=>$context1->id)));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>$DB->sql_empty(), 'userid'=>$user4->id, 'roleid'=>$studentrole->id, 'contextid'=>$context1->id)));
|
||||
$this->assertEquals(5, $DB->count_records('role_assignments', array('contextid'=>$context1->id)));
|
||||
|
||||
|
||||
$this->assertEquals(1, $DB->count_records('enrol', array('courseid'=>$course2->id, 'enrol'=>'manual')));
|
||||
$this->assertEquals(0, $DB->count_records('enrol', array('courseid'=>$course2->id, 'enrol'=>'xxx')));
|
||||
$maninstance2 = $DB->get_record('enrol', array('courseid'=>$course2->id, 'enrol'=>'manual'), '*', MUST_EXIST);
|
||||
$this->assertEquals(ENROL_INSTANCE_ENABLED, $maninstance2->status);
|
||||
|
||||
|
||||
$this->assertEquals(1, $DB->count_records('enrol', array('courseid'=>$course3->id, 'enrol'=>'manual')));
|
||||
$this->assertEquals(1, $DB->count_records('enrol', array('courseid'=>$course3->id, 'enrol'=>'xxx')));
|
||||
$maninstance3 = $DB->get_record('enrol', array('courseid'=>$course3->id, 'enrol'=>'manual'), '*', MUST_EXIST);
|
||||
$this->assertEquals(ENROL_INSTANCE_DISABLED, $maninstance3->status);
|
||||
$this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$maninstance3->id, 'userid'=>$user1->id, 'status'=>ENROL_USER_ACTIVE)));
|
||||
$this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$maninstance3->id, 'userid'=>$user2->id, 'status'=>ENROL_USER_SUSPENDED)));
|
||||
$this->assertEquals(2, $DB->count_records('user_enrolments', array('enrolid'=>$maninstance3->id)));
|
||||
$this->assertEquals(0, $DB->count_records('user_enrolments', array('enrolid'=>$xxxinstance3->id)));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>$DB->sql_empty(), 'userid'=>$user1->id, 'roleid'=>$studentrole->id, 'contextid'=>$context3->id)));
|
||||
$this->assertEquals(1, $DB->count_records('role_assignments', array('contextid'=>$context3->id)));
|
||||
|
||||
|
||||
$this->assertEquals(1, $DB->count_records('enrol', array('courseid'=>$course4->id, 'enrol'=>'manual')));
|
||||
$this->assertEquals(2, $DB->count_records('enrol', array('courseid'=>$course4->id, 'enrol'=>'xxx')));
|
||||
$maninstance4 = $DB->get_record('enrol', array('courseid'=>$course4->id, 'enrol'=>'manual'), '*', MUST_EXIST);
|
||||
$this->assertEquals(ENROL_INSTANCE_ENABLED, $maninstance4->status);
|
||||
$this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$maninstance4->id, 'userid'=>$user1->id, 'status'=>ENROL_USER_ACTIVE)));
|
||||
$this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$maninstance4->id, 'userid'=>$user2->id, 'status'=>ENROL_USER_ACTIVE)));
|
||||
$this->assertTrue($DB->record_exists('user_enrolments', array('enrolid'=>$maninstance4->id, 'userid'=>$user4->id, 'status'=>ENROL_USER_SUSPENDED)));
|
||||
$this->assertEquals(3, $DB->count_records('user_enrolments', array('enrolid'=>$maninstance4->id)));
|
||||
$this->assertEquals(0, $DB->count_records('user_enrolments', array('enrolid'=>$xxxinstance4->id)));
|
||||
$this->assertEquals(0, $DB->count_records('user_enrolments', array('enrolid'=>$xxxinstance4b->id)));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>$DB->sql_empty(), 'userid'=>$user1->id, 'roleid'=>$studentrole->id, 'contextid'=>$context4->id)));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>$DB->sql_empty(), 'userid'=>$user1->id, 'roleid'=>$teacherrole->id, 'contextid'=>$context4->id)));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>$DB->sql_empty(), 'userid'=>$user2->id, 'roleid'=>$studentrole->id, 'contextid'=>$context4->id)));
|
||||
$this->assertTrue($DB->record_exists('role_assignments', array('itemid'=>0, 'component'=>$DB->sql_empty(), 'userid'=>$user4->id, 'roleid'=>$teacherrole->id, 'contextid'=>$context4->id)));
|
||||
$this->assertEquals(4, $DB->count_records('role_assignments', array('contextid'=>$context4->id)));
|
||||
|
||||
|
||||
$this->assertEquals(0, $DB->count_records('enrol', array('courseid'=>$course5->id, 'enrol'=>'manual')));
|
||||
$this->assertEquals(0, $DB->count_records('enrol', array('courseid'=>$course5->id, 'enrol'=>'xxx')));
|
||||
|
||||
// Make sure wrong params do not produce errors or notices.
|
||||
|
||||
enrol_manual_migrate_plugin_enrolments('manual');
|
||||
enrol_manual_migrate_plugin_enrolments('yyyy');
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@@ -18,8 +17,7 @@
|
||||
/**
|
||||
* Manual enrolment plugin - support for user self unenrolment.
|
||||
*
|
||||
* @package enrol
|
||||
* @subpackage manual
|
||||
* @package enrol_manual
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@@ -41,7 +39,7 @@ require_login($course);
|
||||
|
||||
$plugin = enrol_get_plugin('manual');
|
||||
|
||||
// security defined inside following function
|
||||
// Security defined inside following function.
|
||||
if (!$plugin->get_unenrolself_link($instance)) {
|
||||
redirect(new moodle_url('/course/view.php', array('id'=>$course->id)));
|
||||
}
|
||||
@@ -51,7 +49,7 @@ $PAGE->set_title($plugin->get_instance_name($instance));
|
||||
|
||||
if ($confirm and confirm_sesskey()) {
|
||||
$plugin->unenrol_user($instance, $USER->id);
|
||||
add_to_log($course->id, 'course', 'unenrol', '../enrol/users.php?id='.$course->id, $course->id); //there should be userid somewhere!
|
||||
add_to_log($course->id, 'course', 'unenrol', '../enrol/users.php?id='.$course->id, $course->id); //TODO: there should be userid somewhere!
|
||||
redirect(new moodle_url('/index.php'));
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,7 @@
|
||||
/**
|
||||
* Manual enrolment plugin version specification.
|
||||
*
|
||||
* @package enrol
|
||||
* @subpackage manual
|
||||
* @package enrol_manual
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
+1
-1
@@ -449,7 +449,7 @@ class course_enrolment_table extends html_table implements renderable {
|
||||
|
||||
// Collect the bulk operations for the currently filtered plugin if there is one.
|
||||
$plugin = $manager->get_filtered_enrolment_plugin();
|
||||
if ($plugin) {
|
||||
if ($plugin and enrol_is_enabled($plugin->get_name())) {
|
||||
$this->bulkoperations = $plugin->get_bulk_operations($manager);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$capabilities = array(
|
||||
|
||||
/* Add or edit enrol-self instance in course. */
|
||||
'enrol/self:config' => array(
|
||||
|
||||
'captype' => 'write',
|
||||
@@ -36,6 +37,7 @@ $capabilities = array(
|
||||
)
|
||||
),
|
||||
|
||||
/* Manage user self-enrolments. */
|
||||
'enrol/self:manage' => array(
|
||||
|
||||
'captype' => 'write',
|
||||
@@ -46,6 +48,7 @@ $capabilities = array(
|
||||
)
|
||||
),
|
||||
|
||||
/* Voluntarily unenrol self from course - watch out for data loss. */
|
||||
'enrol/self:unenrolself' => array(
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_COURSE,
|
||||
@@ -54,6 +57,7 @@ $capabilities = array(
|
||||
)
|
||||
),
|
||||
|
||||
/* Unenrol anybody from course (including self) - watch out for data loss. */
|
||||
'enrol/self:unenrol' => array(
|
||||
'captype' => 'write',
|
||||
'contextlevel' => CONTEXT_COURSE,
|
||||
@@ -64,5 +68,3 @@ $capabilities = array(
|
||||
),
|
||||
|
||||
);
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@@ -18,8 +17,7 @@
|
||||
/**
|
||||
* Self enrol plugin installation script
|
||||
*
|
||||
* @package enrol
|
||||
* @subpackage self
|
||||
* @package enrol_self
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
+8
-8
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@@ -19,8 +18,7 @@
|
||||
* Adds new instance of enrol_self to specified course
|
||||
* or edits current instance.
|
||||
*
|
||||
* @package enrol
|
||||
* @subpackage self
|
||||
* @package enrol_self
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@@ -29,7 +27,7 @@ require('../../config.php');
|
||||
require_once('edit_form.php');
|
||||
|
||||
$courseid = required_param('courseid', PARAM_INT);
|
||||
$instanceid = optional_param('id', 0, PARAM_INT); // instanceid
|
||||
$instanceid = optional_param('id', 0, PARAM_INT);
|
||||
|
||||
$course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
|
||||
$context = context_course::instance($course->id, MUST_EXIST);
|
||||
@@ -51,11 +49,12 @@ if ($instanceid) {
|
||||
$instance = $DB->get_record('enrol', array('courseid'=>$course->id, 'enrol'=>'self', 'id'=>$instanceid), '*', MUST_EXIST);
|
||||
} else {
|
||||
require_capability('moodle/course:enrolconfig', $context);
|
||||
// no instance yet, we have to add new instance
|
||||
// No instance yet, we have to add new instance.
|
||||
navigation_node::override_active_url(new moodle_url('/enrol/instances.php', array('id'=>$course->id)));
|
||||
$instance = new stdClass();
|
||||
$instance->id = null;
|
||||
$instance->courseid = $course->id;
|
||||
$instance->id = null;
|
||||
$instance->courseid = $course->id;
|
||||
$instance->customint5 = 0;
|
||||
}
|
||||
|
||||
$mform = new enrol_self_edit_form(NULL, array($instance, $plugin, $context));
|
||||
@@ -74,6 +73,7 @@ if ($mform->is_cancelled()) {
|
||||
$instance->customint2 = $data->customint2;
|
||||
$instance->customint3 = $data->customint3;
|
||||
$instance->customint4 = $data->customint4;
|
||||
$instance->customint5 = $data->customint5;
|
||||
$instance->customtext1 = $data->customtext1;
|
||||
$instance->roleid = $data->roleid;
|
||||
$instance->enrolperiod = $data->enrolperiod;
|
||||
@@ -88,7 +88,7 @@ if ($mform->is_cancelled()) {
|
||||
|
||||
} else {
|
||||
$fields = array('status'=>$data->status, 'name'=>$data->name, 'password'=>$data->password, 'customint1'=>$data->customint1, 'customint2'=>$data->customint2,
|
||||
'customint3'=>$data->customint3, 'customint4'=>$data->customint4, 'customtext1'=>$data->customtext1,
|
||||
'customint3'=>$data->customint3, 'customint4'=>$data->customint4, 'customint5'=>$data->customint5, 'customtext1'=>$data->customtext1,
|
||||
'roleid'=>$data->roleid, 'enrolperiod'=>$data->enrolperiod, 'enrolstartdate'=>$data->enrolstartdate, 'enrolenddate'=>$data->enrolenddate);
|
||||
$plugin->add_instance($course, $fields);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@@ -19,8 +18,7 @@
|
||||
* Adds new instance of enrol_self to specified course
|
||||
* or edits current instance.
|
||||
*
|
||||
* @package enrol
|
||||
* @subpackage self
|
||||
* @package enrol_self
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@@ -32,6 +30,8 @@ require_once($CFG->libdir.'/formslib.php');
|
||||
class enrol_self_edit_form extends moodleform {
|
||||
|
||||
function definition() {
|
||||
global $DB;
|
||||
|
||||
$mform = $this->_form;
|
||||
|
||||
list($instance, $plugin, $context) = $this->_customdata;
|
||||
@@ -100,6 +100,38 @@ class enrol_self_edit_form extends moodleform {
|
||||
$mform->addHelpButton('customint3', 'maxenrolled', 'enrol_self');
|
||||
$mform->setType('customint3', PARAM_INT);
|
||||
|
||||
$cohorts = array(0 => get_string('no'));
|
||||
list($sqlparents, $params) = $DB->get_in_or_equal($context->get_parent_context_ids(), SQL_PARAMS_NAMED);
|
||||
$params['current'] = $instance->customint5;
|
||||
$sql = "SELECT id, name, idnumber, contextid
|
||||
FROM {cohort}
|
||||
WHERE contextid $sqlparents OR id = :current
|
||||
ORDER BY name ASC, idnumber ASC";
|
||||
$rs = $DB->get_recordset_sql($sql, $params);
|
||||
foreach ($rs as $c) {
|
||||
$ccontext = context::instance_by_id($c->contextid);
|
||||
if ($c->id != $instance->customint5 and !has_capability('moodle/cohort:view', $ccontext)) {
|
||||
continue;
|
||||
}
|
||||
$cohorts[$c->id] = format_string($c->name, true, array('context'=>$context));
|
||||
if ($c->idnumber) {
|
||||
$cohorts[$c->id] .= ' ['.s($c->idnumber).']';
|
||||
}
|
||||
}
|
||||
if (!isset($cohorts[$instance->customint5])) {
|
||||
// Somebody deleted a cohort, better keep the wrong value so that random ppl can not enrol.
|
||||
$cohorts[$instance->customint5] = get_string('unknowncohort', 'cohort', $instance->customint5);
|
||||
}
|
||||
$rs->close();
|
||||
if (count($cohorts) > 1) {
|
||||
$mform->addElement('select', 'customint5', get_string('cohortonly', 'enrol_self'), $cohorts);
|
||||
$mform->addHelpButton('customint5', 'cohortonly', 'enrol_self');
|
||||
} else {
|
||||
$mform->addElement('hidden', 'customint5');
|
||||
$mform->setType('customint5', PARAM_INT);
|
||||
$mform->setConstant('customint5', 0);
|
||||
}
|
||||
|
||||
$mform->addElement('advcheckbox', 'customint4', get_string('sendcoursewelcomemessage', 'enrol_self'));
|
||||
$mform->setDefault('customint4', $plugin->get_config('sendcoursewelcomemessage'));
|
||||
$mform->addHelpButton('customint4', 'sendcoursewelcomemessage', 'enrol_self');
|
||||
@@ -159,7 +191,7 @@ class enrol_self_edit_form extends moodleform {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of roles that this user can assign for the course as the default for self-enrolment
|
||||
* Gets a list of roles that this user can assign for the course as the default for self-enrolment.
|
||||
*
|
||||
* @param context $context the context.
|
||||
* @param integer $defaultrole the id of the role that is set as the default for self-enrolment
|
||||
|
||||
@@ -20,48 +20,49 @@
|
||||
* This page allows the current user to edit a self user enrolment.
|
||||
* It is not compatible with the frontpage.
|
||||
*
|
||||
* @package enrol
|
||||
* @subpackage self
|
||||
* @package enrol_self
|
||||
* @copyright 2011 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require('../../config.php');
|
||||
require_once("$CFG->dirroot/enrol/locallib.php"); // Required for the course enrolment manager
|
||||
require_once("$CFG->dirroot/enrol/renderer.php"); // Required for the course enrolment users table
|
||||
require_once("$CFG->dirroot/enrol/self/editenrolment_form.php"); // Forms for this page
|
||||
require_once("$CFG->dirroot/enrol/locallib.php"); // Required for the course enrolment manager.
|
||||
require_once("$CFG->dirroot/enrol/renderer.php"); // Required for the course enrolment users table.
|
||||
require_once("$CFG->dirroot/enrol/self/editenrolment_form.php"); // Forms for this page.
|
||||
|
||||
$ueid = required_param('ue', PARAM_INT); // user enrolment id
|
||||
$filter = optional_param('ifilter', 0, PARAM_INT); // table filter for return url
|
||||
$ueid = required_param('ue', PARAM_INT);
|
||||
$filter = optional_param('ifilter', 0, PARAM_INT); // Table filter for return url.
|
||||
|
||||
// Get the user enrolment object
|
||||
$ue = $DB->get_record('user_enrolments', array('id' => $ueid), '*', MUST_EXIST);
|
||||
// Get the user for whom the enrolment is
|
||||
$user = $DB->get_record('user', array('id'=>$ue->userid), '*', MUST_EXIST);
|
||||
// Get the course the enrolment is to
|
||||
list($ctxsql, $ctxjoin) = context_instance_preload_sql('c.id', CONTEXT_COURSE, 'ctx');
|
||||
$sql = "SELECT c.* $ctxsql
|
||||
// Get the user enrolment object.
|
||||
$ue = $DB->get_record('user_enrolments', array('id' => $ueid), '*', MUST_EXIST);
|
||||
// Get the user for whom the enrolment is.
|
||||
$user = $DB->get_record('user', array('id'=>$ue->userid), '*', MUST_EXIST);
|
||||
// Get the course the enrolment is to.
|
||||
$sql = "SELECT c.*
|
||||
FROM {course} c
|
||||
LEFT JOIN {enrol} e ON e.courseid = c.id
|
||||
$ctxjoin
|
||||
JOIN {enrol} e ON e.courseid = c.id
|
||||
WHERE e.id = :enrolid";
|
||||
$params = array('enrolid' => $ue->enrolid);
|
||||
$course = $DB->get_record_sql($sql, $params, MUST_EXIST);
|
||||
context_instance_preload($course);
|
||||
|
||||
// Make sure the course isn't the front page
|
||||
// Make sure the course isn't the front page.
|
||||
if ($course->id == SITEID) {
|
||||
redirect(new moodle_url('/'));
|
||||
}
|
||||
|
||||
// Obvioulsy
|
||||
// Do not allow any changes if plugin disabled.
|
||||
if (!enrol_is_enabled('self')) {
|
||||
redirect(new moodle_url('/course/view.php', array('id'=>$course->id)));
|
||||
}
|
||||
|
||||
// Obviously.
|
||||
require_login($course);
|
||||
// The user must be able to manage self enrolments within the course
|
||||
// The user must be able to manage self enrolments within the course.
|
||||
require_capability("enrol/self:manage", context_course::instance($course->id, MUST_EXIST));
|
||||
|
||||
// Get the enrolment manager for this course
|
||||
// Get the enrolment manager for this course.
|
||||
$manager = new course_enrolment_manager($PAGE, $course, $filter);
|
||||
// Get an enrolment users table object. Doign this will automatically retrieve the the URL params
|
||||
// Get an enrolment users table object. Doing this will automatically retrieve the the URL params
|
||||
// relating to table the user was viewing before coming here, and allows us to return the user to the
|
||||
// exact page of the users screen they can from.
|
||||
$table = new course_enrolment_users_table($manager, $PAGE);
|
||||
@@ -70,30 +71,28 @@ $table = new course_enrolment_users_table($manager, $PAGE);
|
||||
$usersurl = new moodle_url('/enrol/users.php', array('id' => $course->id));
|
||||
// The URl to return the user too after this screen.
|
||||
$returnurl = new moodle_url($usersurl, $manager->get_url_params()+$table->get_url_params());
|
||||
// The URL of this page
|
||||
// The URL of this page.
|
||||
$url = new moodle_url('/enrol/self/editenrolment.php', $returnurl->params());
|
||||
|
||||
$PAGE->set_url($url);
|
||||
$PAGE->set_pagelayout('admin');
|
||||
navigation_node::override_active_url($usersurl);
|
||||
|
||||
// Gets the compontents of the user enrolment
|
||||
// Gets the components of the user enrolment.
|
||||
list($instance, $plugin) = $manager->get_user_enrolment_components($ue);
|
||||
// Check that the user can manage this instance, and that the instance is of the correct type
|
||||
// Check that the user can manage this instance, and that the instance is of the correct type.
|
||||
if (!$plugin->allow_manage($instance) || $instance->enrol != 'self' || !($plugin instanceof enrol_self_plugin)) {
|
||||
print_error('erroreditenrolment', 'enrol');
|
||||
}
|
||||
|
||||
// Get the self enrolment edit form
|
||||
// Get the self enrolment edit form.
|
||||
$mform = new enrol_self_user_enrolment_form($url, array('user'=>$user, 'course'=>$course, 'ue'=>$ue));
|
||||
$mform->set_data($PAGE->url->params());
|
||||
|
||||
// Check the form hasn't been cancelled
|
||||
if ($mform->is_cancelled()) {
|
||||
redirect($returnurl);
|
||||
} else if ($mform->is_submitted() && $mform->is_validated() && confirm_sesskey()) {
|
||||
// The forms been submit, validated and the sesskey has been checked ... edit the enrolment.
|
||||
$data = $mform->get_data();
|
||||
|
||||
} else if ($data = $mform->get_data()) {
|
||||
if ($manager->edit_enrolment($ue, $data)) {
|
||||
redirect($returnurl);
|
||||
}
|
||||
@@ -110,4 +109,4 @@ $PAGE->navbar->add($fullname);
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($fullname);
|
||||
$mform->display();
|
||||
echo $OUTPUT->footer();
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@@ -18,8 +17,7 @@
|
||||
/**
|
||||
* Contains the form used to edit self enrolments for a user.
|
||||
*
|
||||
* @package enrol
|
||||
* @subpackage self
|
||||
* @package enrol_self
|
||||
* @copyright 2011 Sam Hemelryk
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@@ -80,4 +78,4 @@ class enrol_self_user_enrolment_form extends moodleform {
|
||||
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@@ -16,14 +15,16 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Strings for component 'enrol_self', language 'en', branch 'MOODLE_20_STABLE'
|
||||
* Strings for component 'enrol_self', language 'en'.
|
||||
*
|
||||
* @package enrol
|
||||
* @subpackage self
|
||||
* @package enrol_self
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['cohortnonmemberinfo'] = 'Only members of cohort \'{$a}\' can self-enrol.';
|
||||
$string['cohortonly'] = 'Only cohort members';
|
||||
$string['cohortonly_help'] = 'Self enrolment may be restricted to members of a specified cohort only. Note that changing this setting has no effect on existing enrolments.';
|
||||
$string['customwelcomemessage'] = 'Custom welcome message';
|
||||
$string['customwelcomemessage_help'] = 'A custom welcome message may be added as plain text or Moodle-auto format, including HTML tags and multi-lang tags.
|
||||
|
||||
|
||||
+46
-25
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@@ -18,8 +17,7 @@
|
||||
/**
|
||||
* Self enrolment plugin.
|
||||
*
|
||||
* @package enrol
|
||||
* @subpackage self
|
||||
* @package enrol_self
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@@ -66,7 +64,7 @@ class enrol_self_plugin extends enrol_plugin {
|
||||
/**
|
||||
* Returns localised name of enrol instance
|
||||
*
|
||||
* @param object $instance (null is accepted too)
|
||||
* @param stdClass $instance (null is accepted too)
|
||||
* @return string
|
||||
*/
|
||||
public function get_instance_name($instance) {
|
||||
@@ -86,28 +84,38 @@ class enrol_self_plugin extends enrol_plugin {
|
||||
}
|
||||
|
||||
public function roles_protected() {
|
||||
// users may tweak the roles later
|
||||
// Users may tweak the roles later.
|
||||
return false;
|
||||
}
|
||||
|
||||
public function allow_unenrol(stdClass $instance) {
|
||||
// users with unenrol cap may unenrol other users manually manually
|
||||
// Users with unenrol cap may unenrol other users manually manually.
|
||||
return true;
|
||||
}
|
||||
|
||||
public function allow_manage(stdClass $instance) {
|
||||
// users with manage cap may tweak period and status
|
||||
// Users with manage cap may tweak period and status.
|
||||
return true;
|
||||
}
|
||||
|
||||
public function show_enrolme_link(stdClass $instance) {
|
||||
return ($instance->status == ENROL_INSTANCE_ENABLED);
|
||||
global $CFG, $USER;
|
||||
|
||||
if ($instance->status != ENROL_INSTANCE_ENABLED) {
|
||||
return false;
|
||||
}
|
||||
if ($instance->customint5) {
|
||||
require_once("$CFG->dirroot/cohort/lib.php");
|
||||
return cohort_is_member($instance->customint5, $USER->id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up navigation entries.
|
||||
*
|
||||
* @param object $instance
|
||||
* @param stdClass $instancesnode
|
||||
* @param stdClass $instance
|
||||
* @return void
|
||||
*/
|
||||
public function add_course_navigation($instancesnode, stdClass $instance) {
|
||||
@@ -156,7 +164,7 @@ class enrol_self_plugin extends enrol_plugin {
|
||||
if (!has_capability('moodle/course:enrolconfig', $context) or !has_capability('enrol/self:config', $context)) {
|
||||
return NULL;
|
||||
}
|
||||
// multiple instances supported - different roles with different password
|
||||
// Multiple instances supported - different roles with different password.
|
||||
return new moodle_url('/enrol/self/edit.php', array('courseid'=>$courseid));
|
||||
}
|
||||
|
||||
@@ -171,7 +179,7 @@ class enrol_self_plugin extends enrol_plugin {
|
||||
global $CFG, $OUTPUT, $SESSION, $USER, $DB;
|
||||
|
||||
if (isguestuser()) {
|
||||
// can not enrol guest!!
|
||||
// Can not enrol guest!!
|
||||
return null;
|
||||
}
|
||||
if ($DB->record_exists('user_enrolments', array('userid'=>$USER->id, 'enrolid'=>$instance->id))) {
|
||||
@@ -189,6 +197,18 @@ class enrol_self_plugin extends enrol_plugin {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($instance->customint5) {
|
||||
require_once("$CFG->dirroot/cohort/lib.php");
|
||||
if (!cohort_is_member($instance->customint5, $USER->id)) {
|
||||
$cohort = $DB->get_record('cohort', array('id'=>$instance->customint5));
|
||||
if (!$cohort) {
|
||||
return null;
|
||||
}
|
||||
$a = format_string($cohort->name, true, array('context'=>context::instance_by_id($cohort->contextid)));
|
||||
return $OUTPUT->box(markdown_to_html(get_string('cohortnonmemberinfo', 'enrol_self', $a)));
|
||||
}
|
||||
}
|
||||
|
||||
require_once("$CFG->dirroot/enrol/self/locallib.php");
|
||||
require_once("$CFG->dirroot/group/lib.php");
|
||||
|
||||
@@ -206,7 +226,7 @@ class enrol_self_plugin extends enrol_plugin {
|
||||
}
|
||||
|
||||
$this->enrol_user($instance, $USER->id, $instance->roleid, $timestart, $timeend);
|
||||
add_to_log($instance->courseid, 'course', 'enrol', '../enrol/users.php?id='.$instance->courseid, $instance->courseid); //there should be userid somewhere!
|
||||
add_to_log($instance->courseid, 'course', 'enrol', '../enrol/users.php?id='.$instance->courseid, $instance->courseid); //TODO: There should be userid somewhere!
|
||||
|
||||
if ($instance->password and $instance->customint1 and $data->enrolpassword !== $instance->password) {
|
||||
// it must be a group enrolment, let's assign group too
|
||||
@@ -221,7 +241,7 @@ class enrol_self_plugin extends enrol_plugin {
|
||||
}
|
||||
}
|
||||
}
|
||||
// send welcome
|
||||
// Send welcome message.
|
||||
if ($instance->customint4) {
|
||||
$this->email_welcome_message($instance, $USER);
|
||||
}
|
||||
@@ -237,7 +257,7 @@ class enrol_self_plugin extends enrol_plugin {
|
||||
|
||||
/**
|
||||
* Add new instance of enrol plugin with default settings.
|
||||
* @param object $course
|
||||
* @param stdClass $course
|
||||
* @return int id of new instance
|
||||
*/
|
||||
public function add_default_instance($course) {
|
||||
@@ -245,6 +265,7 @@ class enrol_self_plugin extends enrol_plugin {
|
||||
'customint2' => $this->get_config('longtimenosee'),
|
||||
'customint3' => $this->get_config('maxenrolled'),
|
||||
'customint4' => $this->get_config('sendcoursewelcomemessage'),
|
||||
'customint5' => 0,
|
||||
'enrolperiod' => $this->get_config('enrolperiod', 0),
|
||||
'status' => $this->get_config('status'),
|
||||
'roleid' => $this->get_config('roleid', 0));
|
||||
@@ -257,10 +278,10 @@ class enrol_self_plugin extends enrol_plugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* Send welcome email to specified user
|
||||
* Send welcome email to specified user.
|
||||
*
|
||||
* @param object $instance
|
||||
* @param object $user user record
|
||||
* @param stdClass $instance
|
||||
* @param stdClass $user user record
|
||||
* @return void
|
||||
*/
|
||||
protected function email_welcome_message($instance, $user) {
|
||||
@@ -304,12 +325,12 @@ class enrol_self_plugin extends enrol_plugin {
|
||||
$contact = generate_email_supportuser();
|
||||
}
|
||||
|
||||
//directly emailing welcome message rather than using messaging
|
||||
// Directly emailing welcome message rather than using messaging.
|
||||
email_to_user($user, $contact, $subject, $messagetext, $messagehtml);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enrol self cron support
|
||||
* Enrol self cron support.
|
||||
* @return void
|
||||
*/
|
||||
public function cron() {
|
||||
@@ -323,10 +344,10 @@ class enrol_self_plugin extends enrol_plugin {
|
||||
|
||||
$now = time();
|
||||
|
||||
//note: the logic of self enrolment guarantees that user logged in at least once (=== u.lastaccess set)
|
||||
// and that user accessed course at least once too (=== user_lastaccess record exists)
|
||||
// Note: the logic of self enrolment guarantees that user logged in at least once (=== u.lastaccess set)
|
||||
// and that user accessed course at least once too (=== user_lastaccess record exists).
|
||||
|
||||
// first deal with users that did not log in for a really long time
|
||||
// First deal with users that did not log in for a really long time.
|
||||
$sql = "SELECT e.*, ue.userid
|
||||
FROM {user_enrolments} ue
|
||||
JOIN {enrol} e ON (e.id = ue.enrolid AND e.enrol = 'self' AND e.customint2 > 0)
|
||||
@@ -341,7 +362,7 @@ class enrol_self_plugin extends enrol_plugin {
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
// now unenrol from course user did not visit for a long time
|
||||
// Now unenrol from course user did not visit for a long time.
|
||||
$sql = "SELECT e.*, ue.userid
|
||||
FROM {user_enrolments} ue
|
||||
JOIN {enrol} e ON (e.id = ue.enrolid AND e.enrol = 'self' AND e.customint2 > 0)
|
||||
@@ -360,7 +381,7 @@ class enrol_self_plugin extends enrol_plugin {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of the user enrolment actions
|
||||
* Gets an array of the user enrolment actions.
|
||||
*
|
||||
* @param course_enrolment_manager $manager
|
||||
* @param stdClass $ue A user enrolment object
|
||||
@@ -388,7 +409,7 @@ class enrol_self_plugin extends enrol_plugin {
|
||||
* Indicates API features that the enrol plugin supports.
|
||||
*
|
||||
* @param string $feature
|
||||
* @return mixed True if yes (some features may use other values)
|
||||
* @return mixed true if yes (some features may use other values)
|
||||
*/
|
||||
function enrol_self_supports($feature) {
|
||||
switch($feature) {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@@ -18,8 +17,7 @@
|
||||
/**
|
||||
* Self enrol plugin implementation.
|
||||
*
|
||||
* @package enrol
|
||||
* @subpackage self
|
||||
* @package enrol_self
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@@ -33,7 +31,7 @@ class enrol_self_enrol_form extends moodleform {
|
||||
protected $toomany = false;
|
||||
|
||||
/**
|
||||
* Overriding this function to get unique form id for multiple self enrolments
|
||||
* Overriding this function to get unique form id for multiple self enrolments.
|
||||
*
|
||||
* @return string form identifier
|
||||
*/
|
||||
@@ -54,10 +52,10 @@ class enrol_self_enrol_form extends moodleform {
|
||||
$mform->addElement('header', 'selfheader', $heading);
|
||||
|
||||
if ($instance->customint3 > 0) {
|
||||
// max enrol limit specified
|
||||
// Max enrol limit specified.
|
||||
$count = $DB->count_records('user_enrolments', array('enrolid'=>$instance->id));
|
||||
if ($count >= $instance->customint3) {
|
||||
// bad luck, no more self enrolments here
|
||||
// Bad luck, no more self enrolments here.
|
||||
$this->toomany = true;
|
||||
$mform->addElement('static', 'notice', '', get_string('maxenrolledreached', 'enrol_self'));
|
||||
return;
|
||||
@@ -65,7 +63,7 @@ class enrol_self_enrol_form extends moodleform {
|
||||
}
|
||||
|
||||
if ($instance->password) {
|
||||
//change the id of self enrolment key input as there can be multiple self enrolment methods
|
||||
// Change the id of self enrolment key input as there can be multiple self enrolment methods.
|
||||
$mform->addElement('passwordunmask', 'enrolpassword', get_string('password', 'enrol_self'),
|
||||
array('id' => 'enrolpassword_'.$instance->id));
|
||||
} else {
|
||||
@@ -109,7 +107,7 @@ class enrol_self_enrol_form extends moodleform {
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
// we can not hint because there are probably multiple passwords
|
||||
// We can not hint because there are probably multiple passwords.
|
||||
$errors['enrolpassword'] = get_string('passwordinvalid', 'enrol_self');
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@@ -18,8 +17,7 @@
|
||||
/**
|
||||
* Self enrolment plugin settings and presets.
|
||||
*
|
||||
* @package enrol
|
||||
* @subpackage self
|
||||
* @package enrol_self
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@@ -18,8 +17,7 @@
|
||||
/**
|
||||
* Self enrolment plugin - support for user self unenrolment.
|
||||
*
|
||||
* @package enrol
|
||||
* @subpackage self
|
||||
* @package enrol_self
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
@@ -41,7 +39,7 @@ require_login($course);
|
||||
|
||||
$plugin = enrol_get_plugin('self');
|
||||
|
||||
// security defined inside following function
|
||||
// Security defined inside following function.
|
||||
if (!$plugin->get_unenrolself_link($instance)) {
|
||||
redirect(new moodle_url('/course/view.php', array('id'=>$course->id)));
|
||||
}
|
||||
@@ -51,7 +49,7 @@ $PAGE->set_title($plugin->get_instance_name($instance));
|
||||
|
||||
if ($confirm and confirm_sesskey()) {
|
||||
$plugin->unenrol_user($instance, $USER->id);
|
||||
add_to_log($course->id, 'course', 'unenrol', '../enrol/users.php?id='.$course->id, $course->id); //there should be userid somewhere!
|
||||
add_to_log($course->id, 'course', 'unenrol', '../enrol/users.php?id='.$course->id, $course->id); //TODO: there should be userid somewhere!
|
||||
redirect(new moodle_url('/index.php'));
|
||||
}
|
||||
|
||||
|
||||
@@ -17,15 +17,14 @@
|
||||
/**
|
||||
* Self enrolment plugin version specification.
|
||||
*
|
||||
* @package enrol
|
||||
* @subpackage self
|
||||
* @package enrol_self
|
||||
* @copyright 2010 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2012061700; // The current plugin version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2012061700; // Requires this Moodle version
|
||||
$plugin->version = 2012082300; // The current plugin version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2012082300; // Requires this Moodle version
|
||||
$plugin->component = 'enrol_self'; // Full name of the plugin (used for diagnostics)
|
||||
$plugin->cron = 180;
|
||||
@@ -8,6 +8,9 @@ required changes in code:
|
||||
* use role_get_name() or role_fix_names() if you need any role names, using role.name
|
||||
directly from database is not correct any more
|
||||
|
||||
other changes:
|
||||
* course enrolment manager now works with disabled plugins too
|
||||
|
||||
|
||||
=== 2.2 ===
|
||||
|
||||
|
||||
+311
-311
@@ -1,33 +1,33 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* External files API
|
||||
*
|
||||
|
||||
/**
|
||||
* External files API
|
||||
*
|
||||
* @package core_files
|
||||
* @category external
|
||||
* @copyright 2010 Dongsheng Cai
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once("$CFG->libdir/externallib.php");
|
||||
require_once("$CFG->libdir/filelib.php");
|
||||
|
||||
/**
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once("$CFG->libdir/externallib.php");
|
||||
require_once("$CFG->libdir/filelib.php");
|
||||
|
||||
/**
|
||||
* Files external functions
|
||||
*
|
||||
* @package core_files
|
||||
@@ -35,31 +35,31 @@ require_once("$CFG->libdir/filelib.php");
|
||||
* @copyright 2011 Jerome Mouneyrac
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 2.2
|
||||
*/
|
||||
class core_files_external extends external_api {
|
||||
|
||||
/**
|
||||
* Returns description of get_files parameters
|
||||
*/
|
||||
class core_files_external extends external_api {
|
||||
|
||||
/**
|
||||
* Returns description of get_files parameters
|
||||
*
|
||||
* @return external_function_parameters
|
||||
* @return external_function_parameters
|
||||
* @since Moodle 2.2
|
||||
*/
|
||||
public static function get_files_parameters() {
|
||||
return new external_function_parameters(
|
||||
array(
|
||||
'contextid' => new external_value(PARAM_INT, 'context id'),
|
||||
'component' => new external_value(PARAM_TEXT, 'component'),
|
||||
'filearea' => new external_value(PARAM_TEXT, 'file area'),
|
||||
'itemid' => new external_value(PARAM_INT, 'associated id'),
|
||||
'filepath' => new external_value(PARAM_PATH, 'file path'),
|
||||
*/
|
||||
public static function get_files_parameters() {
|
||||
return new external_function_parameters(
|
||||
array(
|
||||
'contextid' => new external_value(PARAM_INT, 'context id'),
|
||||
'component' => new external_value(PARAM_TEXT, 'component'),
|
||||
'filearea' => new external_value(PARAM_TEXT, 'file area'),
|
||||
'itemid' => new external_value(PARAM_INT, 'associated id'),
|
||||
'filepath' => new external_value(PARAM_PATH, 'file path'),
|
||||
'filename' => new external_value(PARAM_FILE, 'file name'),
|
||||
'modified' => new external_value(PARAM_INT, 'timestamp to return files changed after this time.', VALUE_DEFAULT, null)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return moodle files listing
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return moodle files listing
|
||||
*
|
||||
* @param int $contextid context id
|
||||
* @param int $component component
|
||||
@@ -68,59 +68,59 @@ class core_files_external extends external_api {
|
||||
* @param string $filepath file path
|
||||
* @param string $filename file name
|
||||
* @param int $modified timestamp to return files changed after this time.
|
||||
* @return array
|
||||
* @return array
|
||||
* @since Moodle 2.2
|
||||
*/
|
||||
*/
|
||||
public static function get_files($contextid, $component, $filearea, $itemid, $filepath, $filename, $modified = null) {
|
||||
global $CFG, $USER, $OUTPUT;
|
||||
global $CFG, $USER, $OUTPUT;
|
||||
$fileinfo = self::validate_parameters(self::get_files_parameters(), array(
|
||||
'contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea,
|
||||
'itemid'=>$itemid, 'filepath'=>$filepath, 'filename'=>$filename, 'modified'=>$modified));
|
||||
|
||||
$browser = get_file_browser();
|
||||
|
||||
if (empty($fileinfo['contextid'])) {
|
||||
$context = get_system_context();
|
||||
} else {
|
||||
$context = get_context_instance_by_id($fileinfo['contextid']);
|
||||
}
|
||||
if (empty($fileinfo['component'])) {
|
||||
$fileinfo['component'] = null;
|
||||
}
|
||||
if (empty($fileinfo['filearea'])) {
|
||||
$fileinfo['filearea'] = null;
|
||||
}
|
||||
if (empty($fileinfo['itemid'])) {
|
||||
$fileinfo['itemid'] = null;
|
||||
}
|
||||
if (empty($fileinfo['filename'])) {
|
||||
$fileinfo['filename'] = null;
|
||||
}
|
||||
if (empty($fileinfo['filepath'])) {
|
||||
$fileinfo['filepath'] = null;
|
||||
}
|
||||
|
||||
$return = array();
|
||||
$return['parents'] = array();
|
||||
$return['files'] = array();
|
||||
|
||||
$browser = get_file_browser();
|
||||
|
||||
if (empty($fileinfo['contextid'])) {
|
||||
$context = get_system_context();
|
||||
} else {
|
||||
$context = context::instance_by_id($fileinfo['contextid']);
|
||||
}
|
||||
if (empty($fileinfo['component'])) {
|
||||
$fileinfo['component'] = null;
|
||||
}
|
||||
if (empty($fileinfo['filearea'])) {
|
||||
$fileinfo['filearea'] = null;
|
||||
}
|
||||
if (empty($fileinfo['itemid'])) {
|
||||
$fileinfo['itemid'] = null;
|
||||
}
|
||||
if (empty($fileinfo['filename'])) {
|
||||
$fileinfo['filename'] = null;
|
||||
}
|
||||
if (empty($fileinfo['filepath'])) {
|
||||
$fileinfo['filepath'] = null;
|
||||
}
|
||||
|
||||
$return = array();
|
||||
$return['parents'] = array();
|
||||
$return['files'] = array();
|
||||
$list = array();
|
||||
if ($file = $browser->get_file_info(
|
||||
$context, $fileinfo['component'], $fileinfo['filearea'], $fileinfo['itemid'],
|
||||
$fileinfo['filepath'], $fileinfo['filename'])) {
|
||||
$level = $file->get_parent();
|
||||
while ($level) {
|
||||
$params = $level->get_params();
|
||||
$params['filename'] = $level->get_visible_name();
|
||||
array_unshift($return['parents'], $params);
|
||||
$level = $level->get_parent();
|
||||
}
|
||||
$children = $file->get_children();
|
||||
foreach ($children as $child) {
|
||||
|
||||
$params = $child->get_params();
|
||||
$level = $file->get_parent();
|
||||
while ($level) {
|
||||
$params = $level->get_params();
|
||||
$params['filename'] = $level->get_visible_name();
|
||||
array_unshift($return['parents'], $params);
|
||||
$level = $level->get_parent();
|
||||
}
|
||||
$children = $file->get_children();
|
||||
foreach ($children as $child) {
|
||||
|
||||
$params = $child->get_params();
|
||||
$timemodified = $child->get_timemodified();
|
||||
|
||||
if ($child->is_directory()) {
|
||||
|
||||
if ($child->is_directory()) {
|
||||
if ((is_null($modified)) or ($modified < $timemodified)) {
|
||||
$node = array(
|
||||
'contextid' => $params['contextid'],
|
||||
@@ -135,7 +135,7 @@ class core_files_external extends external_api {
|
||||
);
|
||||
$list[] = $node;
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
if ((is_null($modified)) or ($modified < $timemodified)) {
|
||||
$node = array(
|
||||
'contextid' => $params['contextid'],
|
||||
@@ -150,76 +150,76 @@ class core_files_external extends external_api {
|
||||
);
|
||||
$list[] = $node;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$return['files'] = $list;
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of get_files returns
|
||||
}
|
||||
}
|
||||
}
|
||||
$return['files'] = $list;
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of get_files returns
|
||||
*
|
||||
* @return external_single_structure
|
||||
* @since Moodle 2.2
|
||||
*/
|
||||
public static function get_files_returns() {
|
||||
return new external_single_structure(
|
||||
array(
|
||||
'parents' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'contextid' => new external_value(PARAM_INT, ''),
|
||||
'component' => new external_value(PARAM_COMPONENT, ''),
|
||||
'filearea' => new external_value(PARAM_AREA, ''),
|
||||
'itemid' => new external_value(PARAM_INT, ''),
|
||||
'filepath' => new external_value(PARAM_TEXT, ''),
|
||||
'filename' => new external_value(PARAM_TEXT, ''),
|
||||
)
|
||||
)
|
||||
),
|
||||
'files' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'contextid' => new external_value(PARAM_INT, ''),
|
||||
'component' => new external_value(PARAM_COMPONENT, ''),
|
||||
'filearea' => new external_value(PARAM_AREA, ''),
|
||||
'itemid' => new external_value(PARAM_INT, ''),
|
||||
'filepath' => new external_value(PARAM_TEXT, ''),
|
||||
'filename' => new external_value(PARAM_FILE, ''),
|
||||
'isdir' => new external_value(PARAM_BOOL, ''),
|
||||
'url' => new external_value(PARAM_TEXT, ''),
|
||||
*/
|
||||
public static function get_files_returns() {
|
||||
return new external_single_structure(
|
||||
array(
|
||||
'parents' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'contextid' => new external_value(PARAM_INT, ''),
|
||||
'component' => new external_value(PARAM_COMPONENT, ''),
|
||||
'filearea' => new external_value(PARAM_AREA, ''),
|
||||
'itemid' => new external_value(PARAM_INT, ''),
|
||||
'filepath' => new external_value(PARAM_TEXT, ''),
|
||||
'filename' => new external_value(PARAM_TEXT, ''),
|
||||
)
|
||||
)
|
||||
),
|
||||
'files' => new external_multiple_structure(
|
||||
new external_single_structure(
|
||||
array(
|
||||
'contextid' => new external_value(PARAM_INT, ''),
|
||||
'component' => new external_value(PARAM_COMPONENT, ''),
|
||||
'filearea' => new external_value(PARAM_AREA, ''),
|
||||
'itemid' => new external_value(PARAM_INT, ''),
|
||||
'filepath' => new external_value(PARAM_TEXT, ''),
|
||||
'filename' => new external_value(PARAM_FILE, ''),
|
||||
'isdir' => new external_value(PARAM_BOOL, ''),
|
||||
'url' => new external_value(PARAM_TEXT, ''),
|
||||
'timemodified' => new external_value(PARAM_INT, ''),
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of upload parameters
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of upload parameters
|
||||
*
|
||||
* @return external_function_parameters
|
||||
* @return external_function_parameters
|
||||
* @since Moodle 2.2
|
||||
*/
|
||||
public static function upload_parameters() {
|
||||
return new external_function_parameters(
|
||||
array(
|
||||
'contextid' => new external_value(PARAM_INT, 'context id'),
|
||||
'component' => new external_value(PARAM_COMPONENT, 'component'),
|
||||
'filearea' => new external_value(PARAM_AREA, 'file area'),
|
||||
'itemid' => new external_value(PARAM_INT, 'associated id'),
|
||||
'filepath' => new external_value(PARAM_PATH, 'file path'),
|
||||
'filename' => new external_value(PARAM_FILE, 'file name'),
|
||||
'filecontent' => new external_value(PARAM_TEXT, 'file content')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uploading a file to moodle
|
||||
*
|
||||
*/
|
||||
public static function upload_parameters() {
|
||||
return new external_function_parameters(
|
||||
array(
|
||||
'contextid' => new external_value(PARAM_INT, 'context id'),
|
||||
'component' => new external_value(PARAM_COMPONENT, 'component'),
|
||||
'filearea' => new external_value(PARAM_AREA, 'file area'),
|
||||
'itemid' => new external_value(PARAM_INT, 'associated id'),
|
||||
'filepath' => new external_value(PARAM_PATH, 'file path'),
|
||||
'filename' => new external_value(PARAM_FILE, 'file name'),
|
||||
'filecontent' => new external_value(PARAM_TEXT, 'file content')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uploading a file to moodle
|
||||
*
|
||||
* @param int $contextid context id
|
||||
* @param string $component component
|
||||
* @param string $filearea file aera
|
||||
@@ -227,112 +227,112 @@ class core_files_external extends external_api {
|
||||
* @param string $filepath file path
|
||||
* @param string $filename file name
|
||||
* @param string $filecontent file content
|
||||
* @return array
|
||||
* @return array
|
||||
* @since Moodle 2.2
|
||||
*/
|
||||
public static function upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent) {
|
||||
global $USER, $CFG;
|
||||
|
||||
*/
|
||||
public static function upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent) {
|
||||
global $USER, $CFG;
|
||||
|
||||
$fileinfo = self::validate_parameters(self::upload_parameters(), array(
|
||||
'contextid'=>$contextid, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>$itemid,
|
||||
'filepath'=>$filepath, 'filename'=>$filename, 'filecontent'=>$filecontent));
|
||||
|
||||
if (!isset($fileinfo['filecontent'])) {
|
||||
throw new moodle_exception('nofile');
|
||||
}
|
||||
|
||||
if (!isset($fileinfo['filecontent'])) {
|
||||
throw new moodle_exception('nofile');
|
||||
}
|
||||
// Saving file.
|
||||
$dir = make_temp_directory('wsupload');
|
||||
|
||||
if (empty($fileinfo['filename'])) {
|
||||
$filename = uniqid('wsupload', true).'_'.time().'.tmp';
|
||||
} else {
|
||||
$filename = $fileinfo['filename'];
|
||||
}
|
||||
|
||||
if (file_exists($dir.$filename)) {
|
||||
$savedfilepath = $dir.uniqid('m').$filename;
|
||||
} else {
|
||||
$savedfilepath = $dir.$filename;
|
||||
}
|
||||
|
||||
file_put_contents($savedfilepath, base64_decode($fileinfo['filecontent']));
|
||||
unset($fileinfo['filecontent']);
|
||||
|
||||
if (!empty($fileinfo['filepath'])) {
|
||||
$filepath = $fileinfo['filepath'];
|
||||
} else {
|
||||
$filepath = '/';
|
||||
}
|
||||
|
||||
if (isset($fileinfo['itemid'])) {
|
||||
$dir = make_temp_directory('wsupload');
|
||||
|
||||
if (empty($fileinfo['filename'])) {
|
||||
$filename = uniqid('wsupload', true).'_'.time().'.tmp';
|
||||
} else {
|
||||
$filename = $fileinfo['filename'];
|
||||
}
|
||||
|
||||
if (file_exists($dir.$filename)) {
|
||||
$savedfilepath = $dir.uniqid('m').$filename;
|
||||
} else {
|
||||
$savedfilepath = $dir.$filename;
|
||||
}
|
||||
|
||||
file_put_contents($savedfilepath, base64_decode($fileinfo['filecontent']));
|
||||
unset($fileinfo['filecontent']);
|
||||
|
||||
if (!empty($fileinfo['filepath'])) {
|
||||
$filepath = $fileinfo['filepath'];
|
||||
} else {
|
||||
$filepath = '/';
|
||||
}
|
||||
|
||||
if (isset($fileinfo['itemid'])) {
|
||||
// TODO MDL-31116 in user private area, itemid is always 0.
|
||||
$itemid = 0;
|
||||
} else {
|
||||
throw new coding_exception('itemid cannot be empty');
|
||||
}
|
||||
|
||||
if (!empty($fileinfo['contextid'])) {
|
||||
$context = get_context_instance_by_id($fileinfo['contextid']);
|
||||
} else {
|
||||
$context = get_system_context();
|
||||
}
|
||||
|
||||
if (!($fileinfo['component'] == 'user' and $fileinfo['filearea'] == 'private')) {
|
||||
throw new coding_exception('File can be uploaded to user private area only');
|
||||
} else {
|
||||
$itemid = 0;
|
||||
} else {
|
||||
throw new coding_exception('itemid cannot be empty');
|
||||
}
|
||||
|
||||
if (!empty($fileinfo['contextid'])) {
|
||||
$context = context::instance_by_id($fileinfo['contextid']);
|
||||
} else {
|
||||
$context = get_system_context();
|
||||
}
|
||||
|
||||
if (!($fileinfo['component'] == 'user' and $fileinfo['filearea'] == 'private')) {
|
||||
throw new coding_exception('File can be uploaded to user private area only');
|
||||
} else {
|
||||
// TODO MDL-31116 hard-coded to use user_private area.
|
||||
$component = 'user';
|
||||
$filearea = 'private';
|
||||
}
|
||||
|
||||
$browser = get_file_browser();
|
||||
|
||||
$component = 'user';
|
||||
$filearea = 'private';
|
||||
}
|
||||
|
||||
$browser = get_file_browser();
|
||||
|
||||
// Check existing file.
|
||||
if ($file = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename)) {
|
||||
throw new moodle_exception('fileexist');
|
||||
}
|
||||
|
||||
if ($file = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename)) {
|
||||
throw new moodle_exception('fileexist');
|
||||
}
|
||||
|
||||
// Move file to filepool.
|
||||
if ($dir = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, '.')) {
|
||||
$info = $dir->create_file_from_pathname($filename, $savedfilepath);
|
||||
$params = $info->get_params();
|
||||
unlink($savedfilepath);
|
||||
return array(
|
||||
'contextid'=>$params['contextid'],
|
||||
'component'=>$params['component'],
|
||||
'filearea'=>$params['filearea'],
|
||||
'itemid'=>$params['itemid'],
|
||||
'filepath'=>$params['filepath'],
|
||||
'filename'=>$params['filename'],
|
||||
'url'=>$info->get_url()
|
||||
);
|
||||
} else {
|
||||
throw new moodle_exception('nofile');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of upload returns
|
||||
if ($dir = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, '.')) {
|
||||
$info = $dir->create_file_from_pathname($filename, $savedfilepath);
|
||||
$params = $info->get_params();
|
||||
unlink($savedfilepath);
|
||||
return array(
|
||||
'contextid'=>$params['contextid'],
|
||||
'component'=>$params['component'],
|
||||
'filearea'=>$params['filearea'],
|
||||
'itemid'=>$params['itemid'],
|
||||
'filepath'=>$params['filepath'],
|
||||
'filename'=>$params['filename'],
|
||||
'url'=>$info->get_url()
|
||||
);
|
||||
} else {
|
||||
throw new moodle_exception('nofile');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of upload returns
|
||||
*
|
||||
* @return external_single_structure
|
||||
* @since Moodle 2.2
|
||||
*/
|
||||
public static function upload_returns() {
|
||||
return new external_single_structure(
|
||||
array(
|
||||
'contextid' => new external_value(PARAM_INT, ''),
|
||||
'component' => new external_value(PARAM_COMPONENT, ''),
|
||||
'filearea' => new external_value(PARAM_AREA, ''),
|
||||
'itemid' => new external_value(PARAM_INT, ''),
|
||||
'filepath' => new external_value(PARAM_TEXT, ''),
|
||||
'filename' => new external_value(PARAM_FILE, ''),
|
||||
'url' => new external_value(PARAM_TEXT, ''),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
public static function upload_returns() {
|
||||
return new external_single_structure(
|
||||
array(
|
||||
'contextid' => new external_value(PARAM_INT, ''),
|
||||
'component' => new external_value(PARAM_COMPONENT, ''),
|
||||
'filearea' => new external_value(PARAM_AREA, ''),
|
||||
'itemid' => new external_value(PARAM_INT, ''),
|
||||
'filepath' => new external_value(PARAM_TEXT, ''),
|
||||
'filename' => new external_value(PARAM_FILE, ''),
|
||||
'url' => new external_value(PARAM_TEXT, ''),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deprecated files external functions
|
||||
*
|
||||
* @package core_files
|
||||
@@ -342,97 +342,97 @@ class core_files_external extends external_api {
|
||||
* @deprecated Moodle 2.2 MDL-29106 - Please do not use this class any more.
|
||||
* @todo MDL-31194 This will be deleted in Moodle 2.5.
|
||||
* @see core_files_external
|
||||
*/
|
||||
class moodle_file_external extends external_api {
|
||||
|
||||
/**
|
||||
* Returns description of get_files parameters
|
||||
*/
|
||||
class moodle_file_external extends external_api {
|
||||
|
||||
/**
|
||||
* Returns description of get_files parameters
|
||||
*
|
||||
* @return external_function_parameters
|
||||
* @return external_function_parameters
|
||||
* @since Moodle 2.0
|
||||
* @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
|
||||
* @todo MDL-31194 This will be deleted in Moodle 2.5.
|
||||
* @see core_files_external::get_files_parameters()
|
||||
*/
|
||||
public static function get_files_parameters() {
|
||||
return core_files_external::get_files_parameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return moodle files listing
|
||||
*/
|
||||
public static function get_files_parameters() {
|
||||
return core_files_external::get_files_parameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return moodle files listing
|
||||
*
|
||||
* @param int $contextid
|
||||
* @param int $component
|
||||
* @param int $filearea
|
||||
* @param int $itemid
|
||||
* @param string $filepath
|
||||
* @param string $filename
|
||||
* @return array
|
||||
* @param int $contextid
|
||||
* @param int $component
|
||||
* @param int $filearea
|
||||
* @param int $itemid
|
||||
* @param string $filepath
|
||||
* @param string $filename
|
||||
* @return array
|
||||
* @since Moodle 2.0
|
||||
* @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
|
||||
* @todo MDL-31194 This will be deleted in Moodle 2.5.
|
||||
* @see core_files_external::get_files()
|
||||
*/
|
||||
public static function get_files($contextid, $component, $filearea, $itemid, $filepath, $filename) {
|
||||
return core_files_external::get_files($contextid, $component, $filearea, $itemid, $filepath, $filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of get_files returns
|
||||
*/
|
||||
public static function get_files($contextid, $component, $filearea, $itemid, $filepath, $filename) {
|
||||
return core_files_external::get_files($contextid, $component, $filearea, $itemid, $filepath, $filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of get_files returns
|
||||
*
|
||||
* @return external_single_structure
|
||||
* @since Moodle 2.0
|
||||
* @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
|
||||
* @todo MDL-31194 This will be deleted in Moodle 2.5.
|
||||
* @see core_files_external::get_files_returns()
|
||||
*/
|
||||
public static function get_files_returns() {
|
||||
return core_files_external::get_files_returns();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of upload parameters
|
||||
*/
|
||||
public static function get_files_returns() {
|
||||
return core_files_external::get_files_returns();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of upload parameters
|
||||
*
|
||||
* @return external_function_parameters
|
||||
* @return external_function_parameters
|
||||
* @since Moodle 2.0
|
||||
* @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
|
||||
* @todo MDL-31194 This will be deleted in Moodle 2.5.
|
||||
* @see core_files_external::upload_parameters()
|
||||
*/
|
||||
public static function upload_parameters() {
|
||||
return core_files_external::upload_parameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Uploading a file to moodle
|
||||
*/
|
||||
public static function upload_parameters() {
|
||||
return core_files_external::upload_parameters();
|
||||
}
|
||||
|
||||
/**
|
||||
* Uploading a file to moodle
|
||||
*
|
||||
* @param int $contextid
|
||||
* @param string $component
|
||||
* @param string $filearea
|
||||
* @param int $itemid
|
||||
* @param string $filepath
|
||||
* @param string $filename
|
||||
* @param string $filecontent
|
||||
* @return array
|
||||
* @param int $contextid
|
||||
* @param string $component
|
||||
* @param string $filearea
|
||||
* @param int $itemid
|
||||
* @param string $filepath
|
||||
* @param string $filename
|
||||
* @param string $filecontent
|
||||
* @return array
|
||||
* @since Moodle 2.0
|
||||
* @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
|
||||
* @todo MDL-31194 This will be deleted in Moodle 2.5.
|
||||
* @see core_files_external::upload()
|
||||
*/
|
||||
public static function upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent) {
|
||||
return core_files_external::upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of upload returns
|
||||
*/
|
||||
public static function upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent) {
|
||||
return core_files_external::upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns description of upload returns
|
||||
*
|
||||
* @return external_single_structure
|
||||
* @since Moodle 2.0
|
||||
* @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more.
|
||||
* @todo MDL-31194 This will be deleted in Moodle 2.5.
|
||||
* @see core_files_external::upload_returns()
|
||||
*/
|
||||
public static function upload_returns() {
|
||||
return core_files_external::upload_returns();
|
||||
}
|
||||
}
|
||||
*/
|
||||
public static function upload_returns() {
|
||||
return core_files_external::upload_returns();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -965,7 +965,7 @@ class files_tree_viewer implements renderable {
|
||||
$this->path = array();
|
||||
while ($level) {
|
||||
$params = $level->get_params();
|
||||
$context = get_context_instance_by_id($params['contextid']);
|
||||
$context = context::instance_by_id($params['contextid']);
|
||||
// $this->context is current context
|
||||
if ($context->id != $this->context->id or empty($params['filearea'])) {
|
||||
break;
|
||||
|
||||
@@ -89,7 +89,7 @@ function filter_algebra_image($imagefile, $tex= "", $height="", $width="", $alig
|
||||
}
|
||||
|
||||
class filter_algebra extends moodle_text_filter {
|
||||
function filter($text, array $options = array()){
|
||||
public function filter($text, array $options = array()){
|
||||
global $CFG, $DB;
|
||||
|
||||
/// Do a quick check using stripos to avoid unnecessary wor
|
||||
@@ -114,9 +114,6 @@ class filter_algebra extends moodle_text_filter {
|
||||
# return $text;
|
||||
# }
|
||||
|
||||
|
||||
$text .= ' ';
|
||||
|
||||
preg_match_all('/@(@@+)([^@])/',$text,$matches);
|
||||
for ($i=0;$i<count($matches[0]);$i++) {
|
||||
$replacement = str_replace('@','@',$matches[1][$i]).$matches[2][$i];
|
||||
@@ -129,6 +126,17 @@ class filter_algebra extends moodle_text_filter {
|
||||
preg_match_all('/<algebra>(.+?)<\/algebra>|@@(.+?)@@/is', $text, $matches);
|
||||
for ($i=0; $i<count($matches[0]); $i++) {
|
||||
$algebra = $matches[1][$i] . $matches[2][$i];
|
||||
|
||||
// Look for some common false positives, and skip processing them.
|
||||
if ($algebra == 'PLUGINFILE' || $algebra == 'DRAFTFILE') {
|
||||
// Raw pluginfile URL.
|
||||
continue;
|
||||
}
|
||||
if (preg_match('/^ -\d+(,\d+)? \+\d+(,\d+)? $/', $algebra)) {
|
||||
// Part of a unified diff.
|
||||
continue;
|
||||
}
|
||||
|
||||
$algebra = str_replace('<nolink>','',$algebra);
|
||||
$algebra = str_replace('</nolink>','',$algebra);
|
||||
$algebra = str_replace('<span class="nolink">','',$algebra);
|
||||
@@ -159,7 +167,7 @@ class filter_algebra extends moodle_text_filter {
|
||||
$algebra = str_replace('upsilon','zupslon',$algebra);
|
||||
$algebra = preg_replace('!\r\n?!',' ',$algebra);
|
||||
$algebra = escapeshellarg($algebra);
|
||||
if ( (PHP_OS == "WINNT") || (PHP_OS == "WIN32") || (PHP_OS == "Windows") ) {
|
||||
if ( (PHP_OS == "WINNT") || (PHP_OS == "WIN32") || (PHP_OS == "Windows")) {
|
||||
$cmd = "cd $CFG->dirroot\\filter\\algebra & algebra2tex.pl $algebra";
|
||||
} else {
|
||||
$cmd = "cd $CFG->dirroot/filter/algebra; ./algebra2tex.pl $algebra";
|
||||
@@ -220,6 +228,7 @@ class filter_algebra extends moodle_text_filter {
|
||||
$texexp = preg_replace('/\\\int\\\left\((.+?d[a-z])\\\right\)/s','\int '. "\$1 ",$texexp);
|
||||
$texexp = preg_replace('/\\\lim\\\left\((.+?),(.+?),(.+?)\\\right\)/s','\lim_'. "{\$2\\to \$3}\$1 ",$texexp);
|
||||
$texexp = str_replace('\mbox', '', $texexp); // now blacklisted in tex, sorry
|
||||
$texcache = new stdClass();
|
||||
$texcache->filter = 'algebra';
|
||||
$texcache->version = 1;
|
||||
$texcache->md5key = $md5;
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Unit test for the filter_algebra
|
||||
*
|
||||
* @package filter_algebra
|
||||
* @category phpunit
|
||||
* @copyright 2012 Tim Hunt
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/filter/algebra/filter.php');
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for filter_algebra.
|
||||
*
|
||||
* Note that this only tests some of the filter logic. It does not acutally test
|
||||
* the normal case of the filter working, because I cannot make it work on my
|
||||
* test server, and if it does not work here, it probably does not also work
|
||||
* for other people. A failing test will be irritating noise.
|
||||
*
|
||||
* @copyright 2012 Tim Hunt
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class filter_algebra_testcase extends basic_testcase {
|
||||
|
||||
protected $filter;
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->filter = new filter_algebra(context_system::instance(), array());
|
||||
}
|
||||
|
||||
function test_algebra_filter_no_algebra() {
|
||||
$this->assertEquals('<p>Look no algebra!</p>',
|
||||
$this->filter->filter('<p>Look no algebra!</p>'));
|
||||
}
|
||||
|
||||
|
||||
function test_algebra_filter_pluginfile() {
|
||||
$this->assertEquals('<img src="@@PLUGINFILE@@/photo.jpg">',
|
||||
$this->filter->filter('<img src="@@PLUGINFILE@@/photo.jpg">'));
|
||||
}
|
||||
|
||||
function test_algebra_filter_draftfile() {
|
||||
$this->assertEquals('<img src="@@DRAFTFILE@@/photo.jpg">',
|
||||
$this->filter->filter('<img src="@@DRAFTFILE@@/photo.jpg">'));
|
||||
}
|
||||
|
||||
function test_algebra_filter_unified_diff() {
|
||||
$diff = '
|
||||
diff -u -r1.1 Worksheet.php
|
||||
--- Worksheet.php 26 Sep 2003 04:18:02 -0000 1.1
|
||||
+++ Worksheet.php 18 Nov 2009 03:58:50 -0000
|
||||
@@ -1264,10 +1264,10 @@
|
||||
}
|
||||
|
||||
// Strip the = or @ sign at the beginning of the formula string
|
||||
- if (ereg("^=",$formula)) {
|
||||
+ if (preg_match("/^=/",$formula)) {
|
||||
$formula = preg_replace("/(^=)/","",$formula);
|
||||
}
|
||||
- elseif(ereg("^@",$formula)) {
|
||||
+ elseif(preg_match("/^@/",$formula)) {
|
||||
$formula = preg_replace("/(^@)/","",$formula);
|
||||
}
|
||||
else {
|
||||
';
|
||||
$this->assertEquals('<pre>' . $diff . '</pre>',
|
||||
$this->filter->filter('<pre>' . $diff . '</pre>'));
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,6 @@ $string['save'] = 'Save';
|
||||
$string['saveguide'] = 'Save marking guide and make it ready';
|
||||
$string['saveguidedraft'] = 'Save as draft';
|
||||
$string['score'] = 'score';
|
||||
$string['showdescriptionstudent'] = 'Display description to those being graded';
|
||||
$string['showmarkerdesc'] = 'Show marker criterion descriptions';
|
||||
$string['showmarkspercriterionstudents'] = 'Show marks per criterion to students';
|
||||
$string['showstudentdesc'] = 'Show student criterion descriptions';
|
||||
|
||||
@@ -506,6 +506,7 @@ class gradingform_guide_controller extends gradingform_controller {
|
||||
$comments = $this->definition->guide_comment;
|
||||
$options = $this->get_options();
|
||||
$guide = '';
|
||||
$guide .= $output->box($this->get_formatted_description(), 'gradingform_guide-description');
|
||||
if (has_capability('moodle/grade:managegradingforms', $page->context)) {
|
||||
$guide .= $output->display_guide_mapping_explained($this->get_min_max_score());
|
||||
$guide .= $output->display_guide($criteria, $comments, $options, self::DISPLAY_PREVIEW, 'guide');
|
||||
@@ -872,10 +873,8 @@ class gradingform_guide_instance extends gradingform_instance {
|
||||
$html .= html_writer::tag('div', get_string('restoredfromdraft', 'gradingform_guide'),
|
||||
array('class' => 'gradingform_guide-restored'));
|
||||
}
|
||||
if (!empty($options['showdescriptionteacher'])) {
|
||||
$html .= html_writer::tag('div', $this->get_controller()->get_formatted_description(),
|
||||
array('class' => 'gradingform_guide-description'));
|
||||
}
|
||||
$html .= html_writer::tag('div', $this->get_controller()->get_formatted_description(),
|
||||
array('class' => 'gradingform_guide-description'));
|
||||
$html .= $this->get_controller()->get_renderer($page)->display_guide($criteria, $comments, $options, $mode,
|
||||
$gradingformelement->getName(), $value, $this->validationerrors);
|
||||
return $html;
|
||||
|
||||
@@ -49,8 +49,5 @@ $PAGE->set_heading($title);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($title);
|
||||
if (!empty($options['showdescriptionstudent'])) {
|
||||
echo $OUTPUT->box($controller->get_formatted_description(), 'gradingform_guide-description');
|
||||
}
|
||||
echo $controller->render_preview($PAGE);
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
@@ -508,6 +508,14 @@ class gradingform_rubric_controller extends gradingform_controller {
|
||||
$criteria = $this->definition->rubric_criteria;
|
||||
$options = $this->get_options();
|
||||
$rubric = '';
|
||||
if (has_capability('moodle/grade:managegradingforms', $page->context)) {
|
||||
$showdescription = true;
|
||||
} else {
|
||||
$showdescription = $options['showdescriptionstudent'];
|
||||
}
|
||||
if ($showdescription) {
|
||||
$rubric .= $output->box($this->get_formatted_description(), 'gradingform_rubric-description');
|
||||
}
|
||||
if (has_capability('moodle/grade:managegradingforms', $page->context)) {
|
||||
$rubric .= $output->display_rubric_mapping_explained($this->get_min_max_score());
|
||||
$rubric .= $output->display_rubric($criteria, $options, self::DISPLAY_PREVIEW, 'rubric');
|
||||
|
||||
@@ -49,8 +49,5 @@ $PAGE->set_heading($title);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading($title);
|
||||
if (!empty($options['showdescriptionstudent'])) {
|
||||
echo $OUTPUT->box($controller->get_formatted_description(), 'gradingform_rubric-description');
|
||||
}
|
||||
echo $controller->render_preview($PAGE);
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
@@ -223,7 +223,7 @@ class grading_manager {
|
||||
global $DB;
|
||||
|
||||
$this->areacache = $DB->get_record('grading_areas', array('id' => $areaid), '*', MUST_EXIST);
|
||||
$this->context = get_context_instance_by_id($this->areacache->contextid, MUST_EXIST);
|
||||
$this->context = context::instance_by_id($this->areacache->contextid, MUST_EXIST);
|
||||
$this->component = $this->areacache->component;
|
||||
$this->area = $this->areacache->areaname;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ if (!is_null($areaid)) {
|
||||
if (is_null($contextid) or is_null($component) or is_null($area)) {
|
||||
throw new coding_exception('The caller script must identify the gradable area.');
|
||||
}
|
||||
$context = get_context_instance_by_id($contextid, MUST_EXIST);
|
||||
$context = context::instance_by_id($contextid, MUST_EXIST);
|
||||
$manager = get_grading_manager($context, $component, $area);
|
||||
}
|
||||
|
||||
@@ -233,7 +233,6 @@ if (!empty($method)) {
|
||||
$tag = html_writer::tag('span', get_string('statusdraft', 'core_grading'), array('class' => 'status draft'));
|
||||
}
|
||||
echo $output->heading(s($definition->name) . ' ' . $tag, 3, 'definition-name');
|
||||
echo $output->box($controller->get_formatted_description());
|
||||
echo $output->box($controller->render_preview($PAGE), 'definition-preview');
|
||||
}
|
||||
}
|
||||
|
||||
+8
-1
@@ -2610,6 +2610,7 @@ abstract class grade_helper {
|
||||
* @return array
|
||||
*/
|
||||
public static function get_info_letters($courseid) {
|
||||
global $SITE;
|
||||
if (self::$letterinfo !== null) {
|
||||
return self::$letterinfo;
|
||||
}
|
||||
@@ -2617,9 +2618,15 @@ abstract class grade_helper {
|
||||
$canmanage = has_capability('moodle/grade:manage', $context);
|
||||
$canmanageletters = has_capability('moodle/grade:manageletters', $context);
|
||||
if ($canmanage || $canmanageletters) {
|
||||
// Redirect to system context when report is accessed from admin settings MDL-31633
|
||||
if ($context->instanceid == $SITE->id) {
|
||||
$param = array('edit' => 1);
|
||||
} else {
|
||||
$param = array('edit' => 1,'id' => $context->id);
|
||||
}
|
||||
self::$letterinfo = array(
|
||||
'view' => new grade_plugin_info('view', new moodle_url('/grade/edit/letter/index.php', array('id'=>$context->id)), get_string('view')),
|
||||
'edit' => new grade_plugin_info('edit', new moodle_url('/grade/edit/letter/index.php', array('edit'=>1,'id'=>$context->id)), get_string('edit'))
|
||||
'edit' => new grade_plugin_info('edit', new moodle_url('/grade/edit/letter/index.php', $param), get_string('edit'))
|
||||
);
|
||||
} else {
|
||||
self::$letterinfo = false;
|
||||
|
||||
@@ -545,6 +545,9 @@ class core_group_external extends external_api {
|
||||
}
|
||||
require_capability('moodle/course:managegroups', $context);
|
||||
|
||||
if (!groups_remove_member_allowed($group, $user)) {
|
||||
throw new moodle_exception('errorremovenotpermitted', 'group', '', fullname($user));
|
||||
}
|
||||
groups_remove_member($group, $user);
|
||||
}
|
||||
|
||||
|
||||
+73
-1
@@ -33,10 +33,12 @@
|
||||
*
|
||||
* @param mixed $grouporid The group id or group object
|
||||
* @param mixed $userorid The user id or user object
|
||||
* @param string $component Optional component name e.g. 'enrol_imsenterprise'
|
||||
* @param int $itemid Optional itemid associated with component
|
||||
* @return bool True if user added successfully or the user is already a
|
||||
* member of the group, false otherwise.
|
||||
*/
|
||||
function groups_add_member($grouporid, $userorid) {
|
||||
function groups_add_member($grouporid, $userorid, $component=null, $itemid=0) {
|
||||
global $DB;
|
||||
|
||||
if (is_object($userorid)) {
|
||||
@@ -68,6 +70,25 @@ function groups_add_member($grouporid, $userorid) {
|
||||
$member->groupid = $groupid;
|
||||
$member->userid = $userid;
|
||||
$member->timeadded = time();
|
||||
$member->component = '';
|
||||
$member->itemid = 0;
|
||||
|
||||
// Check the component exists if specified
|
||||
if (!empty($component)) {
|
||||
$dir = get_component_directory($component);
|
||||
if ($dir && is_dir($dir)) {
|
||||
// Component exists and can be used
|
||||
$member->component = $component;
|
||||
$member->itemid = $itemid;
|
||||
} else {
|
||||
throw new coding_exception('Invalid call to groups_add_member(). An invalid component was specified');
|
||||
}
|
||||
}
|
||||
|
||||
if ($itemid !== 0 && empty($member->component)) {
|
||||
// An itemid can only be specified if a valid component was found
|
||||
throw new coding_exception('Invalid call to groups_add_member(). A component must be specified if an itemid is given');
|
||||
}
|
||||
|
||||
$DB->insert_record('groups_members', $member);
|
||||
|
||||
@@ -78,11 +99,62 @@ function groups_add_member($grouporid, $userorid) {
|
||||
$eventdata = new stdClass();
|
||||
$eventdata->groupid = $groupid;
|
||||
$eventdata->userid = $userid;
|
||||
$eventdata->component = $member->component;
|
||||
$eventdata->itemid = $member->itemid;
|
||||
events_trigger('groups_member_added', $eventdata);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the current user is permitted (using the normal UI) to
|
||||
* remove a specific group member, assuming that they have access to remove
|
||||
* group members in general.
|
||||
*
|
||||
* For automatically-created group member entries, this checks with the
|
||||
* relevant plugin to see whether it is permitted. The default, if the plugin
|
||||
* doesn't provide a function, is true.
|
||||
*
|
||||
* For other entries (and any which have already been deleted/don't exist) it
|
||||
* just returns true.
|
||||
*
|
||||
* @param mixed $grouporid The group id or group object
|
||||
* @param mixed $userorid The user id or user object
|
||||
* @return bool True if permitted, false otherwise
|
||||
*/
|
||||
function groups_remove_member_allowed($grouporid, $userorid) {
|
||||
global $DB;
|
||||
|
||||
if (is_object($userorid)) {
|
||||
$userid = $userorid->id;
|
||||
} else {
|
||||
$userid = $userorid;
|
||||
}
|
||||
if (is_object($grouporid)) {
|
||||
$groupid = $grouporid->id;
|
||||
} else {
|
||||
$groupid = $grouporid;
|
||||
}
|
||||
|
||||
// Get entry
|
||||
if (!($entry = $DB->get_record('groups_members',
|
||||
array('groupid' => $groupid, 'userid' => $userid), '*', IGNORE_MISSING))) {
|
||||
// If the entry does not exist, they are allowed to remove it (this
|
||||
// is consistent with groups_remove_member below).
|
||||
return true;
|
||||
}
|
||||
|
||||
// If the entry does not have a component value, they can remove it
|
||||
if (empty($entry->component)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// It has a component value, so we need to call a plugin function (if it
|
||||
// exists); the default is to allow removal
|
||||
return component_callback($entry->component, 'allow_group_member_remove',
|
||||
array($entry->itemid, $entry->groupid, $entry->userid), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the link between the specified user and group.
|
||||
*
|
||||
|
||||
@@ -67,6 +67,10 @@ if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
|
||||
$userstoremove = $groupmembersselector->get_selected_users();
|
||||
if (!empty($userstoremove)) {
|
||||
foreach ($userstoremove as $user) {
|
||||
if (!groups_remove_member_allowed($groupid, $user->id)) {
|
||||
print_error('errorremovenotpermitted', 'group', $returnurl,
|
||||
$user->fullname);
|
||||
}
|
||||
if (!groups_remove_member($groupid, $user->id)) {
|
||||
print_error('erroraddremoveuser', 'group', $returnurl);
|
||||
}
|
||||
|
||||
@@ -34,9 +34,11 @@ $string['clianswerno'] = 'n';
|
||||
$string['cliansweryes'] = 't';
|
||||
$string['cliincorrectvalueerror'] = 'Klaida, klaidinga "{$a->option}" reikšmė "{$a->value}"';
|
||||
$string['cliincorrectvalueretry'] = 'Klaidinga reikšmė, bandykite dar kartą';
|
||||
$string['clitypevalue'] = 'tipo reikšmė';
|
||||
$string['clitypevaluedefault'] = 'tipo reikšmė, paspauskite „Enter“, jei norite naudoti numatytąją reikšmę ({$a})';
|
||||
$string['cliunknowoption'] = 'Neatpažintos parinktys: {$a} naudokite --žinyno parinktį.';
|
||||
$string['clitypevalue'] = 'įveskite reikšmę';
|
||||
$string['clitypevaluedefault'] = 'įveskite reikšmę, paspauskite „Enter“, jei norite naudoti numatytąją reikšmę ({$a})';
|
||||
$string['cliunknowoption'] = 'Neatpažintos parinktys:
|
||||
{$a}
|
||||
Naudokite --help parinktį.';
|
||||
$string['cliyesnoprompt'] = 'įveskite t (taip) arba n (ne)';
|
||||
$string['environmentrequireinstall'] = 'turi būti įdiegta ir įgalinta';
|
||||
$string['environmentrequireversion'] = 'reikalinga {$a->needed} versija, o Jūs turite {$a->current}';
|
||||
|
||||
+6
-1
@@ -98,8 +98,13 @@ $string['unenrolconfirm'] = 'Do you really want to unenrol user "{$a->user}" fro
|
||||
$string['unenrolme'] = 'Unenrol me from {$a}';
|
||||
$string['unenrolnotpermitted'] = 'You do not have permission or can not unenrol this user from this course.';
|
||||
$string['unenrolroleusers'] = 'Unenrol users';
|
||||
$string['uninstallconfirm'] = 'You are about to completely delete the enrol plugin \'{$a}\'. This will completely delete everything in the database associated with this enrolment type. Are you SURE you want to continue?';
|
||||
$string['uninstallconfirm'] = 'You are about to uninstall the enrolment plugin \'{$a}\'. This will result in the deletion of all data associated with this enrolment type, including users\' grades, group membership, forum subscriptions and any other course-related data.
|
||||
|
||||
Are you SURE you want to continue?';
|
||||
$string['uninstalldelete'] = 'Delete all enrolments and uninstall';
|
||||
$string['uninstalldeletefiles'] = 'All data associated with the enrol plugin \'{$a->plugin}\' has been deleted from the database. To complete the deletion (and prevent the plugin re-installing itself), you should now delete this directory from your server: {$a->directory}';
|
||||
$string['uninstallmigrate'] = 'Uninstall but keep all enrolments';
|
||||
$string['uninstallmigrating'] = 'Migrating "{$a}" enrolments';
|
||||
$string['unknowajaxaction'] = 'Unknown action requested';
|
||||
$string['unlimitedduration'] = 'Unlimited';
|
||||
$string['usersearch'] = 'Search ';
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['addedby'] = 'Added by {$a}';
|
||||
$string['addgroup'] = 'Add user into group';
|
||||
$string['addgroupstogrouping'] = 'Add group to grouping';
|
||||
$string['addgroupstogroupings'] = 'Add/remove groups';
|
||||
@@ -62,6 +63,7 @@ $string['erroraddremoveuser'] = 'Error adding/removing user {$a} to group';
|
||||
$string['erroreditgroup'] = 'Error creating/updating group {$a}';
|
||||
$string['erroreditgrouping'] = 'Error creating/updating grouping {$a}';
|
||||
$string['errorinvalidgroup'] = 'Error, invalid group {$a}';
|
||||
$string['errorremovenotpermitted'] = 'You do not have permission to remove automatically-added group member {$a}';
|
||||
$string['errorselectone'] = 'Please select a single group before choosing this option';
|
||||
$string['errorselectsome'] = 'Please select one or more groups before choosing this option';
|
||||
$string['evenallocation'] = 'Note: To keep group allocation even, the actual number of members per group differs from the number you specified.';
|
||||
|
||||
@@ -100,6 +100,7 @@ $string['error'] = 'An unknown error occurred!';
|
||||
$string['errornotyourfile'] = 'You cannot pick file which is not added by your';
|
||||
$string['erroruniquename'] = 'Repository instance name should be unique';
|
||||
$string['errorpostmaxsize'] = 'The uploaded file may exceed max_post_size directive in php.ini.';
|
||||
$string['errorwhiledownload'] = 'An error occured while downloading the file: {$a}';
|
||||
$string['existingrepository'] = 'This repository already exists';
|
||||
$string['federatedsearch'] = 'Federated search';
|
||||
$string['fileexists'] = 'File name already being used, please use another name';
|
||||
|
||||
+1
-1
@@ -1238,7 +1238,7 @@ class block_manager {
|
||||
|
||||
$systemcontext = context_system::instance();
|
||||
$frontpagecontext = context_course::instance(SITEID);
|
||||
$parentcontext = get_context_instance_by_id($data->bui_parentcontextid);
|
||||
$parentcontext = context::instance_by_id($data->bui_parentcontextid);
|
||||
|
||||
// Updating stickiness and contexts. See MDL-21375 for details.
|
||||
if (has_capability('moodle/site:manageblocks', $parentcontext)) { // Check permissions in destination
|
||||
|
||||
+12
-10
@@ -176,7 +176,7 @@ class boxclient {
|
||||
$params['action'] = 'get_account_tree';
|
||||
$params['onelevel'] = 1;
|
||||
$params['params[]'] = 'nozip';
|
||||
$c = new curl(array('debug'=>$this->debug, 'cache'=>true, 'module_cache'=>'repository'));
|
||||
$c = new curl(array('debug'=>$this->debug));
|
||||
$c->setopt(array('CURLOPT_FOLLOWLOCATION'=>1));
|
||||
try {
|
||||
$args = array();
|
||||
@@ -196,23 +196,25 @@ class boxclient {
|
||||
* Get box.net file info
|
||||
*
|
||||
* @param string $fileid
|
||||
* @return string|null
|
||||
* @param int $timeout request timeout in seconds
|
||||
* @return stdClass|null
|
||||
*/
|
||||
function get_file_info($fileid) {
|
||||
function get_file_info($fileid, $timeout = 0) {
|
||||
$this->_clearErrors();
|
||||
$params = array();
|
||||
$params['action'] = 'get_file_info';
|
||||
$params['file_id'] = $fileid;
|
||||
$params['auth_token'] = $this->auth_token;
|
||||
$params['api_key'] = $this->api_key;
|
||||
$http = new curl(array('debug'=>$this->debug, 'cache'=>true, 'module_cache'=>'repository'));
|
||||
$xml = $http->get($this->_box_api_url, $params);
|
||||
$o = simplexml_load_string(trim($xml));
|
||||
if ($o->status == 's_get_file_info') {
|
||||
return $o->info;
|
||||
} else {
|
||||
return null;
|
||||
$http = new curl(array('debug'=>$this->debug));
|
||||
$xml = $http->get($this->_box_api_url, $params, array('timeout' => $timeout));
|
||||
if (!$http->get_errno()) {
|
||||
$o = simplexml_load_string(trim($xml));
|
||||
if ($o->status == 's_get_file_info') {
|
||||
return $o->info;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -621,16 +621,20 @@ class completion_info {
|
||||
debugging('set_module_viewed must be called before header is printed',
|
||||
DEBUG_DEVELOPER);
|
||||
}
|
||||
|
||||
// Don't do anything if view condition is not turned on
|
||||
if ($cm->completionview == COMPLETION_VIEW_NOT_REQUIRED || !$this->is_enabled($cm)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get current completion state
|
||||
$data = $this->get_data($cm, $userid);
|
||||
$data = $this->get_data($cm, false, $userid);
|
||||
|
||||
// If we already viewed it, don't do anything
|
||||
if ($data->viewed == COMPLETION_VIEWED) {
|
||||
return;
|
||||
}
|
||||
|
||||
// OK, change state, save it, and update completion
|
||||
$data->viewed = COMPLETION_VIEWED;
|
||||
$this->internal_set_data($cm, $data);
|
||||
|
||||
@@ -466,10 +466,6 @@ function cron_run() {
|
||||
$fs = get_file_storage();
|
||||
$fs->cron();
|
||||
|
||||
mtrace("Clean up cached external files");
|
||||
// 1 week
|
||||
cache_file::cleanup(array(), 60 * 60 * 24 * 7);
|
||||
|
||||
mtrace("Cron script completed correctly");
|
||||
|
||||
$difftime = microtime_diff($starttime, microtime());
|
||||
|
||||
+44
-40
@@ -76,9 +76,10 @@ class csv_import_reader {
|
||||
* @param string $encoding content encoding
|
||||
* @param string $delimiter_name separator (comma, semicolon, colon, cfg)
|
||||
* @param string $column_validation name of function for columns validation, must have one param $columns
|
||||
* @param string $enclosure field wrapper. One character only.
|
||||
* @return bool false if error, count of data lines if ok; use get_error() to get error string
|
||||
*/
|
||||
function load_csv_content(&$content, $encoding, $delimiter_name, $column_validation=null) {
|
||||
function load_csv_content(&$content, $encoding, $delimiter_name, $column_validation=null, $enclosure='"') {
|
||||
global $USER, $CFG;
|
||||
|
||||
$this->close();
|
||||
@@ -89,62 +90,65 @@ class csv_import_reader {
|
||||
$content = textlib::trim_utf8_bom($content);
|
||||
// Fix mac/dos newlines
|
||||
$content = preg_replace('!\r\n?!', "\n", $content);
|
||||
// is there anyting in file?
|
||||
$columns = strtok($content, "\n");
|
||||
if ($columns === false) {
|
||||
$this->_error = get_string('csvemptyfile', 'error');
|
||||
return false;
|
||||
}
|
||||
|
||||
$csv_delimiter = csv_import_reader::get_delimiter($delimiter_name);
|
||||
$csv_encode = csv_import_reader::get_encoded_delimiter($delimiter_name);
|
||||
// $csv_encode = csv_import_reader::get_encoded_delimiter($delimiter_name);
|
||||
|
||||
// create a temporary file and store the csv file there.
|
||||
$fp = tmpfile();
|
||||
fwrite($fp, $content);
|
||||
fseek($fp, 0);
|
||||
// Create an array to store the imported data for error checking.
|
||||
$columns = array();
|
||||
// str_getcsv doesn't iterate through the csv data properly. It has
|
||||
// problems with line returns.
|
||||
while ($fgetdata = fgetcsv($fp, 0, $csv_delimiter, $enclosure)) {
|
||||
$columns[] = $fgetdata;
|
||||
}
|
||||
$col_count = 0;
|
||||
|
||||
// process header - list of columns
|
||||
$columns = explode($csv_delimiter, $columns);
|
||||
$col_count = count($columns);
|
||||
if ($col_count === 0) {
|
||||
if (!isset($columns[0])) {
|
||||
$this->_error = get_string('csvemptyfile', 'error');
|
||||
fclose($fp);
|
||||
return false;
|
||||
} else {
|
||||
$col_count = count($columns[0]);
|
||||
}
|
||||
|
||||
foreach ($columns as $key=>$value) {
|
||||
$columns[$key] = str_replace($csv_encode, $csv_delimiter, trim($value));
|
||||
}
|
||||
// Column validation.
|
||||
if ($column_validation) {
|
||||
$result = $column_validation($columns);
|
||||
$result = $column_validation($columns[0]);
|
||||
if ($result !== true) {
|
||||
$this->_error = $result;
|
||||
fclose($fp);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
$this->_columns = $columns; // cached columns
|
||||
|
||||
// open file for writing
|
||||
$filename = $CFG->tempdir.'/csvimport/'.$this->_type.'/'.$USER->id.'/'.$this->_iid;
|
||||
$fp = fopen($filename, "w");
|
||||
fwrite($fp, serialize($columns)."\n");
|
||||
|
||||
// again - do we have any data for processing?
|
||||
$line = strtok("\n");
|
||||
$data_count = 0;
|
||||
while ($line !== false) {
|
||||
$line = explode($csv_delimiter, $line);
|
||||
foreach ($line as $key=>$value) {
|
||||
$line[$key] = str_replace($csv_encode, $csv_delimiter, trim($value));
|
||||
}
|
||||
if (count($line) !== $col_count) {
|
||||
// this is critical!!
|
||||
$this->_columns = $columns[0]; // cached columns
|
||||
// check to make sure that the data columns match up with the headers.
|
||||
foreach ($columns as $rowdata) {
|
||||
if (count($rowdata) !== $col_count) {
|
||||
$this->_error = get_string('csvweirdcolumns', 'error');
|
||||
fclose($fp);
|
||||
$this->cleanup();
|
||||
return false;
|
||||
}
|
||||
fwrite($fp, serialize($line)."\n");
|
||||
$data_count++;
|
||||
$line = strtok("\n");
|
||||
}
|
||||
|
||||
$filename = $CFG->tempdir.'/csvimport/'.$this->_type.'/'.$USER->id.'/'.$this->_iid;
|
||||
$filepointer = fopen($filename, "w");
|
||||
// The information has been stored in csv format, as serialized data has issues
|
||||
// with special characters and line returns.
|
||||
$storedata = csv_export_writer::print_array($columns, ',', '"', true);
|
||||
fwrite($filepointer, $storedata);
|
||||
|
||||
fclose($fp);
|
||||
return $data_count;
|
||||
fclose($filepointer);
|
||||
|
||||
$datacount = count($columns);
|
||||
return $datacount;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,12 +168,12 @@ class csv_import_reader {
|
||||
return false;
|
||||
}
|
||||
$fp = fopen($filename, "r");
|
||||
$line = fgets($fp);
|
||||
$line = fgetcsv($fp);
|
||||
fclose($fp);
|
||||
if ($line === false) {
|
||||
return false;
|
||||
}
|
||||
$this->_columns = unserialize($line);
|
||||
$this->_columns = $line;
|
||||
return $this->_columns;
|
||||
}
|
||||
|
||||
@@ -194,7 +198,7 @@ class csv_import_reader {
|
||||
return false;
|
||||
}
|
||||
//skip header
|
||||
return (fgets($this->_fp) !== false);
|
||||
return (fgetcsv($this->_fp) !== false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -206,8 +210,8 @@ class csv_import_reader {
|
||||
if (empty($this->_fp) or feof($this->_fp)) {
|
||||
return false;
|
||||
}
|
||||
if ($ser = fgets($this->_fp)) {
|
||||
return unserialize($ser);
|
||||
if ($ser = fgetcsv($this->_fp)) {
|
||||
return $ser;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
+18
-9
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<XMLDB PATH="lib/db" VERSION="20120717" COMMENT="XMLDB file for core Moodle tables"
|
||||
<XMLDB PATH="lib/db" VERSION="20120825" COMMENT="XMLDB file for core Moodle tables"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
|
||||
>
|
||||
@@ -235,14 +235,21 @@
|
||||
<FIELD NAME="customint1" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Custom - general int" PREVIOUS="roleid" NEXT="customint2"/>
|
||||
<FIELD NAME="customint2" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Custom - general int" PREVIOUS="customint1" NEXT="customint3"/>
|
||||
<FIELD NAME="customint3" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Custom - general int" PREVIOUS="customint2" NEXT="customint4"/>
|
||||
<FIELD NAME="customint4" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Custom - general int" PREVIOUS="customint3" NEXT="customchar1"/>
|
||||
<FIELD NAME="customchar1" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="Custom - general short name" PREVIOUS="customint4" NEXT="customchar2"/>
|
||||
<FIELD NAME="customchar2" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="Custom - general short name" PREVIOUS="customchar1" NEXT="customdec1"/>
|
||||
<FIELD NAME="customdec1" TYPE="number" LENGTH="12" NOTNULL="false" SEQUENCE="false" DECIMALS="7" COMMENT="Custom - general decimal" PREVIOUS="customchar2" NEXT="customdec2"/>
|
||||
<FIELD NAME="customint4" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Custom - general int" PREVIOUS="customint3" NEXT="customint5"/>
|
||||
<FIELD NAME="customint5" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Custom - general int" PREVIOUS="customint4" NEXT="customint6"/>
|
||||
<FIELD NAME="customint6" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Custom - general int" PREVIOUS="customint5" NEXT="customint7"/>
|
||||
<FIELD NAME="customint7" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Custom - general int" PREVIOUS="customint6" NEXT="customint8"/>
|
||||
<FIELD NAME="customint8" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Custom - general int" PREVIOUS="customint7" NEXT="customchar1"/>
|
||||
<FIELD NAME="customchar1" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="Custom - general short name" PREVIOUS="customint8" NEXT="customchar2"/>
|
||||
<FIELD NAME="customchar2" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="Custom - general short name" PREVIOUS="customchar1" NEXT="customchar3"/>
|
||||
<FIELD NAME="customchar3" TYPE="char" LENGTH="1333" NOTNULL="false" SEQUENCE="false" COMMENT="Custom - general short name" PREVIOUS="customchar2" NEXT="customdec1"/>
|
||||
<FIELD NAME="customdec1" TYPE="number" LENGTH="12" NOTNULL="false" SEQUENCE="false" DECIMALS="7" COMMENT="Custom - general decimal" PREVIOUS="customchar3" NEXT="customdec2"/>
|
||||
<FIELD NAME="customdec2" TYPE="number" LENGTH="12" NOTNULL="false" SEQUENCE="false" DECIMALS="7" COMMENT="Custom - general decimal" PREVIOUS="customdec1" NEXT="customtext1"/>
|
||||
<FIELD NAME="customtext1" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Custom - general text" PREVIOUS="customdec2" NEXT="customtext2"/>
|
||||
<FIELD NAME="customtext2" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Custom - general text" PREVIOUS="customtext1" NEXT="timecreated"/>
|
||||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="customtext2" NEXT="timemodified"/>
|
||||
<FIELD NAME="customtext2" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Custom - general text" PREVIOUS="customtext1" NEXT="customtext3"/>
|
||||
<FIELD NAME="customtext3" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Custom - general text" PREVIOUS="customtext2" NEXT="customtext4"/>
|
||||
<FIELD NAME="customtext4" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Custom - general text" PREVIOUS="customtext3" NEXT="timecreated"/>
|
||||
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="customtext4" NEXT="timemodified"/>
|
||||
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="timecreated"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
@@ -2090,7 +2097,9 @@
|
||||
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true" NEXT="groupid"/>
|
||||
<FIELD NAME="groupid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="userid"/>
|
||||
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="groupid" NEXT="timeadded"/>
|
||||
<FIELD NAME="timeadded" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="userid"/>
|
||||
<FIELD NAME="timeadded" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="userid" NEXT="component"/>
|
||||
<FIELD NAME="component" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" COMMENT="Defines the Moodle component which added this group membership (e.g. 'auth_myplugin'), or blank if it was added manually. (Entries which are created by a Moodle component cannot be removed in the normal user interface.)" PREVIOUS="timeadded" NEXT="itemid"/>
|
||||
<FIELD NAME="itemid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="If the 'component' field is set, this can be used to define the instance of the component that created the entry. Otherwise should be left as default (0)." PREVIOUS="component"/>
|
||||
</FIELDS>
|
||||
<KEYS>
|
||||
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="groupid"/>
|
||||
@@ -2857,4 +2866,4 @@
|
||||
</KEYS>
|
||||
</TABLE>
|
||||
</TABLES>
|
||||
</XMLDB>
|
||||
</XMLDB>
|
||||
|
||||
@@ -1119,6 +1119,70 @@ function xmldb_main_upgrade($oldversion) {
|
||||
upgrade_main_savepoint(true, 2012081600.01);
|
||||
}
|
||||
|
||||
if ($oldversion < 2012082300.01) {
|
||||
// Add more custom enrol fields.
|
||||
$table = new xmldb_table('enrol');
|
||||
|
||||
$field = new xmldb_field('customint5', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'customint4');
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
$field = new xmldb_field('customint6', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'customint5');
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
$field = new xmldb_field('customint7', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'customint6');
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
$field = new xmldb_field('customint8', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'customint7');
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
$field = new xmldb_field('customchar3', XMLDB_TYPE_CHAR, '1333', null, null, null, null, 'customchar2');
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
$field = new xmldb_field('customtext3', XMLDB_TYPE_TEXT, null, null, null, null, null, 'customtext2');
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
$field = new xmldb_field('customtext4', XMLDB_TYPE_TEXT, null, null, null, null, null, 'customtext3');
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// Main savepoint reached.
|
||||
upgrade_main_savepoint(true, 2012082300.01);
|
||||
}
|
||||
|
||||
if ($oldversion < 2012082300.02) {
|
||||
// Define field component to be added to groups_members
|
||||
$table = new xmldb_table('groups_members');
|
||||
$field = new xmldb_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'timeadded');
|
||||
|
||||
// Conditionally launch add field component
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// Define field itemid to be added to groups_members
|
||||
$field = new xmldb_field('itemid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'component');
|
||||
|
||||
// Conditionally launch add field itemid
|
||||
if (!$dbman->field_exists($table, $field)) {
|
||||
$dbman->add_field($table, $field);
|
||||
}
|
||||
|
||||
// Main savepoint reached
|
||||
upgrade_main_savepoint(true, 2012082300.02);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -26,12 +26,205 @@ defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once("$CFG->libdir/pluginlib.php");
|
||||
|
||||
|
||||
/**
|
||||
* Editor subplugin info class.
|
||||
*
|
||||
* @package editor_tinymce
|
||||
* @copyright 2012 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class plugininfo_tinymce extends plugininfo_base {
|
||||
|
||||
public function get_uninstall_url() {
|
||||
return new moodle_url('/lib/editor/tinymce/subplugins.php', array('delete' => $this->name, 'sesskey' => sesskey()));
|
||||
}
|
||||
|
||||
public function get_settings_url() {
|
||||
global $CFG;
|
||||
if (file_exists("$CFG->dirroot/lib/editor/tinymce/plugins/$this->name/settings.php")) {
|
||||
return new moodle_url('/admin/settings.php', array('section'=>'tinymce'.$this->name.'settings'));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function is_enabled() {
|
||||
static $disabledsubplugins = null; // TODO: MDL-34344 remove this once get_config() is cached via MUC!
|
||||
|
||||
if (is_null($disabledsubplugins)) {
|
||||
$disabledsubplugins = array();
|
||||
$config = get_config('editor_tinymce', 'disabledsubplugins');
|
||||
if ($config) {
|
||||
$config = explode(',', $config);
|
||||
foreach ($config as $sp) {
|
||||
$sp = trim($sp);
|
||||
if ($sp !== '') {
|
||||
$disabledsubplugins[$sp] = $sp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !isset($disabledsubplugins[$this->name]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Special class for TinyMCE subplugin administration.
|
||||
*
|
||||
* @package editor_tinymce
|
||||
* @copyright 2012 Petr Skoda {@link http://skodak.org}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tiynce_subplugins_settings extends admin_setting {
|
||||
public function __construct() {
|
||||
$this->nosave = true;
|
||||
parent::__construct('tinymcesubplugins', get_string('subplugintype_tinymce_plural', 'editor_tinymce'), '', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Always returns true, does nothing.
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
public function get_setting() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Always returns true, does nothing.
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
public function get_defaultsetting() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Always returns '', does not write anything.
|
||||
*
|
||||
* @param string $data
|
||||
* @return string Always returns ''
|
||||
*/
|
||||
public function write_setting($data) {
|
||||
// Do not write any setting.
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if $query is one of the available subplugins.
|
||||
*
|
||||
* @param string $query The string to search for
|
||||
* @return bool Returns true if found, false if not
|
||||
*/
|
||||
public function is_related($query) {
|
||||
if (parent::is_related($query)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$subplugins = get_plugin_list('tinymce');
|
||||
foreach ($subplugins as $name=>$dir) {
|
||||
if (stripos($name, $query) !== false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$namestr = get_string('pluginname', 'tinymce_'.$name);
|
||||
if (strpos(textlib::strtolower($namestr), textlib::strtolower($query)) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the XHTML to display the control.
|
||||
*
|
||||
* @param string $data Unused
|
||||
* @param string $query
|
||||
* @return string
|
||||
*/
|
||||
public function output_html($data, $query='') {
|
||||
global $CFG, $OUTPUT;
|
||||
require_once("$CFG->libdir/editorlib.php");
|
||||
require_once("$CFG->libdir/pluginlib.php");
|
||||
require_once(__DIR__.'/lib.php');
|
||||
$tinymce = new tinymce_texteditor();
|
||||
$pluginmanager = plugin_manager::instance();
|
||||
|
||||
// display strings
|
||||
$strbuttons = get_string('availablebuttons', 'editor_tinymce');
|
||||
$strdisable = get_string('disable');
|
||||
$strenable = get_string('enable');
|
||||
$strname = get_string('name');
|
||||
$strsettings = get_string('settings');
|
||||
$struninstall = get_string('uninstallplugin', 'admin');
|
||||
$strversion = get_string('version');
|
||||
|
||||
$subplugins = get_plugin_list('tinymce');
|
||||
|
||||
$return = $OUTPUT->heading(get_string('subplugintype_tinymce_plural', 'editor_tinymce'), 3, 'main', true);
|
||||
$return .= $OUTPUT->box_start('generalbox tinymcesubplugins');
|
||||
|
||||
$table = new html_table();
|
||||
$table->head = array($strname, $strbuttons, $strversion, $strenable, $strsettings, $struninstall);
|
||||
$table->align = array('left', 'left', 'center', 'center', 'center', 'center');
|
||||
$table->data = array();
|
||||
$table->width = '100%';
|
||||
|
||||
// Iterate through subplugins.
|
||||
foreach ($subplugins as $name => $dir) {
|
||||
$namestr = get_string('pluginname', 'tinymce_'.$name);
|
||||
$version = get_config('tinymce_'.$name, 'version');
|
||||
if ($version === false) {
|
||||
$version = '';
|
||||
}
|
||||
$plugin = $tinymce->get_plugin($name);
|
||||
$plugininfo = $pluginmanager->get_plugin_info('tinymce_'.$name);
|
||||
|
||||
// Add hide/show link.
|
||||
if (!$version) {
|
||||
$hideshow = '';
|
||||
$displayname = html_writer::tag('span', $name, array('class'=>'error'));
|
||||
} else if ($plugininfo->is_enabled()) {
|
||||
$url = new moodle_url('/lib/editor/tinymce/subplugins.php', array('sesskey'=>sesskey(), 'return'=>'settings', 'disable'=>$name));
|
||||
$hideshow = html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('i/hide'), 'class'=>'icon', 'alt'=>$strdisable));
|
||||
$hideshow = html_writer::link($url, $hideshow);
|
||||
$displayname = html_writer::tag('span', $namestr);
|
||||
} else {
|
||||
$url = new moodle_url('/lib/editor/tinymce/subplugins.php', array('sesskey'=>sesskey(), 'return'=>'settings', 'enable'=>$name));
|
||||
$hideshow = html_writer::empty_tag('img', array('src'=>$OUTPUT->pix_url('i/show'), 'class'=>'icon', 'alt'=>$strenable));
|
||||
$hideshow = html_writer::link($url, $hideshow);
|
||||
$displayname = html_writer::tag('span', $namestr, array('class'=>'dimmed_text'));
|
||||
}
|
||||
|
||||
// Add available buttons.
|
||||
$buttons = implode(', ', $plugin->get_buttons());
|
||||
$buttons = html_writer::tag('span', $buttons, array('class'=>'tinymcebuttons'));
|
||||
|
||||
// Add settings link.
|
||||
if (!$version) {
|
||||
$settings = '';
|
||||
} else if ($url = $plugininfo->get_settings_url()) {
|
||||
$settings = html_writer::link($url, $strsettings);
|
||||
} else {
|
||||
$settings = '';
|
||||
}
|
||||
|
||||
// Add uninstall info.
|
||||
if ($version) {
|
||||
$url = new moodle_url($plugininfo->get_uninstall_url(), array('return'=>'settings'));
|
||||
$uninstall = html_writer::link($url, $struninstall);
|
||||
} else {
|
||||
$uninstall = '';
|
||||
}
|
||||
|
||||
// Add a row to the table.
|
||||
$table->data[] = array($displayname, $buttons, $version, $hideshow, $settings, $uninstall);
|
||||
}
|
||||
$return .= html_writer::table($table);
|
||||
$return .= html_writer::tag('p', get_string('tablenosave', 'admin'));
|
||||
$return .= $OUTPUT->box_end();
|
||||
return highlight($query, $return);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,12 @@ abstract class editor_tinymce_plugin {
|
||||
/** @var string Plugin folder */
|
||||
protected $plugin;
|
||||
|
||||
/** @var array Plugin settings */
|
||||
protected $config = null;
|
||||
|
||||
/** @var array list of buttons defined by this plugin */
|
||||
protected $buttons = array();
|
||||
|
||||
/**
|
||||
* @param string $plugin Name of folder
|
||||
*/
|
||||
@@ -44,6 +50,64 @@ abstract class editor_tinymce_plugin {
|
||||
$this->plugin = $plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of buttons defined by this plugin.
|
||||
* useful mostly as information when setting custom toolbar.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_buttons() {
|
||||
return $this->buttons;
|
||||
}
|
||||
/**
|
||||
* Makes sure config is loaded and cached.
|
||||
* @return void
|
||||
*/
|
||||
protected function load_config() {
|
||||
if (!isset($this->config)) {
|
||||
$name = $this->get_name();
|
||||
$this->config = get_config("tinymce_$name");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns plugin config value.
|
||||
* @param string $name
|
||||
* @param string $default value if config does not exist yet
|
||||
* @return string value or default
|
||||
*/
|
||||
public function get_config($name, $default = null) {
|
||||
$this->load_config();
|
||||
return isset($this->config->$name) ? $this->config->$name : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets plugin config value.
|
||||
* @param string $name name of config
|
||||
* @param string $value string config value, null means delete
|
||||
* @return string value
|
||||
*/
|
||||
public function set_config($name, $value) {
|
||||
$pluginname = $this->get_name();
|
||||
$this->load_config();
|
||||
if ($value === null) {
|
||||
unset($this->config->$name);
|
||||
} else {
|
||||
$this->config->$name = $value;
|
||||
}
|
||||
set_config($name, $value, "tinymce_$pluginname");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns name of this tinymce plugin.
|
||||
* @return string
|
||||
*/
|
||||
public function get_name() {
|
||||
// All class names start with "tinymce_".
|
||||
$words = explode('_', get_class($this), 2);
|
||||
return $words[1];
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjusts TinyMCE init parameters for this plugin.
|
||||
*
|
||||
@@ -274,9 +338,23 @@ abstract class editor_tinymce_plugin {
|
||||
// Get list of plugin directories.
|
||||
$plugins = get_plugin_list('tinymce');
|
||||
|
||||
// Get list of disabled subplugins.
|
||||
$disabled = array();
|
||||
if ($params['moodle_config']->disabledsubplugins) {
|
||||
foreach (explode(',', $params['moodle_config']->disabledsubplugins) as $sp) {
|
||||
$sp = trim($sp);
|
||||
if ($sp !== '') {
|
||||
$disabled[$sp] = $sp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Construct all the plugins.
|
||||
$pluginobjects = array();
|
||||
foreach ($plugins as $plugin => $dir) {
|
||||
if (isset($disabled[$plugin])) {
|
||||
continue;
|
||||
}
|
||||
require_once($dir . '/lib.php');
|
||||
$classname = 'tinymce_' . $plugin;
|
||||
$pluginobjects[] = new $classname($plugin);
|
||||
|
||||
@@ -24,12 +24,17 @@
|
||||
|
||||
|
||||
//== Custom Moodle strings that are not part of upstream TinyMCE ==
|
||||
$string['availablebuttons'] = 'Available buttons';
|
||||
$string['common:browseimage'] = 'Find or upload an image...';
|
||||
$string['common:browsemedia'] = 'Find or upload a sound, video or applet...';
|
||||
$string['customtoolbar'] = 'Custom editor toolbar';
|
||||
$string['customtoolbar_desc'] = 'Each line contains a list of comma separated button names, use "|" as a group separator. Leave empty if you want standard toolbar. See <a href="{$a}" target="_blank">{$a}</a> for the list of default TinyMCE buttons.';
|
||||
$string['fontselectlist'] = 'Available fonts list';
|
||||
$string['media_dlg:filename'] = 'Filename';
|
||||
$string['pluginname'] = 'TinyMCE HTML editor';
|
||||
$string['settings'] = 'General settings';
|
||||
$string['subplugindeleteconfirm'] = 'You are about to completely delete TinyMCE subplugin \'{$a}\'. This will completely delete everything in the database associated with this subplugin. Are you SURE you want to continue?';
|
||||
$string['subplugintype_tinymce_plural'] = 'Plugins';
|
||||
|
||||
|
||||
// == TinyMCE upstream lang strings from all standard upstream plugins ==
|
||||
|
||||
@@ -122,6 +122,9 @@ class tinymce_texteditor extends texteditor {
|
||||
$context = empty($options['context']) ? context_system::instance() : $options['context'];
|
||||
|
||||
$config = get_config('editor_tinymce');
|
||||
if (!isset($config->disabledsubplugins)) {
|
||||
$config->disabledsubplugins = '';
|
||||
}
|
||||
|
||||
$fontselectlist = empty($config->fontselectlist) ? '' : $config->fontselectlist;
|
||||
$fontbutton = ($fontselectlist === '') ? '' : 'fontselect,';
|
||||
@@ -177,11 +180,6 @@ class tinymce_texteditor extends texteditor {
|
||||
$params['extended_valid_elements'] = 'nolink,tex,algebra,lang[lang]';
|
||||
$params['custom_elements'] = 'nolink,~tex,~algebra,lang';
|
||||
|
||||
if (empty($options['legacy'])) {
|
||||
if (isset($options['maxfiles']) and $options['maxfiles'] != 0) {
|
||||
$params['file_browser_callback'] = "M.editor_tinymce.filepicker";
|
||||
}
|
||||
}
|
||||
//Add onblur event for client side text validation
|
||||
if (!empty($options['required'])) {
|
||||
$params['init_instance_callback'] = 'M.editor_tinymce.onblur_event';
|
||||
@@ -190,12 +188,52 @@ class tinymce_texteditor extends texteditor {
|
||||
// Allow plugins to adjust parameters.
|
||||
editor_tinymce_plugin::all_update_init_params($params, $context, $options);
|
||||
|
||||
// Should we override the default toolbar layout unconditionally?
|
||||
$customtoolbar = self::parse_toolbar_setting($config->customtoolbar);
|
||||
if ($customtoolbar) {
|
||||
unset($params['theme_advanced_buttons1']);
|
||||
unset($params['theme_advanced_buttons2']);
|
||||
unset($params['theme_advanced_buttons3']);
|
||||
unset($params['theme_advanced_buttons4']);
|
||||
$i = 1;
|
||||
foreach ($customtoolbar as $line) {
|
||||
$params['theme_advanced_buttons'.$i] = $line;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove temporary parameters.
|
||||
unset($params['moodle_config']);
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the custom toolbar setting.
|
||||
* @param string $customtoolbar
|
||||
* @return array csv toolbar lines
|
||||
*/
|
||||
public static function parse_toolbar_setting($customtoolbar) {
|
||||
$result = array();
|
||||
$customtoolbar = trim($customtoolbar);
|
||||
if ($customtoolbar === '') {
|
||||
return $result;
|
||||
}
|
||||
$customtoolbar = str_replace("\r", "\n", $customtoolbar);
|
||||
$customtoolbar = strtolower($customtoolbar);
|
||||
foreach (explode("\n", $customtoolbar) as $line) {
|
||||
$line = preg_replace('/[^a-z0-9_,\|\-]/', ',', $line);
|
||||
$line = str_replace('|', ',|,', $line);
|
||||
$line = preg_replace('/,,+/', ',', $line);
|
||||
$line = trim($line, ',|');
|
||||
if ($line === '') {
|
||||
continue;
|
||||
}
|
||||
$result[] = $line;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a named plugin object. Will cause fatal error if plugin doesn't
|
||||
* exist. This is intended for use by plugin files themselves.
|
||||
|
||||
@@ -24,6 +24,9 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tinymce_dragmath extends editor_tinymce_plugin {
|
||||
/** @var array list of buttons defined by this plugin */
|
||||
protected $buttons = array('dragmath');
|
||||
|
||||
protected function update_init_params(array &$params, context $context,
|
||||
array $options = null) {
|
||||
|
||||
|
||||
@@ -24,6 +24,9 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tinymce_moodleemoticon extends editor_tinymce_plugin {
|
||||
/** @var array list of buttons defined by this plugin */
|
||||
protected $buttons = array('moodleemoticon');
|
||||
|
||||
protected function update_init_params(array &$params, context $context,
|
||||
array $options = null) {
|
||||
global $OUTPUT;
|
||||
|
||||
@@ -24,9 +24,19 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tinymce_moodleimage extends editor_tinymce_plugin {
|
||||
/** @var array list of buttons defined by this plugin */
|
||||
protected $buttons = array('image');
|
||||
|
||||
protected function update_init_params(array &$params, context $context,
|
||||
array $options = null) {
|
||||
|
||||
// Add file picker callback.
|
||||
if (empty($options['legacy'])) {
|
||||
if (isset($options['maxfiles']) and $options['maxfiles'] != 0) {
|
||||
$params['file_browser_callback'] = "M.editor_tinymce.filepicker";
|
||||
}
|
||||
}
|
||||
|
||||
// This plugin overrides standard 'image' button, no need to insert new button.
|
||||
|
||||
// Add JS file, which uses default name.
|
||||
|
||||
@@ -24,9 +24,19 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tinymce_moodlemedia extends editor_tinymce_plugin {
|
||||
/** @var array list of buttons defined by this plugin */
|
||||
protected $buttons = array('moodlemedia');
|
||||
|
||||
protected function update_init_params(array &$params, context $context,
|
||||
array $options = null) {
|
||||
|
||||
// Add file picker callback.
|
||||
if (empty($options['legacy'])) {
|
||||
if (isset($options['maxfiles']) and $options['maxfiles'] != 0) {
|
||||
$params['file_browser_callback'] = "M.editor_tinymce.filepicker";
|
||||
}
|
||||
}
|
||||
|
||||
// Add button after emoticon button in advancedbuttons3.
|
||||
$added = $this->add_button_after($params, 3, 'moodlemedia', 'moodleemoticon', false);
|
||||
|
||||
|
||||
@@ -24,6 +24,9 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tinymce_moodlenolink extends editor_tinymce_plugin {
|
||||
/** @var array list of buttons defined by this plugin */
|
||||
protected $buttons = array('moodlenolink');
|
||||
|
||||
protected function update_init_params(array &$params, context $context,
|
||||
array $options = null) {
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user