Commit 1d981ae4 authored by Eloy Lafuente's avatar Eloy Lafuente
Browse files

Merge branch 'wip-MDL-53443-master' of https://github.com/marinaglancy/moodle

parents f40b444e df003a85
...@@ -1266,7 +1266,7 @@ class behat_general extends behat_base { ...@@ -1266,7 +1266,7 @@ class behat_general extends behat_base {
* @param string $link the text of the link. * @param string $link the text of the link.
* @return string the content of the downloaded file. * @return string the content of the downloaded file.
*/ */
protected function download_file_from_link($link) { public function download_file_from_link($link) {
// Find the link. // Find the link.
$linknode = $this->find_link($link); $linknode = $this->find_link($link);
$this->ensure_node_is_visible($linknode); $this->ensure_node_is_visible($linknode);
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Contains class mod_feedback_templates_table
*
* @package mod_feedback
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . '/tablelib.php');
/**
* Class mod_feedback_templates_table
*
* @package mod_feedback
* @copyright 2016 Marina Glancy
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_feedback_templates_table extends flexible_table {
/**
* Constructor
* @param int $uniqueid all tables have to have a unique id, this is used
* as a key when storing table properties like sort order in the session.
* @param moodle_url $baseurl
*/
public function __construct($uniqueid, $baseurl) {
parent::__construct($uniqueid);
$tablecolumns = array('template', 'action');
$tableheaders = array(get_string('template', 'feedback'), '');
$this->set_attribute('class', 'templateslist');
$this->define_columns($tablecolumns);
$this->define_headers($tableheaders);
$this->define_baseurl($baseurl);
$this->column_class('template', 'template');
$this->column_class('action', 'action');
$this->sortable(false);
}
/**
* Displays the table with the given set of templates
* @param array $templates
*/
public function display($templates) {
global $OUTPUT;
if (empty($templates)) {
echo $OUTPUT->box(get_string('no_templates_available_yet', 'feedback'),
'generalbox boxaligncenter');
return;
}
$this->setup();
$strdeletefeedback = get_string('delete_template', 'feedback');
foreach ($templates as $template) {
$data = array();
$data[] = format_string($template->name);
$url = new moodle_url($this->baseurl, array('deletetempl' => $template->id));
$data[] = $OUTPUT->single_button($url, $strdeletefeedback, 'post');
$this->add_data($data);
}
$this->finish_output();
}
}
...@@ -24,82 +24,35 @@ ...@@ -24,82 +24,35 @@
require_once("../../config.php"); require_once("../../config.php");
require_once("lib.php"); require_once("lib.php");
require_once('delete_template_form.php');
require_once($CFG->libdir.'/tablelib.php');
$current_tab = 'templates'; $current_tab = 'templates';
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$canceldelete = optional_param('canceldelete', false, PARAM_INT);
$shoulddelete = optional_param('shoulddelete', false, PARAM_INT);
$deletetempl = optional_param('deletetempl', false, PARAM_INT); $deletetempl = optional_param('deletetempl', false, PARAM_INT);
$url = new moodle_url('/mod/feedback/delete_template.php', array('id'=>$id)); $baseurl = new moodle_url('/mod/feedback/delete_template.php', array('id' => $id));
if ($canceldelete !== false) { $PAGE->set_url($baseurl);
$url->param('canceldelete', $canceldelete);
}
if ($shoulddelete !== false) {
$url->param('shoulddelete', $shoulddelete);
}
if ($deletetempl !== false) {
$url->param('deletetempl', $deletetempl);
}
$PAGE->set_url($url);
if (($formdata = data_submitted()) AND !confirm_sesskey()) {
print_error('invalidsesskey');
}
if ($canceldelete == 1) {
$editurl = new moodle_url('/mod/feedback/edit.php', array('id'=>$id, 'do_show'=>'templates'));
redirect($editurl->out(false));
}
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');
$context = context_module::instance($cm->id); $context = context_module::instance($cm->id);
require_login($course, true, $cm); require_login($course, true, $cm);
require_capability('mod/feedback:deletetemplate', $context); require_capability('mod/feedback:deletetemplate', $context);
$mform = new mod_feedback_delete_template_form(); $feedback = $PAGE->activityrecord;
$newformdata = array('id'=>$id, $systemcontext = context_system::instance();
'deletetempl'=>$deletetempl,
'confirmdelete'=>'1');
$mform->set_data($newformdata); // Process template deletion.
$formdata = $mform->get_data(); if ($deletetempl && optional_param('confirm', 0, PARAM_BOOL) && confirm_sesskey()) {
$template = $DB->get_record('feedback_template', array('id' => $deletetempl), '*', MUST_EXIST);
$deleteurl = new moodle_url('/mod/feedback/delete_template.php', array('id'=>$id));
if ($mform->is_cancelled()) {
redirect($deleteurl->out(false));
}
if (isset($formdata->confirmdelete) AND $formdata->confirmdelete == 1) {
if (!$template = $DB->get_record("feedback_template", array("id"=>$deletetempl))) {
print_error('error');
}
if ($template->ispublic) { if ($template->ispublic) {
$systemcontext = context_system::instance();
require_capability('mod/feedback:createpublictemplate', $systemcontext); require_capability('mod/feedback:createpublictemplate', $systemcontext);
require_capability('mod/feedback:deletetemplate', $systemcontext); require_capability('mod/feedback:deletetemplate', $systemcontext);
} }
feedback_delete_template($template); feedback_delete_template($template);
redirect($deleteurl->out(false)); redirect($baseurl, get_string('template_deleted', 'feedback'));
} }
/// Print the page header /// Print the page header
...@@ -107,6 +60,8 @@ $strfeedbacks = get_string("modulenameplural", "feedback"); ...@@ -107,6 +60,8 @@ $strfeedbacks = get_string("modulenameplural", "feedback");
$strfeedback = get_string("modulename", "feedback"); $strfeedback = get_string("modulename", "feedback");
$strdeletefeedback = get_string('delete_template', 'feedback'); $strdeletefeedback = get_string('delete_template', 'feedback');
navigation_node::override_active_url(new moodle_url('/mod/feedback/edit.php',
array('id' => $id, 'do_show' => 'templates')));
$PAGE->set_heading($course->fullname); $PAGE->set_heading($course->fullname);
$PAGE->set_title($feedback->name); $PAGE->set_title($feedback->name);
echo $OUTPUT->header(); echo $OUTPUT->header();
...@@ -119,100 +74,30 @@ require('tabs.php'); ...@@ -119,100 +74,30 @@ require('tabs.php');
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
echo $OUTPUT->heading($strdeletefeedback, 3); echo $OUTPUT->heading($strdeletefeedback, 3);
if ($shoulddelete == 1) { if ($deletetempl) {
$continueurl = new moodle_url($baseurl, array('deletetempl' => $deletetempl, 'confirm' => 1, 'sesskey' => sesskey()));
echo $OUTPUT->box_start('generalbox errorboxcontent boxaligncenter boxwidthnormal'); echo $OUTPUT->confirm(get_string('confirmdeletetemplate', 'feedback'), $continueurl, $baseurl);
echo html_writer::tag('p', get_string('confirmdeletetemplate', 'feedback'), array('class' => 'bold'));
$mform->display();
echo $OUTPUT->box_end();
} else { } else {
//first we get the own templates // First we get the course templates.
$templates = feedback_get_template_list($course, 'own'); $templates = feedback_get_template_list($course, 'own');
if (!is_array($templates)) { echo $OUTPUT->box_start('coursetemplates');
echo $OUTPUT->box(get_string('no_templates_available_yet', 'feedback'), echo $OUTPUT->heading(get_string('course'), 4);
'generalbox boxaligncenter'); $tablecourse = new mod_feedback_templates_table('feedback_template_course_table', $baseurl);
} else { $tablecourse->display($templates);
echo $OUTPUT->heading(get_string('course'), 4); echo $OUTPUT->box_end();
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal'); // Now we get the public templates if it is permitted.
$tablecolumns = array('template', 'action');
$tableheaders = array(get_string('template', 'feedback'), '');
$tablecourse = new flexible_table('feedback_template_course_table');
$tablecourse->define_columns($tablecolumns);
$tablecourse->define_headers($tableheaders);
$tablecourse->define_baseurl($deleteurl);
$tablecourse->column_style('action', 'width', '10%');
$tablecourse->sortable(false);
$tablecourse->set_attribute('width', '100%');
$tablecourse->set_attribute('class', 'generaltable');
$tablecourse->setup();
foreach ($templates as $template) {
$data = array();
$data[] = $template->name;
$url = new moodle_url($deleteurl, array(
'id'=>$id,
'deletetempl'=>$template->id,
'shoulddelete'=>1,
));
$data[] = $OUTPUT->single_button($url, $strdeletefeedback, 'post');
$tablecourse->add_data($data);
}
$tablecourse->finish_output();
echo $OUTPUT->box_end();
}
//now we get the public templates if it is permitted
$systemcontext = context_system::instance();
if (has_capability('mod/feedback:createpublictemplate', $systemcontext) AND if (has_capability('mod/feedback:createpublictemplate', $systemcontext) AND
has_capability('mod/feedback:deletetemplate', $systemcontext)) { has_capability('mod/feedback:deletetemplate', $systemcontext)) {
$templates = feedback_get_template_list($course, 'public'); $templates = feedback_get_template_list($course, 'public');
if (!is_array($templates)) { echo $OUTPUT->box_start('publictemplates');
echo $OUTPUT->box(get_string('no_templates_available_yet', 'feedback'), echo $OUTPUT->heading(get_string('public', 'feedback'), 4);
'generalbox boxaligncenter'); $tablepublic = new mod_feedback_templates_table('feedback_template_public_table', $baseurl);
} else { $tablepublic->display($templates);
echo $OUTPUT->heading(get_string('public', 'feedback'), 4); echo $OUTPUT->box_end();
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnormal');
$tablecolumns = array('template', 'action');
$tableheaders = array(get_string('template', 'feedback'), '');
$tablepublic = new flexible_table('feedback_template_public_table');
$tablepublic->define_columns($tablecolumns);
$tablepublic->define_headers($tableheaders);
$tablepublic->define_baseurl($deleteurl);
$tablepublic->column_style('action', 'width', '10%');
$tablepublic->sortable(false);
$tablepublic->set_attribute('width', '100%');
$tablepublic->set_attribute('class', 'generaltable');
$tablepublic->setup();
foreach ($templates as $template) {
$data = array();
$data[] = $template->name;
$url = new moodle_url($deleteurl, array(
'id'=>$id,
'deletetempl'=>$template->id,
'shoulddelete'=>1,
));
$data[] = $OUTPUT->single_button($url, $strdeletefeedback, 'post');
$tablepublic->add_data($data);
}
$tablepublic->finish_output();
echo $OUTPUT->box_end();
}
} }
echo $OUTPUT->box_start('boxaligncenter boxwidthnormal'); $url = new moodle_url('/mod/feedback/edit.php', array('id' => $id, 'do_show' => 'templates'));
$url = new moodle_url($deleteurl, array(
'id'=>$id,
'canceldelete'=>1,
));
echo $OUTPUT->single_button($url, get_string('back'), 'post'); echo $OUTPUT->single_button($url, get_string('back'), 'post');
echo $OUTPUT->box_end();
} }
echo $OUTPUT->footer(); echo $OUTPUT->footer();
......
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* prints the form to confirm delete a completed
*
* @author Andreas Grabs
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @package mod_feedback
*/
//It must be included from a Moodle page
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.');
}
require_once($CFG->libdir.'/formslib.php');
class mod_feedback_delete_template_form extends moodleform {
public function definition() {
$mform =& $this->_form;
// hidden elements
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->addElement('hidden', 'deletetempl');
$mform->setType('deletetempl', PARAM_INT);
$mform->addElement('hidden', 'confirmdelete');
$mform->setType('confirmdelete', PARAM_INT);
//-------------------------------------------------------------------------------
// buttons
$this->add_action_buttons(true, get_string('yes'));
}
}
...@@ -94,34 +94,20 @@ if ($switchitemrequired) { ...@@ -94,34 +94,20 @@ if ($switchitemrequired) {
exit; exit;
} }
//The create_template-form // Process the create template form.
$create_template_form = new feedback_edit_create_template_form(); $cancreatetemplates = has_capability('mod/feedback:createprivatetemplate', $context) ||
$create_template_form->set_feedbackdata(array('context'=>$context, 'course'=>$course)); has_capability('mod/feedback:createpublictemplate', $context);
$create_template_form->set_form_elements(); $create_template_form = new feedback_edit_create_template_form(null, array('id' => $id));
$create_template_form->set_data(array('id'=>$id, 'do_show'=>'templates')); if ($data = $create_template_form->get_data()) {
$create_template_formdata = $create_template_form->get_data(); // Check the capabilities to create templates.
if (isset($create_template_formdata->savetemplate) && $create_template_formdata->savetemplate == 1) { if (!$cancreatetemplates) {
//Check the capabilities to create templates. print_error('cannotsavetempl', 'feedback', $url);
if (!has_capability('mod/feedback:createprivatetemplate', $context) AND
!has_capability('mod/feedback:createpublictemplate', $context)) {
print_error('cannotsavetempl', 'feedback');
} }
if (trim($create_template_formdata->templatename) == '') { $ispublic = !empty($data->ispublic) ? 1 : 0;
$savereturn = 'notsaved_name'; if (!feedback_save_as_template($feedback, $data->templatename, $ispublic)) {
redirect($url, get_string('saving_failed', 'feedback'), null, \core\output\notification::NOTIFY_ERROR);
} else { } else {
//If the feedback is located on the frontpage then templates can be public. redirect($url, get_string('template_saved', 'feedback'), null, \core\output\notification::NOTIFY_SUCCESS);
if (has_capability('mod/feedback:createpublictemplate', context_system::instance())) {
$create_template_formdata->ispublic = isset($create_template_formdata->ispublic) ? 1 : 0;
} else {
$create_template_formdata->ispublic = 0;
}
if (!feedback_save_as_template($feedback,
$create_template_formdata->templatename,
$create_template_formdata->ispublic)) {
$savereturn = 'failed';
} else {
$savereturn = 'saved';
}
} }
} }
...@@ -141,10 +127,7 @@ $lastposition++; ...@@ -141,10 +127,7 @@ $lastposition++;
//The use_template-form //The use_template-form
$use_template_form = new feedback_edit_use_template_form('use_templ.php'); $use_template_form = new feedback_edit_use_template_form('use_templ.php', array('course' => $course, 'id' => $id));
$use_template_form->set_feedbackdata(array('course' => $course));
$use_template_form->set_form_elements();
$use_template_form->set_data(array('id'=>$id));
//Print the page header. //Print the page header.
$strfeedbacks = get_string('modulenameplural', 'feedback'); $strfeedbacks = get_string('modulenameplural', 'feedback');
...@@ -178,36 +161,13 @@ require('tabs.php'); ...@@ -178,36 +161,13 @@ require('tabs.php');
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
$savereturn=isset($savereturn)?$savereturn:'';
//Print the messages.
if ($savereturn == 'notsaved_name') {
echo '<p align="center"><b><font color="red">'.
get_string('name_required', 'feedback').
'</font></b></p>';
}
if ($savereturn == 'saved') {
echo '<p align="center"><b><font color="green">'.
get_string('template_saved', 'feedback').
'</font></b></p>';
}
if ($savereturn == 'failed') {
echo '<p align="center"><b><font color="red">'.
get_string('saving_failed', 'feedback').
'</font></b></p>';
}
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
///Print the template-section. ///Print the template-section.
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
if ($do_show == 'templates') { if ($do_show == 'templates') {
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
$use_template_form->display(); $use_template_form->display();
if (has_capability('mod/feedback:createprivatetemplate', $context) OR if ($cancreatetemplates) {
has_capability('mod/feedback:createpublictemplate', $context)) {
$deleteurl = new moodle_url('/mod/feedback/delete_template.php', array('id' => $id)); $deleteurl = new moodle_url('/mod/feedback/delete_template.php', array('id' => $id));
$create_template_form->display(); $create_template_form->display();
echo '<p><a href="'.$deleteurl->out().'">'. echo '<p><a href="'.$deleteurl->out().'">'.
...@@ -226,7 +186,6 @@ if ($do_show == 'templates') { ...@@ -226,7 +186,6 @@ if ($do_show == 'templates') {
<a href="'.$importurl->out().'">'.get_string('import_questions', 'feedback').'</a> <a href="'.$importurl->out().'">'.get_string('import_questions', 'feedback').'</a>
</p>'; </p>';
} }
echo $OUTPUT->box_end();
} }
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
///Print the Item-Edit-section. ///Print the Item-Edit-section.
......
<
...@@ -30,34 +30,15 @@ if (!defined('MOODLE_INTERNAL')) { ...@@ -30,34 +30,15 @@ if (!defined('MOODLE_INTERNAL')) {
require_once($CFG->libdir.'/formslib.php'); require_once($CFG->libdir.'/formslib.php');
class feedback_edit_use_template_form extends moodleform { class feedback_edit_use_template_form extends moodleform {
private $feedbackdata;
/**
* Form definition
*/
public function definition() { public function definition() {
$this->feedbackdata = new stdClass();
//this function can not be called, because not all data are available at this time
//I use set_form_elements instead
}
//this function set the data used in set_form_elements()
//in this form the only value have to set is course
//eg: array('course' => $course)
public function set_feedbackdata($data) {
if (is_array($data)) {
if (!isset($this->feedbackdata)) {
$this->feedbackdata = new stdClass();
}
foreach ($data as $key => $val) {
$this->feedbackdata->{$key} = $val;
}
}
}
//here the elements will be set
//this function have to be called manually
//the advantage is that the data are already set
public function set_form_elements() {
$mform =& $this->_form; $mform =& $this->_form;
$course = $this->_customdata['course'];
$elementgroup = array(); $elementgroup = array();
//headline //headline
$mform->addElement('header', 'using_templates', get_string('using_templates', 'feedback')); $mform->addElement('header', 'using_templates', get_string('using_templates', 'feedback'));
...@@ -67,17 +48,17 @@ class feedback_edit_use_template_form extends moodleform { ...@@ -67,17 +48,17 @@ class feedback_edit_use_template_form extends moodleform {
// visible elements // visible elements
$templates_options = array(); $templates_options = array();
$owntemplates = feedback_get_template_list($this->feedbackdata->course, 'own'); $owntemplates = feedback_get_template_list($course, 'own');
$publictemplates = feedback_get_template_list($this->feedbackdata->course, 'public'); $publictemplates = feedback_get_template_list($course, 'public');
$options = array(); $options = array();
if ($owntemplates or $publictemplates) { if ($owntemplates or $publictemplates) {
$options[''] = array('' => get_string('choose')); $options[''] = array('' => get_string('choosedots'));
if ($owntemplates) { if ($owntemplates) {
$courseoptions = array(); $courseoptions = array();
foreach ($owntemplates as $template) { foreach ($owntemplates as $template) {
$courseoptions[$template->id] = $template->name; $courseoptions[$template->id] = format_string($template->name);
} }
$options[get_string('course')] = $courseoptions; $options[get_string('course')] = $courseoptions;
} }
...@@ -85,7 +66,7 @@ class feedback_edit_use_template_form extends moodleform { ...@@ -85,7 +66,7 @@ class feedback_edit_use_template_form extends moodleform {
if ($publictemplates) { if ($publictemplates) {