echo "</select>\n";
}
+/**
+ * Output an array of question categories.
+ *
+ * Categories from this course and (optionally) published categories from other courses
+ * are included. Optionally, only categories the current user may edit can be included.
+ *
+ * @param integer $courseid the id of the course to get the categories for.
+ * @param integer $published if true, include publised categories from other courses.
+ * @param integer $only_editable if true, exclude categories this user is not allowed to edit.
+ * @return array The list of categories.
+ */
+function question_category_options($courseid, $published = false, $only_editable = false) {
+ global $CFG;
+
+ // get sql fragment for published
+ $publishsql="";
+ if ($published) {
+ $publishsql = " OR publish = 1";
+ }
+
+ $categories = get_records_sql("
+ SELECT cat.*, c.shortname AS coursename
+ FROM {$CFG->prefix}question_categories cat, {$CFG->prefix}course c
+ WHERE c.id = cat.course AND (cat.course = $courseid $publishsql)
+ ORDER BY cat.parent, cat.sortorder, cat.name ASC");
+ $categoriesarray = array();
+ foreach ($categories as $category) {
+ $cid = $category->id;
+ $cname = question_category_coursename($category, $courseid);
+ if ((!$only_editable) || has_capability('moodle/question:managecategory', get_context_instance(CONTEXT_COURSE, $category->course))) {
+ $categoriesarray[$cid] = $cname;
+ }
+ }
+ return $categoriesarray;
+}
+
/**
* If the category is not from this course, and it is a published category,
* then return the course category name with the course shortname appended in
* @return mixed category object or null if fails
*/
function create_category_path( $catpath, $delimiter='/', $courseid=0 ) {
- $catpath = clean_param( $catpath,PARAM_PATH );
+ $catpath = clean_param( $catpath,PARAM_PATH );
$catnames = explode( $delimiter, $catpath );
$parent = 0;
$category = null;
// Standard fields at the start of the form.
$mform->addElement('header', 'generalheader', get_string("general", 'form'));
- /*$mform->addElement('questioncategory', 'category', get_string('category', 'quiz'),
+ $mform->addElement('questioncategory', 'category', get_string('category', 'quiz'),
array('courseid' => $COURSE->id, 'published' => true, 'only_editable' => true));
-*/
+
$mform->addElement('text', 'name', get_string('questionname', 'quiz'),
array('size' => 50));
$mform->setType('name', PARAM_TEXT);
$mform->addElement('hidden', 'versioning');
$mform->setType('versioning', PARAM_BOOL);
- $this->add_action_buttons();
+ $buttonarray = array();
+ $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('savechanges'));
+ if (!empty($this->question->id)) {
+ $buttonarray[] = &$mform->createElement('submit', 'makecopy', get_string('makecopy', 'quiz'));
+ }
+ $buttonarray[] = &$mform->createElement('cancel');
+ $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
+ $mform->closeHeaderBefore('buttonar');
}
/**