示例#1
0
$txt->modulenameplural = get_string('modulenameplural', 'quiz');
$txt->tofile = get_string('tofile', 'quiz');
if (!($course = get_record("course", "id", $courseid))) {
    error("Course does not exist!");
}
if ($categoryid) {
    // update category in session variable
    $SESSION->questioncat = $categoryid;
} else {
    // try to get category from modform
    if (isset($SESSION->questioncat)) {
        $categoryid = $SESSION->questioncat;
    }
}
if (!($category = get_record("question_categories", "id", $categoryid))) {
    $category = get_default_question_category($courseid);
}
if (!($categorycourse = get_record("course", "id", $category->course))) {
    print_error('nocategory', 'quiz');
}
require_login($course->id, false);
// check role capability
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_capability('moodle/question:export', $context);
// ensure the files area exists for this course
make_upload_directory("{$course->id}");
// check category is valid
if (!empty($categoryid)) {
    $validcats = question_category_options($course->id, true, false);
    if (!array_key_exists($categoryid, $validcats)) {
        print_error('invalidcategory', 'quiz');
示例#2
0
/**
 * prints a form to choose categories
 */
function question_category_form($course, $current, $recurse = 1, $showhidden = false, $showquestiontext = false)
{
    global $CFG;
    /// Make sure the default category exists for this course
    get_default_question_category($course->id);
    /// Get all the existing categories now
    $catmenu = question_category_options($course->id, true);
    $strcategory = get_string("category", "quiz");
    $strshow = get_string("show", "quiz");
    $streditcats = get_string("editcategories", "quiz");
    echo "<table><tr><td style=\"white-space:nowrap;\">";
    echo "<strong>{$strcategory}:</strong>&nbsp;";
    echo "</td><td>";
    popup_form("edit.php?courseid={$course->id}&amp;cat=", $catmenu, "catmenu", $current, "", "", "", false, "self");
    echo "</td><td align=\"right\">";
    echo "<form method=\"get\" action=\"{$CFG->wwwroot}/question/category.php\">";
    echo "<div>";
    echo "<input type=\"hidden\" name=\"id\" value=\"{$course->id}\" />";
    echo "<input type=\"submit\" value=\"{$streditcats}\" />";
    echo '</div>';
    echo "</form>";
    echo '</td></tr></table>';
    echo '<form method="get" action="edit.php" id="displayoptions">';
    echo "<fieldset class='invisiblefieldset'>";
    echo "<input type=\"hidden\" name=\"courseid\" value=\"{$course->id}\" />\n";
    question_category_form_checkbox('recurse', $recurse);
    question_category_form_checkbox('showhidden', $showhidden);
    question_category_form_checkbox('showquestiontext', $showquestiontext);
    echo '<noscript><div class="centerpara"><input type="submit" value="' . get_string('go') . '" />';
    echo '</div></noscript></fieldset></form>';
}
示例#3
0
 /**
  * Initializes this classes general category-related variables
  */
 function initialize()
 {
     /// Get the existing categories
     if (!($this->defaultcategory = get_default_question_category($this->course->id))) {
         error("Error: Could not find or make a category!");
     }
     $this->categories = $this->get_question_categories(null, "parent, sortorder, name ASC");
     $this->categories = $this->arrange_categories($this->categories);
     // create the array of id=>full_name strings
     $this->categorystrings = $this->expanded_category_strings($this->categories);
     // for pagination calculate number of 'top' categories and hence number of pages
     // (pagination only based on top categories)
     $count = 0;
     foreach ($this->categories as $category) {
         if ($category->parent == 0) {
             ++$count;
         }
     }
     $this->topcount = $count;
     $this->pagecount = (int) ceil($count / PAGE_LENGTH);
 }