From: jamiesensei Date: Sun, 7 Jan 2007 13:54:36 +0000 (+0000) Subject: fixed the MoodleQuickForm_questioncategory, question_category_options function wasn... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=375ed78a93106da39de253a46e8fba1429585b94;p=moodle.git fixed the MoodleQuickForm_questioncategory, question_category_options function wasn't committed so I've implemented it from question_category_select_menu code. --- diff --git a/lib/questionlib.php b/lib/questionlib.php index f091633a96..359b7d0ef6 100644 --- a/lib/questionlib.php +++ b/lib/questionlib.php @@ -1576,6 +1576,42 @@ function question_category_select_menu($courseid, $published = false, $only_edit echo "\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 @@ -1617,7 +1653,7 @@ function question_categorylist($categoryid) { * @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; diff --git a/question/type/edit_question_form.php b/question/type/edit_question_form.php index dad8fb2be3..6ebae88dc2 100644 --- a/question/type/edit_question_form.php +++ b/question/type/edit_question_form.php @@ -51,9 +51,9 @@ class question_edit_form extends moodleform { // 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); @@ -111,7 +111,14 @@ class question_edit_form extends moodleform { $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'); } /**