? question/addcategory_form.php
Index: lang/en_utf8/error.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lang/en_utf8/error.php,v
retrieving revision 1.18
diff -u -r1.18 error.php
--- lang/en_utf8/error.php 3 Apr 2007 03:32:46 -0000 1.18
+++ lang/en_utf8/error.php 16 Apr 2007 11:33:48 -0000
@@ -1,4 +1,4 @@
- You have to terminate the \"Login as\" session before entering any other course.';
$string['loginasnoenrol'] = 'You can not use enrol or unenrol when in course \"Login as\" session.';
$string['missingfield'] = 'Field \"$a\" is missing';
Index: lang/en_utf8/question.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lang/en_utf8/question.php,v
retrieving revision 1.3
diff -u -r1.3 question.php
--- lang/en_utf8/question.php 27 Feb 2007 16:20:39 -0000 1.3
+++ lang/en_utf8/question.php 13 Apr 2007 06:06:39 -0000
@@ -9,5 +9,6 @@
$string['questiondoesnotexist'] = 'This question does not exist';
$string['unknownquestiontype'] = 'Unknown question type: $a.';
$string['fractionsnomax'] = 'One of the answers should have a score of 100%% so it is possible to get full marks for this question.';
-
+$string['makechildof'] = "Make Child of '\$a'";
+$string['maketoplevelitem'] = 'Move to top level';
?>
Index: question/category.php
===================================================================
RCS file: /cvsroot/moodle/moodle/question/category.php,v
retrieving revision 1.13
diff -u -r1.13 category.php
--- question/category.php 19 Mar 2007 17:22:46 -0000 1.13
+++ question/category.php 17 Apr 2007 08:53:09 -0000
@@ -14,36 +14,41 @@
// get values from form
$param = new stdClass();
- $id = required_param('id',PARAM_INT); // course id
- $param->moveup = optional_param('moveup',0,PARAM_INT);
- $param->movedown = optional_param('movedown',0,PARAM_INT);
- $param->hide = optional_param('hide',0,PARAM_INT);
- $param->delete = optional_param('delete',0,PARAM_INT);
- $param->confirm = optional_param('confirm',0,PARAM_INT);
- $param->cancel = optional_param('cancel','',PARAM_ALPHA);
- $param->move = optional_param('move',0,PARAM_INT);
- $param->moveto = optional_param('moveto',0,PARAM_INT);
- $param->publish = optional_param('publish',0,PARAM_INT);
- $param->addcategory = optional_param('addcategory','',PARAM_NOTAGS);
- $param->edit = optional_param('edit',0,PARAM_INT);
- $param->updateid = optional_param('updateid',0,PARAM_INT);
- $param->page = optional_param('page',1,PARAM_INT);
+
+ $id = required_param('id', PARAM_INT); // course id
+ $param->page = optional_param('page', 1, PARAM_INT);
+
+ $param->moveup = optional_param('moveup', 0, PARAM_INT);
+ $param->movedown = optional_param('movedown', 0, PARAM_INT);
+ $param->left = optional_param('left', 0, PARAM_INT);
+ $param->right = optional_param('right', 0, PARAM_INT);
+ $param->hide = optional_param('hide', 0, PARAM_INT);
+ $param->delete = optional_param('delete', 0, PARAM_INT);
+ $param->confirm = optional_param('confirm', 0, PARAM_INT);
+ $param->cancel = optional_param('cancel', '', PARAM_ALPHA);
+ $param->move = optional_param('move', 0, PARAM_INT);
+ $param->moveto = optional_param('moveto', 0, PARAM_INT);
+ $param->publish = optional_param('publish', 0, PARAM_INT);
+ $param->addcategory = optional_param('addcategory', '', PARAM_NOTAGS);
+ $param->edit = optional_param('edit', 0, PARAM_INT);
+ $param->updateid = optional_param('updateid', 0, PARAM_INT);
if (! $course = get_record("course", "id", $id)) {
error("Course ID is incorrect");
}
-
+
$context = get_context_instance(CONTEXT_COURSE, $id);
-
+
require_login($course->id, false);
require_capability('moodle/question:managecategory', $context);
- $qcobject = new question_category_object();
- $qcobject->set_course($course);
+ $qcobject = new question_category_object($param->page);
- // Page header
- // TODO: generalise this to any activity
- if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
+ if ($qcobject->editlist->process_actions($param->left, $param->right, $param->moveup, $param->movedown)) {
+ //processing of these actions is handled in the method and page redirects.
+ } else if (isset($SESSION->modform->instance) and $quiz = get_record('quiz', 'id', $SESSION->modform->instance)) {
+ // Page header
+ // TODO: generalise this to any activity
$strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id))
? update_module_button($SESSION->modform->cmid, $course->id, get_string('modulename', 'quiz'))
: "";
@@ -72,10 +77,6 @@
} else {
$qcobject->delete_category($param->delete);
}
- } else if (!empty($param->moveup)) {
- $qcobject->move_category_up_down('up', $param->moveup);
- } else if (!empty($param->movedown)) {
- $qcobject->move_category_up_down('down', $param->movedown);
} else if (!empty($param->hide)) {
$qcobject->publish_category(false, $param->hide);
} else if (!empty($param->move)) {
@@ -102,7 +103,7 @@
}
// display the user interface
- $qcobject->display_user_interface($param->page);
+ $qcobject->display_user_interface();
print_footer($course);
?>
Index: question/category_class.php
===================================================================
RCS file: /cvsroot/moodle/moodle/question/category_class.php,v
retrieving revision 1.18
diff -u -r1.18 category_class.php
--- question/category_class.php 21 Mar 2007 10:41:28 -0000 1.18
+++ question/category_class.php 19 Apr 2007 05:40:02 -0000
@@ -8,34 +8,110 @@
*/
// number of categories to display on page
-define( "PAGE_LENGTH",25 );
+define("QUESTION_PAGE_LENGTH", 25);
+
+require_once("$CFG->libdir/listlib.php");
+
+class question_category_list extends moodle_list {
+ var $table = "question_categories";
+ var $listitemclassname = 'question_category_list_item';
+ function question_category_list($type='ul', $attributes='', $editable = false, $page = 0){
+ parent::moodle_list($type, $attributes, $editable, $page);
+ }
+ function get_records() {
+ global $COURSE, $CFG;
+ $categories = get_records($this->table, 'course', "{$COURSE->id}", $this->sortby);
+
+ $catids = array_keys($categories);
+ $select = "WHERE category IN ('".join("', '", $catids)."') AND hidden='0' AND parent='0'";
+ $questioncounts = get_records_sql_menu('SELECT category, COUNT(*) FROM '. $CFG->prefix . 'question' .' '. $select.' GROUP BY category');
+ foreach ($categories as $categoryid => $category){
+ if (isset($questioncounts[$categoryid])){
+ $categories[$categoryid]->questioncount = $questioncounts[$categoryid];
+ } else {
+ $categories[$categoryid]->questioncount = 0;
+ }
+ }
+ $this->records = $categories;
+ }
+}
+
+class question_category_list_item extends list_item {
+
+
+ function item_html($extraargs = array()){
+ global $CFG;
+ $pixpath = $CFG->pixpath;
+ $str = $extraargs['str'];
+ $category = $this->item;
+
+ $linkcss = $category->publish ? ' class="published" ' : ' class="unpublished" ';
+
+ if (!empty($parent->page)) {
+ $pagelink="&page=".$parent->page;
+ } else {
+ $pagelink="";
+ }
+
+ /// Each section adds html to be displayed as part of this list item
+
+ $item = '
+
' . $category->name . '('.$category->questioncount.')'. '';
+
+ $item .= ' '. $category->info;
+
+
+ if (!empty($category->publish)) {
+ $item .= '
+
';
+ } else {
+ $item .= '
+
';
+ }
+
+ if ($category->id != $extraargs['defaultcategory']->id) {
+ $item .= '
+
';
+ }
+
+ return $item;
+
+
+ }
+
+}
+
/**
* Class representing question categories
- *
+ *
* @package questionbank
*/
class question_category_object {
var $str;
var $pixpath;
- var $edittable;
+ /**
+ * Nested list to display categories.
+ *
+ * @var question_category_list
+ */
+ var $editlist;
var $newtable;
var $tab;
var $tabsize = 3;
var $categories;
var $categorystrings;
var $defaultcategory;
- var $course;
- var $topcount;
/**
* Constructor
*
* Gets necessary strings and sets relevant path information
*/
- function question_category_object() {
- global $CFG;
+ function question_category_object($page) {
+ global $CFG, $COURSE;
$this->tab = str_repeat(' ', $this->tabsize);
@@ -62,39 +138,31 @@
$this->str->page = get_string('page');
$this->pixpath = $CFG->pixpath;
- }
+ $this->editlist = new question_category_list('ul', '', true, $page);
+ $this->editlist->add_page_params(array('id'=>$COURSE->id));
+ $this->initialize();
- /**
- * Sets the course for this object
- *
- * @param object course
- */
- function set_course($course) {
- $this->course = $course;
}
+
+
/**
* Displays the user interface
*
- * @param object modform
- * @param int $page page number to display (0=don't paginate)
*/
- function display_user_interface($page=0) {
- $this->initialize();
+ function display_user_interface() {
+ /// Interface for editing existing categories
+ print_heading_with_help($this->str->editcategories, 'categories', 'quiz');
+ $this->output_edit_list();
+
+
+ echo '
';
/// Interface for adding a new category:
print_heading_with_help($this->str->addcategory, 'categories_edit', 'quiz');
$this->output_new_table();
echo '
';
- /// Interface for editing existing categories
- print_heading_with_help($this->str->editcategories, 'categories', 'quiz');
- $this->output_edit_table($page);
- if ($this->topcount>PAGE_LENGTH) {
- $this->display_page_numbers($page);
- }
- echo '
';
-
}
@@ -102,60 +170,34 @@
* Initializes this classes general category-related variables
*/
function initialize() {
+ global $COURSE, $CFG;
/// Get the existing categories
- if (!$this->defaultcategory = get_default_question_category($this->course->id)) {
+ if (!$this->defaultcategory = get_default_question_category($COURSE->id)) {
error("Error: Could not find or make a category!");
}
- $this->categories = $this->get_question_categories(null, "parent, sortorder, name ASC");
+ $this->editlist->list_from_records(QUESTION_PAGE_LENGTH);
- $this->categories = $this->arrange_categories($this->categories);
+ $this->categories = $this->editlist->records;
// 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 = (integer) ceil( $count / PAGE_LENGTH );
- }
-
- /**
- * display list of page numbers for navigation
- */
- function display_page_numbers( $page=0 ) {
- global $USER;
- echo "
' . $fill . $category->name . '';
-
- $this->edittable->align["$category->id.info"] = "left";
- $this->edittable->wrap["$category->id.info"] = "nowrap";
- $row["$category->id.info"] = '' . $category->info . '';
- $this->edittable->align["$category->id.qcount"] = "center";
- $row["$category->id.qcount"] = $category->questioncount;
- $this->edittable->align["$category->id.publish"] = "center";
- $this->edittable->wrap["$category->id.publish"] = "nowrap";
- if (!empty($category->publish)) {
- $row["$category->id.publish"] = '
';
- } else {
- $row["$category->id.publish"] = '
';
- }
-
- if ($category->id != $this->defaultcategory->id) {
- $this->edittable->align["$category->id.delete"] = "center";
- $this->edittable->wrap["$category->id.delete"] = "nowrap";
- $row["$category->id.delete"] = '
';
- } else {
- $row["$category->id.delete"] = '';
- }
-
- $this->edittable->align["$category->id.order"] = "left";
- $this->edittable->wrap["$category->id.order"] = "nowrap";
- $icons = '';
- if ($up) {
- $icons .= '
-
';
- }
- if ($down) {
- $icons .= '
-
';
- }
- $row["$category->id.order"]= $icons;
-
- $this->edittable->align["$category->id.moveto"] = "left";
- $this->edittable->wrap["$category->id.moveto"] = "nowrap";
- if ($category->id != $this->defaultcategory->id) {
- $viableparents = $this->categorystrings;
- $this->set_viable_parents($viableparents, $category);
- $viableparents = array(0=>$this->str->top) + $viableparents;
-
- $row["$category->id.moveto"] = popup_form ("category.php?id={$this->course->id}&move={$category->id}&sesskey=$USER->sesskey$pagelink&moveto=",
- $viableparents, "moveform{$category->id}", "$category->parent", "", "", "", true);
- } else {
- $row["$category->id.moveto"]='---';
- }
-
-
- $this->edittable->data[$category->id] = $row;
- }
-
-
- function edit_single_category($categoryid,$page=1) {
+ function edit_single_category($categoryid, $page=1) {
/// Interface for adding a new category
- global $USER;
- $this->initialize();
+ global $USER, $COURSE;
/// Interface for editing existing categories
if ($category = get_record("question_categories", "id", $categoryid)) {
@@ -382,20 +289,20 @@
helpbutton("categories_edit", $this->str->editcategory, "quiz");
echo '';
echo '| '; - $this->output_edit_single_table($category,$page); + $this->output_edit_single_table($category, $page); echo ' |