]> git.mjollnir.org Git - moodle.git/commitdiff
fixed the MoodleQuickForm_questioncategory, question_category_options function wasn...
authorjamiesensei <jamiesensei>
Sun, 7 Jan 2007 13:54:36 +0000 (13:54 +0000)
committerjamiesensei <jamiesensei>
Sun, 7 Jan 2007 13:54:36 +0000 (13:54 +0000)
lib/questionlib.php
question/type/edit_question_form.php

index f091633a96663c54bfcd09c454a9e4dd49aea687..359b7d0ef6f0e50f5c818963291368d3189bfe62 100644 (file)
@@ -1576,6 +1576,42 @@ function question_category_select_menu($courseid, $published = false, $only_edit
     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
@@ -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;
index dad8fb2be349fa98ed2408928e1fa286d0475a15..6ebae88dc2ff39e5cf9073d1f5ddf4558898441e 100644 (file)
@@ -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');
     }
 
     /**