Browse files

MDL-6773 - eliminate duplicate code for getting a list of question ca…

…tegories.
  • Loading branch information...
1 parent 31eb4b1 commit 7c1fb231562f449925e03e5add838c74aacfd25d tjhunt committed Mar 1, 2007
Showing with 12 additions and 65 deletions.
  1. +8 −28 lib/questionlib.php
  2. +0 −34 question/editlib.php
  3. +1 −1 question/format/coursetestmanager/format.php
  4. +3 −2 question/import.php
View
36 lib/questionlib.php
@@ -1545,35 +1545,13 @@ function add_indented_names($categories) {
* @param integer $selected optionally, the id of a category to be selected by default in the dropdown.
*/
function question_category_select_menu($courseid, $published = false, $only_editable = false, $selected = "") {
- 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");
-
- $categories = add_indented_names($categories);
-
- echo "<select name=\"category\">\n";
- foreach ($categories as $category) {
- $cid = $category->id;
- $cname = question_category_coursename($category, $courseid);
- $seltxt = "";
- if ($cid==$selected) {
- $seltxt = "selected=\"selected\"";
- }
- if ((!$only_editable) || has_capability('moodle/question:managecategory', get_context_instance(CONTEXT_COURSE, $category->course))) {
- echo " <option value=\"$cid\" $seltxt>$cname</option>\n";
- }
+ $categoriesarray = question_category_options($courseid, $published, $only_editable);
+ if ($selected) {
+ $nothing = '';
+ } else {
+ $nothing = 'choose';
}
- echo "</select>\n";
+ choose_from_menu($categoriesarray, 'category', $selected, $nothing);
}
/**
@@ -1601,6 +1579,8 @@ function question_category_options($courseid, $published = false, $only_editable
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");
+ $categories = add_indented_names($categories);
+
$categoriesarray = array();
foreach ($categories as $category) {
$cid = $category->id;
View
34 question/editlib.php
@@ -94,40 +94,6 @@ function get_default_question_category($courseid) {
}
/**
- * Return a list of categories nicely formatted
- * @param int courseid id of course
- * @param bool published true=include all published categories
- * @return array formatted category names
- */
-function question_category_menu($courseid, $published=false) {
-/// Returns the list of categories
- $publish = "";
- if ($published) {
- $publish = "OR publish = '1'";
- }
-
- if (!has_capability('moodle/question:manage', get_context_instance(CONTEXT_SYSTEM, SITEID))) {
- $categories = get_records_select("question_categories", "course = '$courseid' $publish", 'parent, sortorder, name ASC');
- } else {
- $categories = get_records_select("question_categories", '', 'parent, sortorder, name ASC');
- }
- if (!$categories) {
- return false;
- }
- $categories = add_indented_names($categories);
-
- foreach ($categories as $category) {
- if ($catcourse = get_record("course", "id", $category->course)) {
- if ($category->publish && ($category->course != $courseid)) {
- $category->indentedname .= " ($catcourse->shortname)";
- }
- $catmenu[$category->id] = $category->indentedname;
- }
- }
- return $catmenu;
-}
-
-/**
* prints a form to choose categories
*/
function question_category_form($course, $current, $recurse=1, $showhidden=false, $showquestiontext=false) {
View
2 question/format/coursetestmanager/format.php
@@ -116,7 +116,7 @@ function importprocess($filename) {
// don't have to do this on linux, since it's alreay been done in the test above
if (PHP_OS == "WINNT") { $question_categories = $this->getquestioncategories($filename); }
// print the intermediary form
- if (!$categories = question_category_menu($course->id, true)) {
+ if (!$categories = question_category_options($course->id, true)) {
error("No categories!");
}
print_heading_with_help($strimportquestions, "import", "quiz");
View
5 question/import.php
@@ -10,8 +10,9 @@
*/
require_once("../config.php");
- require_once( "editlib.php" );
- require_once($CFG->dirroot.'/lib/uploadlib.php');
+ require_once("editlib.php" );
+ require_once($CFG->libdir . '/uploadlib.php');
+ require_once($CFG->libdir . '/questionlib.php');
// get parameters
$params = new stdClass;

0 comments on commit 7c1fb23

Please sign in to comment.