From ab5bd34d182201317c41f3f734522ee1792edd22 Mon Sep 17 00:00:00 2001 From: samhemelryk Date: Fri, 11 Sep 2009 02:04:38 +0000 Subject: [PATCH] mod-feedback MDL-20254 Upgrade feedback module to make use of new navigation blocks At the same time I also took the oppertunity to fix up the bugs within the feedback module that were making it un-usable --- lang/en_utf8/feedback.php | 4 +- lib/simpletest/testnavigationlib.php | 2 + mod/feedback/analysis.php | 22 ++++---- mod/feedback/complete.php | 7 +-- mod/feedback/edit.php | 9 ++- mod/feedback/edit_item.php | 2 + .../item/feedback_item_form_class.php | 3 +- mod/feedback/item/textarea/lib.php | 2 +- mod/feedback/item/textarea/textarea_form.php | 4 +- mod/feedback/lib.php | 56 ++++++++++++++++++- mod/feedback/show_entries.php | 6 +- mod/feedback/view.php | 4 +- 12 files changed, 88 insertions(+), 33 deletions(-) diff --git a/lang/en_utf8/feedback.php b/lang/en_utf8/feedback.php index f3d5dbc631b..09e2d0b21bd 100644 --- a/lang/en_utf8/feedback.php +++ b/lang/en_utf8/feedback.php @@ -63,6 +63,7 @@ You can view it url\">here.'; $string['entries_saved'] = 'Your answers have been saved. Thank you.'; $string['export_questions'] = 'Export questions'; $string['export_to_excel'] = 'Export to Excel'; +$string['feedbackadministration'] = 'Feedback administration'; $string['feedback:complete'] = 'Complete a feedback'; $string['feedback:createprivatetemplate'] = 'Create private template'; $string['feedback:createpublictemplate'] = 'Create public template'; @@ -93,7 +94,7 @@ $string['infotype'] = 'Information-Type'; $string['item_name'] = 'Question'; $string['items_are_required'] = 'Answers are required to starred questions.'; $string['label'] = 'Label'; -$string['line_labels'] = 'Label'; +$string['item_label'] = 'Label'; $string['line_values'] = 'Rating'; $string['mapcourse'] = 'Map course'; $string['mapcourses'] = 'Map feedback to courses'; @@ -119,6 +120,7 @@ $string['name_required'] = 'Name required'; $string['next_page'] = 'Next page'; $string['no_handler']='No action handler exists for'; $string['no_itemname'] = 'No itemname'; +$string['no_itemlabel'] = 'No label'; $string['no_items_available_yet'] = 'No questions have been set up yet'; $string['no_templates_available_yet'] = 'No templates available yet'; $string['non_anonymous'] = 'User\'s name will be logged and shown with answers'; diff --git a/lib/simpletest/testnavigationlib.php b/lib/simpletest/testnavigationlib.php index d4349745e2e..d2225ea868a 100644 --- a/lib/simpletest/testnavigationlib.php +++ b/lib/simpletest/testnavigationlib.php @@ -725,6 +725,8 @@ class limited_global_navigation_test extends UnitTestCase { } $node2 = clone($this->mocknode); + $fakecontext = new stdClass; + $this->cache->coursecontext2 = $fakecontext; $node2->initialise(navigation_node::TYPE_CATEGORY, 2); $this->assertIsA($node2->get('initcall'), 'navigation_node'); if ($node2->get('initcall')) { diff --git a/mod/feedback/analysis.php b/mod/feedback/analysis.php index c0037a35e28..5a5d69e6e41 100644 --- a/mod/feedback/analysis.php +++ b/mod/feedback/analysis.php @@ -1,12 +1,12 @@ -id, $course->id, $strfeedback); - $PAGE->navbar->add($strfeedbacks, new moodle_url($CFG->wwwroot.'/mod/feedback/index.php', array('id'=>$course->id))); - $PAGE->navbar->add(format_string($feedback->name)); - + $PAGE->navbar->add(get_string('analysis','feedback')); + $PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/feedback/edit.php', array('id'=>$cm->id, 'course'=>$courseid))); $PAGE->set_title(format_string($feedback->name)); $PAGE->set_button($buttontext); echo $OUTPUT->header(); @@ -127,6 +126,7 @@ //get the class of item-typ $itemclass = 'feedback_item_'.$item->typ; //get the instance of the item-class + require_once($CFG->dirroot.'/mod/feedback/item/'.$item->typ.'/lib.php'); $itemobj = new $itemclass(); $itemnr++; if($feedback->autonumbering) { diff --git a/mod/feedback/complete.php b/mod/feedback/complete.php index 1b6ee3680a4..019eca35dec 100644 --- a/mod/feedback/complete.php +++ b/mod/feedback/complete.php @@ -122,10 +122,9 @@ $strfeedbacks = get_string("modulenameplural", "feedback"); $strfeedback = get_string("modulename", "feedback"); $buttontext = update_module_button($cm->id, $course->id, $strfeedback); - - $PAGE->navbar->add($strfeedbacks, new moodle_url($CFG->wwwroot.'/mod/feedback/index.php', array('id'=>$course->id))); - $PAGE->navbar->add(format_string($feedback->name)); - + + $PAGE->navbar->add(get_string('feedback:complete', 'feedback')); + $PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/feedback/complete.php', array('id'=>$cm->id, 'gopage'=>$gopage, 'courseid'=>$course->id))); $PAGE->set_title(format_string($feedback->name)); $PAGE->set_button($buttontext); echo $OUTPUT->header(); diff --git a/mod/feedback/edit.php b/mod/feedback/edit.php index 29719c2a113..ffe41f70e49 100644 --- a/mod/feedback/edit.php +++ b/mod/feedback/edit.php @@ -144,9 +144,12 @@ $strfeedback = get_string("modulename", "feedback"); $buttontext = update_module_button($cm->id, $course->id, $strfeedback); - $PAGE->navbar->add($strfeedbacks, new moodle_url($CFG->wwwroot.'/mod/feedback/index.php', array('id'=>$course->id))); - $PAGE->navbar->add(format_string($feedback->name)); - + if ($do_show == 'edit') { + $PAGE->navbar->add(get_string('edit_items', 'feedback')); + } else { + $PAGE->navbar->add(get_string($do_show, 'feedback')); + } + $PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/feedback/edit.php', array('id'=>$cm->id, 'do_show'=>$do_show))); $PAGE->set_title(format_string($feedback->name)); $PAGE->set_button($buttontext); echo $OUTPUT->header(); diff --git a/mod/feedback/edit_item.php b/mod/feedback/edit_item.php index 70a76a33804..46359c4247b 100644 --- a/mod/feedback/edit_item.php +++ b/mod/feedback/edit_item.php @@ -69,6 +69,8 @@ } } + require_once($CFG->dirroot.'/mod/feedback/item/'.$typ.'/lib.php'); + //////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// if(isset($formdata->cancel)){ diff --git a/mod/feedback/item/feedback_item_form_class.php b/mod/feedback/item/feedback_item_form_class.php index 8b6dfe36ccc..6c76344713f 100644 --- a/mod/feedback/item/feedback_item_form_class.php +++ b/mod/feedback/item/feedback_item_form_class.php @@ -4,8 +4,7 @@ require_once $CFG->libdir.'/formslib.php'; define('FEEDBACK_ITEM_NAME_TEXTBOX_SIZE', 80); define('FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE', 20); -class feedback_item_form extends moodleform { - +abstract class feedback_item_form extends moodleform { function get_item_form() { return $this->_form; } diff --git a/mod/feedback/item/textarea/lib.php b/mod/feedback/item/textarea/lib.php index a5e678b25b9..3bd9e501443 100644 --- a/mod/feedback/item/textarea/lib.php +++ b/mod/feedback/item/textarea/lib.php @@ -30,7 +30,7 @@ class feedback_item_textarea extends feedback_item_base { $widthAndHeight = explode('|',$item->presentation); $itemwidth = isset($widthAndHeight[0]) ? $widthAndHeight[0] : 30; $itemheight = isset($widthAndHeight[1]) ? $widthAndHeight[1] : 5; - $item_form->selectwith->setValue($itemwidth); + $item_form->selectwidth->setValue($itemwidth); $item_form->selectheight->setValue($itemheight); return $item_form; diff --git a/mod/feedback/item/textarea/textarea_form.php b/mod/feedback/item/textarea/textarea_form.php index f40acd9b830..bd6124dc06c 100644 --- a/mod/feedback/item/textarea/textarea_form.php +++ b/mod/feedback/item/textarea/textarea_form.php @@ -7,7 +7,7 @@ class feedback_textarea_form extends feedback_item_form { var $requiredcheck; var $itemname; var $itemlabel; - var $selectwith; + var $selectwidth; var $selectheight; function definition() { @@ -19,7 +19,7 @@ class feedback_textarea_form extends feedback_item_form { $this->itemname = $mform->addElement('text', 'itemname', get_string('item_name', 'feedback'), array('size="'.FEEDBACK_ITEM_NAME_TEXTBOX_SIZE.'"','maxlength="255"')); $this->itemlabel = $mform->addElement('text', 'itemlabel', get_string('item_label', 'feedback'), array('size="'.FEEDBACK_ITEM_LABEL_TEXTBOX_SIZE.'"','maxlength="255"')); - $this->selectwith = $mform->addElement('select', + $this->selectwidth = $mform->addElement('select', 'itemwidth', get_string('textarea_width', 'feedback').' ', array_slice(range(0,80),5,80,true)); diff --git a/mod/feedback/lib.php b/mod/feedback/lib.php index 1b4b9ab9216..2f7b286283b 100644 --- a/mod/feedback/lib.php +++ b/mod/feedback/lib.php @@ -997,8 +997,8 @@ function feedback_create_item($data) { $item->position = $data->position; $item->required=0; - if (isset($data->required)) { - $item->required=$data->required; + if (!empty($data->required)) { + $item->required = $data->required; } return $DB->insert_record('feedback_item', $item); @@ -1212,11 +1212,15 @@ function feedback_move_item($moveitem, $pos){ * @return void */ function feedback_print_item($item, $value = false, $readonly = false, $edit = false, $highlightrequire = false){ + global $CFG; if($item->typ == 'pagebreak') return; if($readonly)$ro = 'readonly="readonly" disabled="disabled"'; //get the class of the given item-typ $itemclass = 'feedback_item_'.$item->typ; + if (!class_exists($itemclass)) { + require_once($CFG->dirroot.'/mod/feedback/item/'.$item->typ.'/lib.php'); + } //get the instance of the item-class $itemobj = new $itemclass(); $itemobj->print_item($item, $value, $readonly, $edit, $highlightrequire); @@ -1538,7 +1542,7 @@ function feedback_get_item_value($completedid, $itemid, $tmp = false) { * @return boolean */ function feedback_check_values($data, $firstitem, $lastitem) { - global $DB; + global $DB, $CFG; //get all items between the first- and lastitem $select = "feedback = ? @@ -1567,6 +1571,11 @@ function feedback_check_values($data, $firstitem, $lastitem) { //get the class of the item-typ $itemclass = 'feedback_item_'.$item->typ; + + if (!class_exists($itemclass)) { + require_once($CFG->dirroot.'/mod/feedback/item/'.$item->typ.'/lib.php'); + } + //get the instance of the item-class $itemobj = new $itemclass(); @@ -1623,6 +1632,9 @@ function feedback_create_values($data, $usrid, $timemodified, $tmp = false, $gue //get the class of item-typ $itemclass = 'feedback_item_'.$itemnr[0]; //get the instance of item-class + if (!class_exists($itemclass)) { + require_once($CFG->dirroot.'/mod/feedback/item/'.$itemnr[0].'/lib.php'); + } $itemobj = new $itemclass(); //the kind of values can be absolutely different so we run create_value directly by the item-class $value->value = $itemobj->create_value($data[$key]); @@ -1670,6 +1682,9 @@ function feedback_update_values($data, $completed, $tmp = false) { //get the class of item-typ $itemclass = 'feedback_item_'.$itemnr[0]; //get the instace of the item-class + if (!class_exists($itemclass)) { + require_once($CFG->dirroot.'/mod/feedback/item/'.$itemnr[0].'/lib.php'); + } $itemobj = new $itemclass(); //the kind of values can be absolutely different so we run create_value directly by the item-class $newvalue->value = $itemobj->create_value($data[$key]); @@ -2312,3 +2327,38 @@ function feedback_encode_target_url($url) { return $url; } } + +function feedback_extend_settings_navigation($settings, $module) { + global $PAGE, $USER, $OUTPUT, $CFG, $DB; + + $feedback = $DB->get_record('feedback', array('id'=>$PAGE->cm->instance)); + $feedbacknavkey = $settings->add(get_string('feedbackadministration', 'feedback')); + $feedbacknav = $settings->get($feedbacknavkey); + $feedbacknav->forceopen = true; + + $capabilities = feedback_load_capabilities($PAGE->cm->id); + + if($capabilities->edititems) { + $qkey = $feedbacknav->add(get_string('questions', 'feedback')); + $feedbacknav->get($qkey)->add(get_string('edit_items', 'feedback'), new moodle_url($CFG->wwwroot.'/mod/feedback/edit.php', array('id'=>$PAGE->cm->id, 'do_show'=>'edit'))); + $feedbacknav->get($qkey)->add(get_string('export_questions', 'feedback'), new moodle_url($CFG->wwwroot.'/mod/feedback/export.php', array('id'=>$PAGE->cm->id, 'action'=>'exportfile'))); + $feedbacknav->get($qkey)->add(get_string('import_questions', 'feedback'), new moodle_url($CFG->wwwroot.'/mod/feedback/import.php', array('id'=>$PAGE->cm->id))); + $feedbacknav->get($qkey)->add(get_string('templates', 'feedback'), new moodle_url($CFG->wwwroot.'/mod/feedback/edit.php', array('id'=>$PAGE->cm->id, 'do_show'=>'templates'))); + } + + if($capabilities->viewreports) { + if($feedback->course == SITEID){ + $feedbacknav->add(get_string('analysis', 'feedback'), new moodle_url($CFG->wwwroot.'/mod/feedback/analysis_course.php', array('id'=>$PAGE->cm->id, 'course'=>$PAGE->course->id,'do_show'=>'analysis'))); + }else { + $feedbacknav->add(get_string('analysis', 'feedback'), new moodle_url($CFG->wwwroot.'/mod/feedback/analysis.php', array('id'=>$PAGE->cm->id, 'course'=>$PAGE->course->id,'do_show'=>'analysis'))); + } + } + + if($capabilities->viewreports) { + $feedbacknav->add(get_string('show_entries', 'feedback'), new moodle_url($CFG->wwwroot.'/mod/feedback/show_entries.php', array('id'=>$PAGE->cm->id, 'do_show'=>'showentries'))); + } + + if (has_capability('moodle/course:manageactivities', $PAGE->cm->context)) { + $feedbacknav->add(get_string('updatethis', '', get_string('modulename', 'feedback')), new moodle_url($CFG->wwwroot.'/course/mod.php', array('update' => $PAGE->cm->id, 'return' => true, 'sesskey' => sesskey()))); + } +} \ No newline at end of file diff --git a/mod/feedback/show_entries.php b/mod/feedback/show_entries.php index 1306bf82865..96025ca1c52 100644 --- a/mod/feedback/show_entries.php +++ b/mod/feedback/show_entries.php @@ -42,6 +42,8 @@ } } + $PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/feedback/edit.php', array('id'=>$cm->id, 'do_show'=>$do_show))); + $capabilities = feedback_load_capabilities($cm->id); require_login($course->id, true, $cm); @@ -68,9 +70,7 @@ $strfeedback = get_string("modulename", "feedback"); $buttontext = update_module_button($cm->id, $course->id, $strfeedback); - $PAGE->navbar->add($strfeedbacks, new moodle_url($CFG->wwwroot.'/mod/feedback/index.php', array('id'=>$course->id))); - $PAGE->navbar->add(format_string($feedback->name)); - + $PAGE->navbar->add(get_string('show_entries','feedback')); $PAGE->set_title(format_string($feedback->name)); $PAGE->set_button($buttontext); echo $OUTPUT->header(); diff --git a/mod/feedback/view.php b/mod/feedback/view.php index 7abc102d41b..d642845d8e3 100644 --- a/mod/feedback/view.php +++ b/mod/feedback/view.php @@ -80,10 +80,8 @@ $strfeedbacks = get_string("modulenameplural", "feedback"); $strfeedback = get_string("modulename", "feedback"); $buttontext = update_module_button($cm->id, $course->id, $strfeedback); - - $PAGE->navbar->add($strfeedbacks, new moodle_url($CFG->wwwroot.'/mod/feedback/index.php', array('id'=>$course->id))); - $PAGE->navbar->add(format_string($feedback->name)); + $PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/feedback/view.php', array('id'=>$cm->id, 'do_show'=>'view'))); $PAGE->set_title(format_string($feedback->name)); $PAGE->set_button($buttontext); echo $OUTPUT->header();