Permalink
Browse files

MDL-19488 - allow the creation of a "Public" feedback

  • Loading branch information...
1 parent 6731a04 commit 485ec5941e1fe76b1c0f5c2a9d943f47b47e8a0c @grabs grabs committed Oct 8, 2011
Showing with 103 additions and 34 deletions.
  1. +3 −2 mod/feedback/delete_template.php
  2. +9 −11 mod/feedback/edit.php
  3. +18 −6 mod/feedback/edit_form.php
  4. +72 −14 mod/feedback/lib.php
  5. +1 −1 mod/feedback/version.php
@@ -104,15 +104,16 @@
$mform->display();
echo $OUTPUT->box_end();
}else {
- $templates = feedback_get_template_list($course, true);
+ $templates = feedback_get_template_list($course, 'own');
echo '<div class="mdl-align">';
if(!is_array($templates)) {
echo $OUTPUT->box(get_string('no_templates_available_yet', 'feedback'), 'generalbox boxaligncenter');
}else {
echo '<table width="30%">';
echo '<tr><th>'.get_string('templates', 'feedback').'</th><th>&nbsp;</th></tr>';
foreach($templates as $template) {
- echo '<tr><td align="center">'.$template->name.'</td>';
+ $suffix = $template->ispublic ? (' ('.get_string('public', 'feedback').')') : '';
+ echo '<tr><td align="left">'.$template->name.$suffix.'</td>';
echo '<td align="center">';
echo '<form action="delete_template.php" method="post">';
echo '<input title="'.get_string('delete_template','feedback').'" type="image" src="'.$OUTPUT->pix_url('t/delete') . '" hspace="1" height="11" width="11" border="0" />';
View
@@ -85,28 +85,26 @@
//the create_template-form
$create_template_form = new feedback_edit_create_template_form();
-$create_template_form->set_feedbackdata(array('context' => $context));
+$create_template_form->set_feedbackdata(array('context'=>$context, 'course'=>$course));
$create_template_form->set_form_elements();
$create_template_form->set_data(array('id'=>$id, 'do_show'=>'templates'));
$create_template_formdata = $create_template_form->get_data();
if(isset($create_template_formdata->savetemplate) && $create_template_formdata->savetemplate == 1) {
//check the capabilities to create templates
if(!has_capability('mod/feedback:createprivatetemplate', $context) AND
- !has_capability('mod/feedback:createpublictemplate', $context)) {
+ !has_capability('mod/feedback:createpublictemplate', $context)) {
print_error('cannotsavetempl', 'feedback');
}
- if(trim($create_template_formdata->templatename) == '')
- {
+ if(trim($create_template_formdata->templatename) == '') {
$savereturn = 'notsaved_name';
}else {
- //public templates are currently deaktivated
- // if(has_capability('mod/feedback:createpublictemplate', $context)) {
- // $create_template_formdata->ispublic = isset($create_template_formdata->ispublic) ? 1 : 0;
- // }else {
+ //if the feedback is located on the frontpage then templates can be public
+ if($CFG->frontpage === $course->id && has_capability('mod/feedback:createpublictemplate', $context)) {
+ $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))
- {
+ }
+ if(!feedback_save_as_template($feedback, $create_template_formdata->templatename, $create_template_formdata->ispublic)) {
$savereturn = 'failed';
}else {
$savereturn = 'saved';
View
@@ -77,11 +77,19 @@ function set_form_elements(){
// visible elements
$templates_options = array();
- if($templates = feedback_get_template_list($this->feedbackdata->course)){//get the templates
+ $owntemplates = feedback_get_template_list($this->feedbackdata->course, 'own');
+ $publictemplates = feedback_get_template_list($this->feedbackdata->course, 'public');
+ if($owntemplates OR $publictemplates){//get the templates
$templates_options[' '] = get_string('select');
- foreach($templates as $template) {
+ foreach($owntemplates as $template) {
+ if($template->ispublic) {
+ continue;
+ }
$templates_options[$template->id] = $template->name;
}
+ foreach($publictemplates as $template) {
+ $templates_options[$template->id] = '*'.$template->name;
+ }
$attributes = 'onChange="this.form.submit()"';
$elementgroup[] =& $mform->createElement('select', 'templateid', '', $templates_options, $attributes);
// buttons
@@ -114,6 +122,8 @@ function set_feedbackdata($data) {
}
function set_form_elements(){
+ global $CFG;
+
$mform =& $this->_form;
// $capabilities = $this->feedbackdata->capabilities;
@@ -134,10 +144,12 @@ function set_form_elements(){
$elementgroup[] =& $mform->createElement('static', 'templatenamelabel', get_string('name', 'feedback'));
$elementgroup[] =& $mform->createElement('text', 'templatename', get_string('name', 'feedback'), array('size'=>'40', 'maxlength'=>'200'));
- //public templates are currently deactivated
- // if(has_capability('mod/feedback:createpublictemplate', $this->feedbackdata->context)) {
- // $elementgroup[] =& $mform->createElement('checkbox', 'ispublic', get_string('public', 'feedback'), get_string('public', 'feedback'));
- // }
+ //If the feedback is located on the frontpage the we can create public templates
+ if($CFG->frontpage === $this->feedbackdata->course->id) {
+ if(has_capability('mod/feedback:createpublictemplate', $this->feedbackdata->context)) {
+ $elementgroup[] =& $mform->createElement('checkbox', 'ispublic', get_string('public', 'feedback'), get_string('public', 'feedback'));
+ }
+ }
// buttons
$elementgroup[] =& $mform->createElement('submit', 'create_template', get_string('save_as_new_template', 'feedback'));
View
@@ -138,6 +138,9 @@ function feedback_update_instance($feedback) {
/**
* Serves the files included in feedback items like label. Implements needed access control ;-)
*
+ * There are two situations in general where the files will be sent.
+ * 1) filearea = item, 2) filearea = template
+ *
* @param object $course
* @param object $cm
* @param object $context
@@ -149,17 +152,59 @@ function feedback_update_instance($feedback) {
function feedback_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
global $CFG, $DB;
- require_login($course, false, $cm);
-
$itemid = (int)array_shift($args);
- require_course_login($course, true, $cm);
-
+ //get the item what includes the file
if (!$item = $DB->get_record('feedback_item', array('id'=>$itemid))) {
return false;
}
+
+ //if the filearea is "item" so we check the permissions like view/complete the feedback
+ if($filearea === 'item') {
+ //get the feedback
+ if(!$feedback = $DB->get_record('feedback', array('id'=>$item->feedback))) {
+ return false;
+ }
- if (!has_capability('mod/feedback:view', $context)) {
+ $canload = false;
+ //first check whether the user has the complete capability
+ if(has_capability('mod/feedback:complete', $context)) {
+ $canload = true;
+ }
+
+ //now we check whether the user has the view capability
+ if(has_capability('mod/feedback:view', $context)) {
+ $canload = true;
+ }
+
+ //if the feedback is on frontpage and anonymous and the fullanonymous is allowed
+ //so the file can be loaded too.
+ if(isset($CFG->feedback_allowfullanonymous)
+ AND $CFG->feedback_allowfullanonymous
+ AND $course->id == SITEID
+ AND $feedback->anonymous == FEEDBACK_ANONYMOUS_YES ) {
+ $canload = true;
+ }
+
+ if(!$canload) {
+ return false;
+ }
+ }else if($filearea === 'template') { //now we check files in templates
+ if(!$template = $DB->get_record('feedback_template', array('id'=>$item->template))) {
+ return false;
+ }
+
+ //if the file is not public so the capability edititems has to be there
+ if(!$template->ispublic) {
+ if(!has_capability('mod/feedback:edititems', $context)) {
+ return false;
+ }
+ }else { //on public templates, at least the user has to be logged in
+ if(!isloggedin()) {
+ return false;
+ }
+ }
+ }else {
return false;
}
@@ -1073,14 +1118,21 @@ function feedback_items_from_template($feedback, $templateid, $deleteold = false
$fs = get_file_storage();
+ if(!$template = $DB->get_record('feedback_template', array('id'=>$templateid))) {
+ return false;
+ }
//get all templateitems
if(!$templitems = $DB->get_records('feedback_item', array('template'=>$templateid))) {
return false;
}
//files in the template_item are in the context of the current course
//files in the feedback_item are in the feedback_context of the feedback
- $c_context = get_context_instance(CONTEXT_COURSE, $feedback->course);
+ if($template->ispublic) {
+ $c_context = get_context_instance(CONTEXT_COURSE, $template->course);
+ }else {
+ $c_context = get_context_instance(CONTEXT_COURSE, $feedback->course);
+ }
$course = $DB->get_record('course', array('id'=>$feedback->course));
$cm = get_coursemodule_from_instance('feedback', $feedback->id);
$f_context = get_context_instance(CONTEXT_MODULE, $cm->id);
@@ -1128,7 +1180,7 @@ function feedback_items_from_template($feedback, $templateid, $deleteold = false
$item->position = $item->position + $positionoffset;
$item->id = $DB->insert_record('feedback_item', $item);
-
+
//TODO: moving the files to the new items
if ($templatefiles = $fs->get_area_files($c_context->id, 'mod_feedback', 'template', $t_item->id, "id", false)) {
foreach($templatefiles as $tfile) {
@@ -1162,16 +1214,22 @@ function feedback_items_from_template($feedback, $templateid, $deleteold = false
*
* @global object
* @param object $course
- * @param boolean $onlyown
+ * @param string $onlyownorpublic
* @return array the template recordsets
*/
-function feedback_get_template_list($course, $onlyown = false) {
- global $DB;
+function feedback_get_template_list($course, $onlyownorpublic = '') {
+ global $DB, $CFG;
- if ($onlyown) {
- $templates = $DB->get_records('feedback_template', array('course'=>$course->id));
- } else {
- $templates = $DB->get_records_select('feedback_template', 'course = ? OR ispublic = 1', array($course->id));
+ switch($onlyownorpublic) {
+ case '':
+ $templates = $DB->get_records_select('feedback_template', 'course = ? OR ispublic = 1', array($course->id), 'name');
+ break;
+ case 'own':
+ $templates = $DB->get_records('feedback_template', array('course'=>$course->id), 'name');
+ break;
+ case 'public':
+ $templates = $DB->get_records('feedback_template', array('course'=>$CFG->frontpage, 'ispublic'=>1), 'name');
+ break;
}
return $templates;
}
View
@@ -9,7 +9,7 @@
*/
- $module->version = 2011051600; // The current module version (Date: YYYYMMDDXX)
+ $module->version = 2011100800; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2010080300; // Requires this Moodle version
$feedback_version_intern = 1; //this version is used for restore older backups
$module->cron = 0; // Period for cron to check this module (secs)

0 comments on commit 485ec59

Please sign in to comment.