function definition() { global $DB, $USER; $mform =& $this->_form; if ($pending = $DB->get_records('course_request', array('requester' => $USER->id))) { $mform->addElement('header', 'pendinglist', get_string('coursespending')); $list = array(); foreach ($pending as $cp) { $list[] = format_string($cp->fullname); } $list = implode(', ', $list); $mform->addElement('static', 'pendingcourses', get_string('courses'), $list); } $mform->addElement('header', 'coursedetails', get_string('courserequestdetails')); $mform->addElement('text', 'fullname', get_string('fullnamecourse'), 'maxlength="254" size="50"'); $mform->addHelpButton('fullname', 'fullnamecourse'); $mform->addRule('fullname', get_string('missingfullname'), 'required', null, 'client'); $mform->setType('fullname', PARAM_MULTILANG); $mform->addElement('text', 'shortname', get_string('shortname'), 'maxlength="100" size="20"'); $mform->addHelpButton('shortname', 'shortnamecourse'); $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client'); $mform->setType('shortname', PARAM_MULTILANG); $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); $mform->addElement('header', 'requestreason', get_string('courserequestreason')); $mform->addElement('textarea', 'reason', get_string('courserequestsupport'), array('rows' => '15', 'cols' => '50')); $mform->addRule('reason', get_string('missingreqreason'), 'required', null, 'client'); $mform->setType('reason', PARAM_TEXT); $this->add_action_buttons(true, get_string('requestcourse')); }
/** * Returns an array of options to use with a summary editor * * @uses course_request::$summaryeditoroptions * @return array An array of options to use with the editor */ public static function summary_editor_options() { global $CFG; if (self::$summaryeditoroptions === null) { self::$summaryeditoroptions = array('maxfiles' => 0, 'maxbytes' => 0); } return self::$summaryeditoroptions; }
exit; } /// Print a list of all the pending requests. echo $OUTPUT->header(); $pending = $DB->get_records('course_request'); if (empty($pending)) { echo $OUTPUT->heading(get_string('nopendingcourses')); } else { echo $OUTPUT->heading(get_string('coursespending')); /// Build a table of all the requests. $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')); foreach ($pending as $course) { $course = new course_request($course); // Check here for shortname collisions and warn about them. $course->check_shortname_collision(); $row = array(); $row[] = format_string($course->shortname); $row[] = format_string($course->fullname); $row[] = fullname($course->get_requester()); $row[] = $course->summary; $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'); /// Add the row to the table. $table->data[] = $row; } /// Display the table. echo html_writer::table($table); /// Message about name collisions, if necessary.
public function test_reject_request() { global $DB; $this->resetAfterTest(true); $this->preventResetByRollback(); unset_config('noemailever'); $this->setAdminUser(); set_config('enablecourserequests', 1); set_config('requestcategoryselection', 0); set_config('defaultrequestcategory', $DB->get_field_select('course_categories', "MIN(id)", "parent=0")); $requester = $this->getDataGenerator()->create_user(); $data = new stdClass(); $data->fullname = 'Həllo World!'; $data->shortname = 'Hi th€re!'; $data->summary_editor['text'] = 'Lorem Ipsum ©'; $data->summary_editor['format'] = FORMAT_HTML; $data->reason = 'Because PHP Unit is cool.'; $this->setUser($requester); $cr = course_request::create($data); $this->assertTrue($DB->record_exists('course_request', array('id' => $cr->id))); $this->setAdminUser(); $sink = $this->redirectMessages(); $cr->reject('Sorry!'); $this->assertFalse($DB->record_exists('course_request', array('id' => $cr->id))); $this->assertCount(1, $sink->get_messages()); $sink->close(); }
print_error('guestsarenotallowed', '', $returnurl); } if (empty($CFG->enablecourserequests)) { print_error('courserequestdisabled', '', $returnurl); } $context = context_system::instance(); $PAGE->set_context($context); require_capability('moodle/course:request', $context); // Set up the form. $data = course_request::prepare(); $requestform = new course_request_form($url, compact('editoroptions')); $requestform->set_data($data); $strtitle = get_string('courserequest'); $PAGE->set_title($strtitle); $PAGE->set_heading($strtitle); // Standard form processing if statement. if ($requestform->is_cancelled()) { redirect($returnurl); } else { if ($data = $requestform->get_data()) { $request = course_request::create($data); // And redirect back to the course listing. notice(get_string('courserequestsuccess'), $returnurl); } } $PAGE->navbar->add($strtitle); echo $OUTPUT->header(); echo $OUTPUT->heading($strtitle); // Show the request form. $requestform->display(); echo $OUTPUT->footer();
public function test_reject_request() { global $DB; $this->resetAfterTest(true); $this->preventResetByRollback(); $this->setAdminUser(); set_config('enablecourserequests', 1); set_config('requestcategoryselection', 0); set_config('defaultrequestcategory', $DB->get_field_select('course_categories', "MIN(id)", "parent=0")); $data = new stdClass(); $data->fullname = 'Həllo World!'; $data->shortname = 'Hi th€re!'; $data->summary_editor['text'] = 'Lorem Ipsum ©'; $data->summary_editor['format'] = FORMAT_HTML; $data->reason = 'Because PHP Unit is cool.'; $cr = course_request::create($data); $this->assertTrue($DB->record_exists('course_request', array('id' => $cr->id))); $cr->reject('Sorry!'); $this->assertDebuggingCalled(); // Caused by sending of message. $this->assertFalse($DB->record_exists('course_request', array('id' => $cr->id))); }