diff --git a/mod/feedback/analysis.php b/mod/feedback/analysis.php index 7b5c540ec0f..ac44aa1074c 100644 --- a/mod/feedback/analysis.php +++ b/mod/feedback/analysis.php @@ -47,7 +47,6 @@ if (!feedback_can_view_analysis($feedback, $context)) { $strfeedbacks = get_string("modulenameplural", "feedback"); $strfeedback = get_string("modulename", "feedback"); -$PAGE->navbar->add(get_string('analysis', 'feedback')); $PAGE->set_heading($course->fullname); $PAGE->set_title($feedback->name); echo $OUTPUT->header(); @@ -57,9 +56,6 @@ echo $OUTPUT->heading(format_string($feedback->name)); require('tabs.php'); -//print analysed items -echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); - //get the groupid $myurl = $CFG->wwwroot.'/mod/feedback/analysis.php?id='.$cm->id.'&do_show=analysis'; $mygroupid = groups_get_activity_group($cm, true); @@ -127,7 +123,6 @@ if ($check_anonymously) { 'feedback', '', '', 3); } echo ''; -echo $OUTPUT->box_end(); echo $OUTPUT->footer(); diff --git a/mod/feedback/analysis_course.php b/mod/feedback/analysis_course.php index d5f4c1745f6..1c4d84d4f6d 100644 --- a/mod/feedback/analysis_course.php +++ b/mod/feedback/analysis_course.php @@ -28,19 +28,16 @@ require_once("lib.php"); $current_tab = 'analysis'; $id = required_param('id', PARAM_INT); //the POST dominated the GET -$coursefilter = optional_param('coursefilter', '0', PARAM_INT); $courseitemfilter = optional_param('courseitemfilter', '0', PARAM_INT); $courseitemfiltertyp = optional_param('courseitemfiltertyp', '0', PARAM_ALPHANUM); $searchcourse = optional_param('searchcourse', '', PARAM_RAW); $courseid = optional_param('courseid', false, PARAM_INT); $url = new moodle_url('/mod/feedback/analysis_course.php', array('id'=>$id)); +navigation_node::override_active_url($url); if ($courseid !== false) { $url->param('courseid', $courseid); } -if ($coursefilter !== '0') { - $url->param('coursefilter', $coursefilter); -} if ($courseitemfilter !== '0') { $url->param('courseitemfilter', $courseitemfilter); } @@ -52,10 +49,6 @@ if ($searchcourse !== '') { } $PAGE->set_url($url); -if (($searchcourse OR $courseitemfilter OR $coursefilter) AND !confirm_sesskey()) { - print_error('invalidsesskey'); -} - if (! $cm = get_coursemodule_from_id('feedback', $id)) { print_error('invalidcoursemodule'); } @@ -83,21 +76,18 @@ $strfeedback = get_string("modulename", "feedback"); $PAGE->set_heading($course->fullname); $PAGE->set_title($feedback->name); echo $OUTPUT->header(); +echo $OUTPUT->heading(format_string($feedback->name)); /// print the tabs require('tabs.php'); //print the analysed items -echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); if (has_capability('mod/feedback:viewreports', $context)) { //button "export to excel" - echo $OUTPUT->container_start('mdl-align'); - $aurl = new moodle_url('analysis_to_excel.php', - array('sesskey' => sesskey(), - 'id' => $id, - 'coursefilter' => $coursefilter)); - + echo $OUTPUT->container_start('form-buttons'); + $aurl = new moodle_url('analysis_to_excel.php', array('sesskey' => sesskey(), 'id' => $id, + 'coursefilter' => $courseid)); echo $OUTPUT->single_button($aurl, get_string('export_to_excel', 'feedback')); echo $OUTPUT->container_end(); } @@ -106,7 +96,7 @@ if (has_capability('mod/feedback:viewreports', $context)) { //lstgroupid is the choosen id $mygroupid = false; //get completed feedbacks -$completedscount = feedback_get_completeds_group_count($feedback, $mygroupid, $coursefilter); +$completedscount = feedback_get_completeds_group_count($feedback, $mygroupid, $courseid); //show the count echo ''.get_string('completed_feedbacks', 'feedback').': '.$completedscount. '
'; @@ -117,15 +107,8 @@ $items = $DB->get_records('feedback_item', $params, 'position'); //show the count if (is_array($items)) { echo ''.get_string('questions', 'feedback').': ' .count($items). '
'; - echo ''; - echo get_string('show_all', 'feedback'); - echo ''; -} else { - $items=array(); } -echo '
'; -echo '
'; if ($courseitemfilter > 0) { $avgvalue = 'avg(value)'; if ($DB->get_dbfamily() == 'postgres') { // TODO: this should be moved to standard sql DML function ;-) @@ -140,8 +123,9 @@ if ($courseitemfilter > 0) { if ($courses = $DB->get_records_sql($sql, array($courseitemfiltertyp, $courseitemfilter))) { $item = $DB->get_record('feedback_item', array('id'=>$courseitemfilter)); - echo ''; - echo ''; + echo '
'.$item->name.'
'; + echo '

'.$item->name.'

'; + echo '
'; + echo '
'; echo ''; $sep_dec = get_string('separator_decimal', 'feedback'); $sep_thous = get_string('separator_thousand', 'feedback'); @@ -157,21 +141,21 @@ if ($courseitemfilter > 0) { echo ''; echo ''; } - echo '
CourseAverage
'; } else { - echo ''.get_string('noresults').''; + echo '

'.get_string('noresults').'

'; } + echo '

'; + echo get_string('back'); + echo '

'; } else { + echo '
'; + echo ''; echo html_writer::label(get_string('search_course', 'feedback') . ': ', 'searchcourse'); echo ' '; echo ''; - echo ''; echo ''; - echo ''; - echo ''; - echo ''; - echo html_writer::script('', $CFG->wwwroot.'/mod/feedback/feedback.js'); $sql = 'select DISTINCT c.id, c.shortname from {course} c, '. '{feedback_value} fv, {feedback_item} fi '. 'where c.id = fv.course_id and fv.item = fi.id '. @@ -182,9 +166,11 @@ if ($courseitemfilter > 0) { $params = array($feedback->id, "%$searchcourse%", "%$searchcourse%"); if ($courses = $DB->get_records_sql_menu($sql, $params)) { - - echo ' '. html_writer::label(get_string('filter_by_course', 'feedback'), 'coursefilterid'). ': '; - echo html_writer::select($courses, 'coursefilter', $coursefilter, + if (!$courseid) { + $courses = array('' => get_string('choosedots')) + $courses; + } + echo ' '. html_writer::label(get_string('filter_by_course', 'feedback'). ': ', 'coursefilterid'); + echo html_writer::select($courses, 'courseid', $courseid, null, array('id'=>'coursefilterid', 'class' => 'autosubmit')); $PAGE->requires->yui_module('moodle-core-formautosubmit', @@ -192,15 +178,22 @@ if ($courseitemfilter > 0) { array(array('selectid' => 'coursefilterid', 'nothing' => false)) ); } + if ($courseid) { + echo ' '; + echo get_string('show_all', 'feedback'); + echo ''; + } + + echo ''; + echo '
'; echo '
'; $itemnr = 0; //print the items in an analysed form - echo ''; foreach ($items as $item) { if ($item->hasvalue == 0) { continue; } - echo ''; + echo '
'; //get the class from item-typ $itemobj = feedback_get_item_class($item->typ); $itemnr++; @@ -209,25 +202,17 @@ if ($courseitemfilter > 0) { } else { $printnr = ''; } - $itemobj->print_analysed($item, $printnr, $mygroupid, $coursefilter); + $itemobj->print_analysed($item, $printnr, $mygroupid, $courseid); if (preg_match('/rated$/i', $item->typ)) { - $onclick = 'onclick="setcourseitemfilter'. - "(".$item->id.",'".$item->typ."');". - ' return false;"'; - - $anker = ''. - get_string('sort_by_course', 'feedback'). - ''; + $url = new moodle_url('/mod/feedback/analysis_course.php', array('id' => $id, + 'courseitemfilter' => $item->id, 'courseitemfiltertyp' => $item->typ)); + $anker = html_writer::link($url, get_string('sort_by_course', 'feedback')); echo ''; } echo '
'.$anker.'
'; } - echo ''; } -echo '
'; -echo ''; -echo $OUTPUT->box_end(); echo $OUTPUT->footer(); diff --git a/mod/feedback/classes/course_map_form.php b/mod/feedback/classes/course_map_form.php new file mode 100644 index 00000000000..fe92115c2e1 --- /dev/null +++ b/mod/feedback/classes/course_map_form.php @@ -0,0 +1,48 @@ +. + +/** + * Contains class mod_feedback_course_map_form + * + * @package mod_feedback + * @copyright 2016 Marina Glancy + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +defined('MOODLE_INTERNAL') || die(); + +/** + * Form for mapping courses to the feedback + * + * @package mod_feedback + * @copyright 2016 Marina Glancy + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class mod_feedback_course_map_form extends moodleform { + /** + * Definition of the form + */ + public function definition() { + $mform = $this->_form; + + $mform->addElement('hidden', 'id'); + $mform->setType('id', PARAM_INT); + + $options = array('multiple' => true); + $mform->addElement('course', 'mappedcourses', get_string('courses'), $options); + + $this->add_action_buttons(); + } +} diff --git a/mod/feedback/edit_item.php b/mod/feedback/edit_item.php index e714704de41..26e6b00cba2 100644 --- a/mod/feedback/edit_item.php +++ b/mod/feedback/edit_item.php @@ -137,11 +137,6 @@ if (isset($error)) { } $itemobj->show_editform(); -if ($typ!='label') { - $PAGE->requires->js('/mod/feedback/feedback.js'); - $PAGE->requires->js_function_call('set_item_focus', Array('id_itemname')); -} - /// Finish the page /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// diff --git a/mod/feedback/feedback.js b/mod/feedback/feedback.js index f0d214c4b23..c7c8da86460 100644 --- a/mod/feedback/feedback.js +++ b/mod/feedback/feedback.js @@ -1,22 +1,3 @@ -function set_item_focus(itemid) { - var item = document.getElementById(itemid); - if(item){ - item.focus(); - } -} - -function feedbackGo2delete(form) { - form.action = M.cfg.wwwroot+'/mod/feedback/delete_completed.php'; - form.submit(); -} - -function setcourseitemfilter(item, item_typ) { - document.report.courseitemfilter.value = item; - document.report.courseitemfiltertyp.value = item_typ; - document.report.submit(); -} - - M.mod_feedback = {}; M.mod_feedback.init_sendmessage = function(Y) { diff --git a/mod/feedback/lang/en/deprecated.txt b/mod/feedback/lang/en/deprecated.txt index 9c745916f4b..7f296854d14 100644 --- a/mod/feedback/lang/en/deprecated.txt +++ b/mod/feedback/lang/en/deprecated.txt @@ -1 +1,2 @@ completed,mod_feedback +mapcourses_help,mod_feedback diff --git a/mod/feedback/lang/en/feedback.php b/mod/feedback/lang/en/feedback.php index 74bd6291b98..e2492c50769 100644 --- a/mod/feedback/lang/en/feedback.php +++ b/mod/feedback/lang/en/feedback.php @@ -152,9 +152,8 @@ $string['mapcourse'] = 'Map feedback to courses'; $string['mapcourse_help'] = 'By default, feedback forms created on your homepage are available site-wide and will appear in all courses using the feedback block. You can force the feedback form to appear by making it a sticky block or limit the courses in which a feedback form will appear by mapping it to specific courses.'; $string['mapcourses'] = 'Map feedback to courses'; -$string['mapcourses_help'] = 'Once you have selected the relevant course(s) from your search, -you can associate them with this feedback using map course(s). Multiple courses may be selected by holding down the Apple or Ctrl key whilst clicking on the course names. A course may be disassociated from a feedback at any time.'; $string['mappedcourses'] = 'Mapped courses'; +$string['mappingchanged'] = 'Course mapping has been changed'; $string['max_args_exceeded'] = 'Max 6 arguments can be handled, too many arguments for'; $string['minimal'] = 'minimum'; $string['maximal'] = 'maximum'; @@ -291,3 +290,6 @@ $string['viewcompleted_help'] = 'You may view completed feedback forms, searchab Feedback responses may be exported to Excel.'; // Deprecated since Moodle 3.0. $string['completed'] = 'completed'; +// Deprecated since Moodle 3.1. +$string['mapcourses_help'] = 'Once you have selected the relevant course(s) from your search, +you can associate them with this feedback using map course(s). Multiple courses may be selected by holding down the Apple or Ctrl key whilst clicking on the course names. A course may be disassociated from a feedback at any time.'; diff --git a/mod/feedback/lib.php b/mod/feedback/lib.php index b5b8c81bf0a..b5846440540 100644 --- a/mod/feedback/lib.php +++ b/mod/feedback/lib.php @@ -2851,16 +2851,15 @@ function feedback_get_feedbacks_from_sitecourse_map($courseid) { } /** - * gets the courses from table feedback_sitecourse_map. + * Gets the courses from table feedback_sitecourse_map * - * @global object * @param int $feedbackid * @return array the course-records */ function feedback_get_courses_from_sitecourse_map($feedbackid) { global $DB; - $sql = "SELECT f.id, f.courseid, c.fullname, c.shortname + $sql = "SELECT c.id, c.fullname, c.shortname FROM {feedback_sitecourse_map} f, {course} c WHERE c.id = f.courseid AND f.feedbackid = ? @@ -2870,6 +2869,27 @@ function feedback_get_courses_from_sitecourse_map($feedbackid) { } +/** + * Updates the course mapping for the feedback + * + * @param stdClass $feedback + * @param array $courses array of course ids + */ +function feedback_update_sitecourse_map($feedback, $courses) { + global $DB; + if (empty($courses)) { + $courses = array(); + } + $currentmapping = $DB->get_fieldset_select('feedback_sitecourse_map', 'courseid', 'feedbackid=?', array($feedback->id)); + foreach (array_diff($courses, $currentmapping) as $courseid) { + $DB->insert_record('feedback_sitecourse_map', array('feedbackid' => $feedback->id, 'courseid' => $courseid)); + } + foreach (array_diff($currentmapping, $courses) as $courseid) { + $DB->delete_records('feedback_sitecourse_map', array('feedbackid' => $feedback->id, 'courseid' => $courseid)); + } + // TODO MDL-53574 add events. +} + /** * removes non existing courses or feedbacks from sitecourse_map. * it shouldn't be called all too often @@ -3147,7 +3167,7 @@ function feedback_encode_target_url($url) { function feedback_extend_settings_navigation(settings_navigation $settings, navigation_node $feedbacknode) { - global $PAGE, $DB; + global $PAGE; if (!$context = context_module::instance($PAGE->cm->id, IGNORE_MISSING)) { print_error('badcontext'); @@ -3176,20 +3196,22 @@ function feedback_extend_settings_navigation(settings_navigation $settings, 'do_show' => 'templates'))); } + if (has_capability('mod/feedback:mapcourse', $context) && $PAGE->course->id == SITEID) { + $feedbacknode->add(get_string('mappedcourses', 'feedback'), + new moodle_url('/mod/feedback/mapcourse.php', + array('id' => $PAGE->cm->id))); + } + if (has_capability('mod/feedback:viewreports', $context)) { - $feedback = $DB->get_record('feedback', array('id'=>$PAGE->cm->instance)); + $feedback = $PAGE->activityrecord; if ($feedback->course == SITEID) { $feedbacknode->add(get_string('analysis', 'feedback'), new moodle_url('/mod/feedback/analysis_course.php', - array('id' => $PAGE->cm->id, - 'course' => $PAGE->course->id, - 'do_show' => 'analysis'))); + array('id' => $PAGE->cm->id))); } else { $feedbacknode->add(get_string('analysis', 'feedback'), new moodle_url('/mod/feedback/analysis.php', - array('id' => $PAGE->cm->id, - 'course' => $PAGE->course->id, - 'do_show' => 'analysis'))); + array('id' => $PAGE->cm->id))); } $feedbacknode->add(get_string('show_entries', 'feedback'), diff --git a/mod/feedback/mapcourse.php b/mod/feedback/mapcourse.php index 1ea2d0d4961..6330d6effa2 100644 --- a/mod/feedback/mapcourse.php +++ b/mod/feedback/mapcourse.php @@ -22,65 +22,36 @@ * @package mod_feedback */ -require_once("../../config.php"); -require_once("lib.php"); +require_once(__DIR__ . "/../../config.php"); +require_once($CFG->dirroot . "/mod/feedback/lib.php"); require_once("$CFG->libdir/tablelib.php"); -$id = required_param('id', PARAM_INT); // Course Module ID, or -$searchcourse = optional_param('searchcourse', '', PARAM_NOTAGS); -$coursefilter = optional_param('coursefilter', '', PARAM_INT); -$courseid = optional_param('courseid', false, PARAM_INT); +$id = required_param('id', PARAM_INT); // Course Module ID. $url = new moodle_url('/mod/feedback/mapcourse.php', array('id'=>$id)); -if ($searchcourse !== '') { - $url->param('searchcourse', $searchcourse); -} -if ($coursefilter !== '') { - $url->param('coursefilter', $coursefilter); -} -if ($courseid !== false) { - $url->param('courseid', $courseid); -} $PAGE->set_url($url); -if (($formdata = data_submitted()) AND !confirm_sesskey()) { - print_error('invalidsesskey'); -} - $current_tab = 'mapcourse'; -if (! $cm = get_coursemodule_from_id('feedback', $id)) { - print_error('invalidcoursemodule'); -} - -if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { - print_error('coursemisconf'); -} - -if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { - print_error('invalidcoursemodule'); -} +list($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback'); +require_login($course, true, $cm); +$feedback = $PAGE->activityrecord; $context = context_module::instance($cm->id); - -require_login($course, true, $cm); - require_capability('mod/feedback:mapcourse', $context); -if ($coursefilter) { - $map = new stdClass; - $map->feedbackid = $feedback->id; - $map->courseid = $coursefilter; - // insert a map only if it does exists yet - $sql = "SELECT id, feedbackid - FROM {feedback_sitecourse_map} - WHERE feedbackid = ? AND courseid = ?"; - if (!$DB->get_records_sql($sql, array($map->feedbackid, $map->courseid))) { - $DB->insert_record('feedback_sitecourse_map', $map); - } +$coursemap = array_keys(feedback_get_courses_from_sitecourse_map($feedback->id)); +$form = new mod_feedback_course_map_form(); +$form->set_data(array('id' => $cm->id, 'mappedcourses' => $coursemap)); +$mainurl = new moodle_url('/mod/feedback/view.php', ['id' => $id]); +if ($form->is_cancelled()) { + redirect($mainurl); +} else if ($data = $form->get_data()) { + feedback_update_sitecourse_map($feedback, $data->mappedcourses); + redirect($mainurl, get_string('mappingchanged', 'feedback'), null, \core\output\notification::NOTIFY_SUCCESS); } -/// Print the page header +// Print the page header. $strfeedbacks = get_string("modulenameplural", "feedback"); $strfeedback = get_string("modulename", "feedback"); @@ -91,64 +62,8 @@ echo $OUTPUT->heading(format_string($feedback->name)); require('tabs.php'); -echo $OUTPUT->box(get_string('mapcourseinfo', 'feedback'), 'generalbox boxaligncenter boxwidthwide'); -echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); -echo '
'; -echo ''; -echo ''; +echo $OUTPUT->box(get_string('mapcourseinfo', 'feedback')); -$sql = "select c.id, c.shortname - from {course} c - where ".$DB->sql_like('c.shortname', '?', false)." - OR ".$DB->sql_like('c.fullname', '?', false); -$params = array("%{$searchcourse}%", "%{$searchcourse}%"); - -if (($courses = $DB->get_records_sql_menu($sql, $params)) && !empty($searchcourse)) { - echo ' '. html_writer::label(get_string('courses'), 'menucoursefilter', false). ': '; - echo html_writer::select($courses, 'coursefilter', $coursefilter); - echo ''; - echo $OUTPUT->help_icon('mapcourses', 'feedback'); - echo ''; - - echo ''; - echo ''; - echo $OUTPUT->help_icon('searchcourses', 'feedback'); -} else { - echo ' '; - echo ''; - echo $OUTPUT->help_icon('searchcourses', 'feedback'); -} - -echo '
'; - -if ($coursemap = feedback_get_courses_from_sitecourse_map($feedback->id)) { - $table = new flexible_table('coursemaps'); - $table->baseurl = $url; - $table->define_columns( array('course')); - $table->define_headers( array(get_string('mappedcourses', 'feedback'))); - - $table->setup(); - - $unmapurl = new moodle_url('/mod/feedback/unmapcourse.php'); - foreach ($coursemap as $cmap) { - $coursecontext = context_course::instance($cmap->courseid); - $cmapshortname = format_string($cmap->shortname, true, array('context' => $coursecontext)); - $cmapfullname = format_string($cmap->fullname, true, array('context' => $coursecontext)); - $unmapurl->params(array('id'=>$id, 'cmapid'=>$cmap->id)); - $anker = ''; - $anker .= 'Delete'; - $anker .= ''; - $table->add_data(array($anker.' ('.$cmapshortname.') '.$cmapfullname)); - } - - $table->print_html(); -} else { - echo $OUTPUT->heading(get_string('mapcoursenone', 'feedback'), 3); -} - - -echo $OUTPUT->box_end(); +$form->display(); echo $OUTPUT->footer(); diff --git a/mod/feedback/tabs.php b/mod/feedback/tabs.php index 71b85bf2ca5..849077bef29 100644 --- a/mod/feedback/tabs.php +++ b/mod/feedback/tabs.php @@ -43,7 +43,7 @@ if (!isset($current_tab)) { $current_tab = ''; } -$viewurl = new moodle_url('/mod/feedback/view.php', array('id'=>$usedid, 'do_show'=>'view')); +$viewurl = new moodle_url('/mod/feedback/view.php', array('id' => $usedid)); $row[] = new tabobject('view', $viewurl->out(), get_string('overview', 'feedback')); if (has_capability('mod/feedback:edititems', $context)) { @@ -54,16 +54,21 @@ if (has_capability('mod/feedback:edititems', $context)) { $row[] = new tabobject('templates', $templateurl->out(), get_string('templates', 'feedback')); } +if ($feedback->course == SITEID && has_capability('mod/feedback:mapcourse', $context)) { + $mapurl = new moodle_url('/mod/feedback/mapcourse.php', array('id' => $usedid)); + $row[] = new tabobject('mapcourse', $mapurl->out(), get_string('mappedcourses', 'feedback')); +} + if (has_capability('mod/feedback:viewreports', $context)) { if ($feedback->course == SITEID) { - $url_params = array('id'=>$usedid, 'courseid'=>$courseid, 'do_show'=>'analysis'); + $url_params = array('id' => $usedid, 'courseid' => $courseid); $analysisurl = new moodle_url('/mod/feedback/analysis_course.php', $url_params); $row[] = new tabobject('analysis', $analysisurl->out(), get_string('analysis', 'feedback')); } else { - $url_params = array('id'=>$usedid, 'courseid'=>$courseid, 'do_show'=>'analysis'); + $url_params = array('id' => $usedid); $analysisurl = new moodle_url('/mod/feedback/analysis.php', $url_params); $row[] = new tabobject('analysis', $analysisurl->out(), diff --git a/mod/feedback/tests/behat/anonymous.feature b/mod/feedback/tests/behat/anonymous.feature index 607b029693e..ac8c77f45e1 100644 --- a/mod/feedback/tests/behat/anonymous.feature +++ b/mod/feedback/tests/behat/anonymous.feature @@ -50,12 +50,6 @@ Feature: Anonymous feedback And I press "Continue" Scenario: Complete anonymous feedback on the front page as an authenticated user - And I log in as "admin" - And I set the following system permissions of "Authenticated user" role: - | capability | permission | - | mod/feedback:view | Allow | - | mod/feedback:complete | Allow | - And I log out And I log in as "user1" And I am on site homepage When I follow "Site feedback" @@ -74,8 +68,6 @@ Feature: Anonymous feedback And I log in as "admin" And I set the following system permissions of "Authenticated user on frontpage" role: | capability | permission | - | mod/feedback:view | Allow | - | mod/feedback:complete | Allow | | mod/feedback:viewanalysepage | Allow | And I log out And I log in as "user1" diff --git a/mod/feedback/tests/behat/coursemapping.feature b/mod/feedback/tests/behat/coursemapping.feature new file mode 100644 index 00000000000..ffe93861d19 --- /dev/null +++ b/mod/feedback/tests/behat/coursemapping.feature @@ -0,0 +1,226 @@ +@mod @mod_feedback +Feature: Mapping courses in a feedback + In order to collect the same feedback about multiple courses + As a manager + I need to be able to map site feedback to courses + + Background: + Given the following "users" exist: + | username | firstname | lastname | + | user1 | Username | 1 | + | user2 | Username | 2 | + | user3 | Username | 3 | + | teacher | Teacher | 4 | + | manager | Manager | 5 | + And the following "courses" exist: + | fullname | shortname | + | Course 1 | C1 | + | Course 2 | C2 | + | Course 3 | C3 | + And the following "course enrolments" exist: + | user | course | role | + | user1 | C1 | student | + | user1 | C2 | student | + | user2 | C1 | student | + | user2 | C2 | student | + | user3 | C3 | student | + | teacher | C1 | editingteacher | + | teacher | C2 | editingteacher | + | teacher | C3 | editingteacher | + And the following "system role assigns" exist: + | user | course | role | + | manager | Acceptance test site | manager | + And I log in as "admin" + And I navigate to "Manage activities" node in "Site administration > Plugins > Activity modules" + And I click on "Show" "link" in the "Feedback" "table_row" + And I navigate to "Manage blocks" node in "Site administration > Plugins > Blocks" + And I click on "Show" "link" in the "Feedback" "table_row" + And I log out + And the following "activities" exist: + | activity | name | course | idnumber | anonymous | publish_stats | + | feedback | Course feedback | Acceptance test site | feedback0 | 1 | 1 | + | feedback | Another feedback | C1 | feedback1 | 1 | 1 | + When I log in as "manager" + And I am on site homepage + And I follow "Course feedback" + And I follow "Edit questions" + And I add a "Information" question to the feedback with: + | Question | this is an information question | + | Label | info | + | Information-Type | Course | + And I add a "Multiple choice (rated)" question to the feedback with: + | Question | this is a multiple choice rated | + | Label | multichoicerated | + | Multiple choice type | Multiple choice - single answer | + | Multiple choice values | 0/option a\n1/option b\n5/option c | + And I add a "Multiple choice" question to the feedback with: + | Question | this is a simple multiple choice | + | Label | multichoicesimple | + | Multiple choice type | Multiple choice - single answer allowed (dropdownlist) | + | Multiple choice values | option d\noption e\noption f | + And I log out + And I log in as "teacher" + And I follow "Course 1" + And I turn editing mode on + And I add the "Feedback" block + And I am on site homepage + And I follow "Course 2" + And I add the "Feedback" block + And I am on site homepage + And I follow "Course 3" + And I add the "Feedback" block + And I log out + + Scenario: Course feedback can not be mapped + And I log in as "manager" + And I am on site homepage + And I follow "Course 1" + And I follow "Another feedback" + And I should not see "Mapped courses" + And I should not see "Map feedback to courses" + + @javascript + Scenario: Site feedback is not mapped to any course + And I log in as "user1" + And I am on site homepage + And I follow "Course feedback" + And I follow "Answer the questions..." + And I should see "Acceptance test site" in the ".feedback_form" "css_element" + And I set the following fields to these values: + | option a | 1 | + | this is a simple multiple choice | option d | + And I press "Submit your answers" + And I press "Continue" + And I follow "Course 1" + And I click on "Course feedback" "link" in the "Feedback" "block" + And I follow "Answer the questions..." + And I should not see "Acceptance test site" in the ".feedback_form" "css_element" + And I should see "C1" in the ".feedback_form" "css_element" + And I set the following fields to these values: + | option b | 1 | + | this is a simple multiple choice | option e | + And I press "Submit your answers" + And I press "Continue" + And I click on "Course feedback" "link" in the "Feedback" "block" + And I should not see "Answer the questions..." + And I log out + And I log in as "user2" + And I follow "Course 1" + And I click on "Course feedback" "link" in the "Feedback" "block" + And I follow "Answer the questions..." + And I should not see "Acceptance test site" in the ".feedback_form" "css_element" + And I should see "C1" in the ".feedback_form" "css_element" + And I set the following fields to these values: + | option c | 1 | + | this is a simple multiple choice | option e | + And I press "Submit your answers" + And I press "Continue" + And I log out + And I log in as "manager" + And I am on site homepage + And I follow "Course feedback" + + And I follow "Analysis" + And the field "Filter by course" matches value "Choose..." + And I should see "1 (33.33 %)" in the "option a" "table_row" + And I should see "1 (33.33 %)" in the "option b" "table_row" + And I should see "1 (33.33 %)" in the "option c" "table_row" + And I should see "Average: 2.00" in the "(multichoicerated)" "table" + And I click on "Sort by course" "link" in the "(multichoicerated)" "table" + And I should see "2.50" in the "C1" "table_row" + And I should see "1.00" in the "Acceptance test site" "table_row" + And I follow "Back" + And I set the field "Filter by course" to "C1" + And I should see "0" in the "option a" "table_row" + And I should see "1 (50.00 %)" in the "option b" "table_row" + And I should see "1 (50.00 %)" in the "option c" "table_row" + And I log out + + @javascript + Scenario: Site feedback is mapped to courses + And I log in as "manager" + And I am on site homepage + And I follow "Course feedback" + And I follow "Map feedback to courses" + And I set the field "Courses" to "Course 2" + And I set the field "Courses" to "Course 3" + And I press "Save changes" + And I log out + + And I log in as "user1" + And I am on site homepage + And I follow "Course feedback" + And I should see "You can only access this feedback from a course" + And I should not see "Answer the questions..." + + And I am on site homepage + And I follow "Course 1" + And "Feedback" "block" should not exist + And I should not see "Course feedback" + + And I am on site homepage + And I follow "Course 2" + And I click on "Course feedback" "link" in the "Feedback" "block" + And I follow "Answer the questions..." + And I should not see "Acceptance test site" in the ".feedback_form" "css_element" + And I should see "C2" in the ".feedback_form" "css_element" + And I set the following fields to these values: + | option b | 1 | + | this is a simple multiple choice | option e | + And I press "Submit your answers" + And I press "Continue" + And I click on "Course feedback" "link" in the "Feedback" "block" + And I should not see "Answer the questions..." + And I log out + And I log in as "user2" + And I follow "Course 2" + And I click on "Course feedback" "link" in the "Feedback" "block" + And I follow "Answer the questions..." + And I should not see "Acceptance test site" in the ".feedback_form" "css_element" + And I should see "C2" in the ".feedback_form" "css_element" + And I set the following fields to these values: + | option c | 1 | + | this is a simple multiple choice | option e | + And I press "Submit your answers" + And I press "Continue" + And I log out + And I log in as "user3" + And I follow "Course 3" + And I click on "Course feedback" "link" in the "Feedback" "block" + And I follow "Answer the questions..." + And I should not see "Acceptance test site" in the ".feedback_form" "css_element" + And I should see "C3" in the ".feedback_form" "css_element" + And I set the following fields to these values: + | option c | 1 | + | this is a simple multiple choice | option d | + And I press "Submit your answers" + And I press "Continue" + And I log out + And I log in as "manager" + And I am on site homepage + And I follow "Course feedback" + And I follow "Analysis" + And the field "Filter by course" matches value "Choose..." + And I should see "0" in the "option a" "table_row" + And I should see "1 (33.33 %)" in the "option b" "table_row" + And I should see "2 (66.67 %)" in the "option c" "table_row" + And I should see "Average: 3.67" in the "(multichoicerated)" "table" + And I click on "Sort by course" "link" in the "(multichoicerated)" "table" + And I should see "3.00" in the "C3" "table_row" + And I should see "2.50" in the "C2" "table_row" + And I follow "Back" + And I set the field "Filter by course" to "C2" + And I should see "0" in the "option a" "table_row" + And I should see "1 (50.00 %)" in the "option b" "table_row" + And I should see "1 (50.00 %)" in the "option c" "table_row" + And I should see "2 (100.00 %)" in the "option e" "table_row" + And I set the field "Filter by course" to "C3" + And I should see "0" in the "option a" "table_row" + And I should see "0" in the "option b" "table_row" + And I should see "1 (100.00 %)" in the "option c" "table_row" + And I should see "1 (100.00 %)" in the "option d" "table_row" + And I follow "Show all" + And I should see "1 (33.33 %)" in the "option d" "table_row" + And I should see "2 (66.67 %)" in the "option e" "table_row" + And I should see "0" in the "option f" "table_row" + And I log out diff --git a/mod/feedback/unmapcourse.php b/mod/feedback/unmapcourse.php deleted file mode 100644 index 34bb14575cc..00000000000 --- a/mod/feedback/unmapcourse.php +++ /dev/null @@ -1,62 +0,0 @@ -. - -/** - * drops records from feedback_sitecourse_map - * - * @author Andreas Grabs - * @license http://www.gnu.org/copyleft/gpl.html GNU Public License - * @package mod_feedback - */ - -require_once("../../config.php"); -require_once($CFG->dirroot.'/mod/feedback/lib.php'); - -$id = required_param('id', PARAM_INT); -$cmapid = required_param('cmapid', PARAM_INT); - -$url = new moodle_url('/mod/feedback/unmapcourse.php', array('id'=>$id)); -if ($cmapid !== '') { - $url->param('cmapid', $cmapid); -} -$PAGE->set_url($url); - -if (! $cm = get_coursemodule_from_id('feedback', $id)) { - print_error('invalidcoursemodule'); -} - -if (! $course = $DB->get_record("course", array("id"=>$cm->course))) { - print_error('coursemisconf'); -} - -if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) { - print_error('invalidcoursemodule'); -} - -$context = context_module::instance($cm->id); - -require_capability('mod/feedback:mapcourse', $context); - -// cleanup all lost entries after deleting courses or feedbacks -feedback_clean_up_sitecourse_map(); - -if ($DB->delete_records('feedback_sitecourse_map', array('id'=>$cmapid))) { - $mapurl = new moodle_url('/mod/feedback/mapcourse.php', array('id'=>$id)); - redirect ($mapurl->out(false)); -} else { - print_error('cannotunmap', 'feedback'); -} - diff --git a/mod/feedback/upgrade.txt b/mod/feedback/upgrade.txt index eee47a8938e..b9826d9b97c 100644 --- a/mod/feedback/upgrade.txt +++ b/mod/feedback/upgrade.txt @@ -1,3 +1,7 @@ +=== 3.1 === + +* feedback_get_courses_from_sitecourse_map() now returns course id as 'id' attribute + === 2.7 === * The validation of the following events is now stricter (see MDL-45445): diff --git a/mod/feedback/view.php b/mod/feedback/view.php index 0819c750fd3..69ecb9e40b2 100644 --- a/mod/feedback/view.php +++ b/mod/feedback/view.php @@ -69,7 +69,7 @@ if ($course->id == SITEID) { $PAGE->set_cm($cm, $course); $PAGE->set_pagelayout('incourse'); } -$PAGE->set_url('/mod/feedback/view.php', array('id'=>$cm->id, 'do_show'=>'view')); +$PAGE->set_url('/mod/feedback/view.php', array('id' => $cm->id)); $PAGE->set_title($feedback->name); $PAGE->set_heading($course->fullname); @@ -136,13 +136,22 @@ echo $OUTPUT->heading(format_string($feedback->name) . $preview); // Print the tabs. require('tabs.php'); +// Show description. +echo $OUTPUT->box_start('generalbox feedback_description'); +$options = (object)array('noclean' => true); +echo format_module_intro('feedback', $feedback, $cm->id); +echo $OUTPUT->box_end(); + //show some infos to the feedback if (has_capability('mod/feedback:edititems', $context)) { + + echo $OUTPUT->heading(get_string('overview', 'feedback'), 3); + //get the groupid $groupselect = groups_print_activity_menu($cm, $CFG->wwwroot.'/mod/feedback/view.php?id='.$cm->id, true); $mygroupid = groups_get_activity_group($cm); - echo $OUTPUT->box_start('boxaligncenter boxwidthwide'); + echo $OUTPUT->box_start('boxaligncenter'); echo $groupselect.'
 
'; $completedscount = feedback_get_completeds_group_count($feedback, $mygroupid); echo $OUTPUT->box_start('feedback_info'); @@ -188,14 +197,6 @@ if (has_capability('mod/feedback:edititems', $context)) { echo $OUTPUT->box_end(); } -if (has_capability('mod/feedback:edititems', $context)) { - echo $OUTPUT->heading(get_string('description', 'feedback'), 3); -} -echo $OUTPUT->box_start('generalbox boxwidthwide'); -$options = (object)array('noclean'=>true); -echo format_module_intro('feedback', $feedback, $cm->id); -echo $OUTPUT->box_end(); - if (has_capability('mod/feedback:edititems', $context)) { require_once($CFG->libdir . '/filelib.php'); @@ -207,7 +208,7 @@ if (has_capability('mod/feedback:edititems', $context)) { 0); echo $OUTPUT->heading(get_string("page_after_submit", "feedback"), 3); - echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); + echo $OUTPUT->box_start('generalbox feedback_after_submit'); echo format_text($page_after_submit_output, $feedback->page_after_submitformat, array('overflowdiv'=>true)); @@ -215,37 +216,22 @@ if (has_capability('mod/feedback:edititems', $context)) { echo $OUTPUT->box_end(); } -if ( (intval($feedback->publish_stats) == 1) AND - ( has_capability('mod/feedback:viewanalysepage', $context)) AND - !( has_capability('mod/feedback:viewreports', $context)) ) { - - $params = array('userid'=>$USER->id, 'feedback'=>$feedback->id); - if ($multiple_count = $DB->count_records('feedback_tracking', $params)) { - $url_params = array('id'=>$id, 'courseid'=>$courseid); - $analysisurl = new moodle_url('/mod/feedback/analysis.php', $url_params); - echo '
'; - echo get_string('completed_feedbacks', 'feedback').''; - echo '
'; - } +if (!has_capability('mod/feedback:viewreports', $context) && + feedback_can_view_analysis($feedback, $context, $courseid)) { + $analysisurl = new moodle_url('/mod/feedback/analysis.php', array('id' => $id)); + echo '
'; + echo get_string('completed_feedbacks', 'feedback').''; + echo '
'; } //####### mapcourse-start -if (has_capability('mod/feedback:mapcourse', $context)) { - if ($feedback->course == SITEID) { - echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); - echo '
'; - echo '
'; - echo '
'; - echo ''; - echo ''; - echo ''; - echo $OUTPUT->help_icon('mapcourse', 'feedback'); - echo '
'; - echo '
'; - echo '
'; - echo '
'; - echo $OUTPUT->box_end(); - } +if (has_capability('mod/feedback:mapcourse', $context) && $feedback->course == SITEID) { + echo $OUTPUT->box_start('generalbox feedback_mapped_courses'); + echo $OUTPUT->heading(get_string("mappedcourses", "feedback"), 3); + echo '

' . get_string('mapcourse_help', 'feedback') . '

'; + $mapurl = new moodle_url('/mod/feedback/mapcourse.php', array('id' => $id)); + echo '

' . html_writer::link($mapurl, get_string('mapcourses', 'feedback')) . '

'; + echo $OUTPUT->box_end(); } //####### mapcourse-end