MDL-8307 Course: Course requests can suggest a category

This commit is contained in:
Frederic Massart 2012-08-16 14:10:39 +08:00
parent 935c3d5ed2
commit 59b9a14063
8 changed files with 56 additions and 8 deletions

View File

@ -85,6 +85,7 @@ if ($hassiteconfig
$temp = new admin_settingpage('courserequest', new lang_string('courserequest'));
$temp->add(new admin_setting_configcheckbox('enablecourserequests', new lang_string('enablecourserequests', 'admin'), new lang_string('configenablecourserequests', 'admin'), 0));
$temp->add(new admin_settings_coursecat_select('defaultrequestcategory', new lang_string('defaultrequestcategory', 'admin'), new lang_string('configdefaultrequestcategory', 'admin'), 1));
$temp->add(new admin_setting_configcheckbox('requestcategoryselection', new lang_string('requestcategoryselection', 'admin'), new lang_string('configrequestcategoryselection', 'admin'), 0));
$temp->add(new admin_setting_users_with_capability('courserequestnotify', new lang_string('courserequestnotify', 'admin'), new lang_string('configcourserequestnotify2', 'admin'), array(), 'moodle/site:approvecourse'));
$ADMIN->add('courses', $temp);

View File

@ -4144,6 +4144,11 @@ class course_request {
global $USER, $DB, $CFG;
$data->requester = $USER->id;
// Setting the default category is none set.
if (empty($data->category) || empty($CFG->requestcategoryselection)) {
$data->category = $CFG->defaultrequestcategory;
}
// Summary is a required field so copy the text over
$data->summary = $data->summary_editor['text'];
$data->summaryformat = $data->summary_editor['format'];
@ -4293,7 +4298,6 @@ class course_request {
$user = $DB->get_record('user', array('id' => $this->properties->requester, 'deleted'=>0), '*', MUST_EXIST);
$category = get_course_category($CFG->defaultrequestcategory);
$courseconfig = get_config('moodlecourse');
// Transfer appropriate settings
@ -4302,6 +4306,14 @@ class course_request {
unset($data->reason);
unset($data->requester);
// If the current user does not have the rights to change the category, or if the
// category does not exist, we set the default category to the course to be approved.
// The system level is used because the capability moodle/site:approvecourse is based on a system level.
if (!has_capability('moodle/course:changecategory', context_system::instance()) ||
(!$category = get_course_category($data->category))) {
$category = get_course_category($CFG->defaultrequestcategory);
}
// Set category
$data->category = $category->id;
$data->sortorder = $category->sortorder; // place as the first in category

View File

@ -101,8 +101,8 @@ if (empty($pending)) {
$table = new html_table();
$table->attributes['class'] = 'pendingcourserequests generaltable';
$table->align = array('center', 'center', 'center', 'center', 'center', 'center');
$table->head = array(get_string('shortnamecourse'), get_string('fullnamecourse'),
get_string('requestedby'), get_string('summary'), get_string('requestreason'), get_string('action'));
$table->head = array(get_string('shortnamecourse'), get_string('fullnamecourse'), get_string('requestedby'),
get_string('summary'), get_string('category'), get_string('requestreason'), get_string('action'));
foreach ($pending as $course) {
$course = new course_request($course);
@ -110,11 +110,22 @@ if (empty($pending)) {
// Check here for shortname collisions and warn about them.
$course->check_shortname_collision();
// Retreiving category name.
// If the user does not have the capability to change the category, we fallback on the default one.
// Else, the category proposed is fetched, but we fallback on the default one if we can't find it.
// It is just a matter of displaying the right information because the logic when approving the category
// proceeds the same way. The system context level is used as moodle/site:approvecourse uses it.
if (!has_capability('moodle/course:changecategory', context_system::instance()) ||
(!$category = get_course_category($course->category))) {
$category = get_course_category($CFG->defaultrequestcategory);
}
$row = array();
$row[] = format_string($course->shortname);
$row[] = format_string($course->fullname);
$row[] = fullname($course->get_requester());
$row[] = $course->summary;
$row[] = format_string($category->name);
$row[] = format_string($course->reason);
$row[] = $OUTPUT->single_button(new moodle_url($baseurl, array('approve' => $course->id, 'sesskey' => sesskey())), get_string('approve'), 'get') .
$OUTPUT->single_button(new moodle_url($baseurl, array('reject' => $course->id)), get_string('rejectdots'), 'get');

View File

@ -42,7 +42,7 @@ require_once($CFG->libdir.'/formslib.php');
*/
class course_request_form extends moodleform {
function definition() {
global $DB, $USER;
global $CFG, $DB, $USER;
$mform =& $this->_form;
@ -68,6 +68,15 @@ class course_request_form extends moodleform {
$mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client');
$mform->setType('shortname', PARAM_TEXT);
if (!empty($CFG->requestcategoryselection)) {
$displaylist = array();
$parentlist = array();
make_categories_list($displaylist, $parentlist, '');
$mform->addElement('select', 'category', get_string('category'), $displaylist);
$mform->setDefault('category', $CFG->defaultrequestcategory);
$mform->addHelpButton('category', 'category');
}
$mform->addElement('editor', 'summary_editor', get_string('summary'), null, course_request::summary_editor_options());
$mform->addHelpButton('summary_editor', 'coursesummary');
$mform->setType('summary_editor', PARAM_RAW);

View File

@ -283,6 +283,7 @@ $string['configrcache'] = 'Use the cache to store database records. Remember to
$string['configrcachettl'] = 'Time-to-live for cached records, in seconds. Use a short (<15) value here.';
$string['configrecaptchaprivatekey'] = 'String of characters used to communicate between your Moodle server and the recaptcha server. Obtain one for this site by visiting http://www.google.com/recaptcha';
$string['configrecaptchapublickey'] = 'String of characters used to display the reCAPTCHA element in the signup form. Generated by http://www.google.com/recaptcha';
$string['configrequestcategoryselection'] = 'Allow the selection of a category when requesting a course.';
$string['configrequestedstudentname'] = 'Word for student used in requested courses';
$string['configrequestedstudentsname'] = 'Word for students used in requested courses';
$string['configrequestedteachername'] = 'Word for teacher used in requested courses';
@ -871,6 +872,7 @@ $string['requires'] = 'Requires';
$string['purgecaches']= 'Purge all caches';
$string['purgecachesconfirm']= 'Moodle can cache themes, javascript, language strings, filtered text, rss feeds and many other pieces of calculated data. Purging these caches will delete that data from the server and force browsers to refetch data, so that you can be sure you are seeing the most up-to-date values produced by the current code. There is no danger in purging caches, but your site may appear slower for a while until the server and clients calculate new information and cache it.';
$string['purgecachesfinished']= 'All caches were purged.';
$string['requestcategoryselection'] = 'Enable category selection';
$string['restorernewroleid'] = 'Restorers\' role in courses';
$string['restorernewroleid_help'] = 'If the user does not already have the permission to manage the newly restored course, the user is automatically assigned this role and enrolled if necessary. Select "None" if you do not want restorers to be able to manage every restored course.';
$string['reverseproxy'] = 'Reverse proxy';

View File

@ -426,8 +426,9 @@
<FIELD NAME="fullname" TYPE="char" LENGTH="254" NOTNULL="true" SEQUENCE="false" PREVIOUS="id" NEXT="shortname"/>
<FIELD NAME="shortname" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" PREVIOUS="fullname" NEXT="summary"/>
<FIELD NAME="summary" TYPE="text" NOTNULL="true" SEQUENCE="false" PREVIOUS="shortname" NEXT="summaryformat"/>
<FIELD NAME="summaryformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="summary" NEXT="reason"/>
<FIELD NAME="reason" TYPE="text" NOTNULL="true" SEQUENCE="false" PREVIOUS="summaryformat" NEXT="requester"/>
<FIELD NAME="summaryformat" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="summary" NEXT="category"/>
<FIELD NAME="category" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="summaryformat" NEXT="reason"/>
<FIELD NAME="reason" TYPE="text" NOTNULL="true" SEQUENCE="false" PREVIOUS="category" NEXT="requester"/>
<FIELD NAME="requester" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="reason" NEXT="password"/>
<FIELD NAME="password" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false" PREVIOUS="requester"/>
</FIELDS>

View File

@ -1122,8 +1122,8 @@ function xmldb_main_upgrade($oldversion) {
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);
}
@ -1194,5 +1194,17 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2012090500.00);
}
if ($oldversion < 2012090700.01) {
// Add a category field in the course_request table
$table = new xmldb_table('course_request');
$field = new xmldb_field('category', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, 0, 'summaryformat');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2012090700.01);
}
return true;
}

View File

@ -30,7 +30,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2012090700.00; // YYYYMMDD = weekly release date of this DEV branch
$version = 2012090700.01; // YYYYMMDD = weekly release date of this DEV branch
// RR = release increments - 00 in DEV branches
// .XX = incremental changes