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

This commit is contained in:
Andreas Grabs 2011-10-11 22:37:47 +02:00
parent e70dab0646
commit 7b1126fd20
5 changed files with 161 additions and 73 deletions

View file

@ -240,7 +240,6 @@ function feedback_pluginfile($course, $cm, $context, $filearea, $args, $forcedow
return false;
}
/**
* this will delete a given instance.
* all referenced data also will be deleted
@ -990,7 +989,7 @@ function feedback_create_template($courseid, $name, $ispublic = 0) {
global $DB;
$templ = new stdClass();
$templ->course = $courseid;
$templ->course = ($ispublic ? 0 : $courseid);
$templ->name = $name;
$templ->ispublic = $ispublic;
@ -1023,9 +1022,14 @@ function feedback_save_as_template($feedback, $name, $ispublic = 0) {
return false;
}
//files in the template_item are in the context of the current course
//files in the template_item are in the context of the current course or
//if the template is public the files are in the system context
//files in the feedback_item are in the feedback_context of the feedback
$c_context = get_context_instance(CONTEXT_COURSE, $newtempl->course);
if($ispublic) {
$s_context = get_system_context();
}else {
$s_context = get_context_instance(CONTEXT_COURSE, $newtempl->course);
}
$cm = get_coursemodule_from_instance('feedback', $feedback->id);
$f_context = get_context_instance(CONTEXT_MODULE, $cm->id);
@ -1046,7 +1050,7 @@ function feedback_save_as_template($feedback, $name, $ispublic = 0) {
if ($itemfiles = $fs->get_area_files($f_context->id, 'mod_feedback', 'item', $item->id, "id", false)) {
foreach($itemfiles as $ifile) {
$file_record = new stdClass();
$file_record->contextid = $c_context->id;
$file_record->contextid = $s_context->id;
$file_record->component = 'mod_feedback';
$file_record->filearea = 'template';
$file_record->itemid = $t_item->id;
@ -1076,27 +1080,19 @@ function feedback_save_as_template($feedback, $name, $ispublic = 0) {
*
* @global object
* @uses CONTEXT_COURSE
* @param int $id the templateid
* @param object $template the template
* @return void
*/
function feedback_delete_template($id) {
function feedback_delete_template($template) {
global $DB;
$template = $DB->get_record("feedback_template", array("id"=>$id));
//deleting the files from the item
$fs = get_file_storage();
$context = get_context_instance(CONTEXT_COURSE, $template->course);
if($t_items = $DB->get_records("feedback_item", array("template"=>$id))) {
//deleting the files from the item is done by feedback_delete_item
if($t_items = $DB->get_records("feedback_item", array("template"=>$template->id))) {
foreach($t_items as $t_item) {
if ($templatefiles = $fs->get_area_files($context->id, 'mod_feedback', 'template', $t_item->id, "id", false)) {
$fs->delete_area_files($context->id, 'mod_feedback', 'template', $t_item->id);
}
feedback_delete_item($t_item->id, false, $template);
}
}
$DB->delete_records("feedback_template", array("id"=>$id));
$DB->delete_records("feedback_template", array("id"=>$template->id));
}
/**
@ -1129,9 +1125,9 @@ function feedback_items_from_template($feedback, $templateid, $deleteold = 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
if($template->ispublic) {
$c_context = get_context_instance(CONTEXT_COURSE, $template->course);
$s_context = get_system_context();
}else {
$c_context = get_context_instance(CONTEXT_COURSE, $feedback->course);
$s_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);
@ -1182,7 +1178,7 @@ function feedback_items_from_template($feedback, $templateid, $deleteold = false
$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)) {
if ($templatefiles = $fs->get_area_files($s_context->id, 'mod_feedback', 'template', $t_item->id, "id", false)) {
foreach($templatefiles as $tfile) {
$file_record = new stdClass();
$file_record->contextid = $f_context->id;
@ -1228,7 +1224,7 @@ function feedback_get_template_list($course, $onlyownorpublic = '') {
$templates = $DB->get_records('feedback_template', array('course'=>$course->id), 'name');
break;
case 'public':
$templates = $DB->get_records('feedback_template', array('course'=>SITEID, 'ispublic'=>1), 'name');
$templates = $DB->get_records('feedback_template', array('ispublic'=>1), 'name');
break;
}
return $templates;
@ -1402,9 +1398,10 @@ function feedback_update_item($item){
* @uses CONTEXT_MODULE
* @param int $itemid
* @param boolean $renumber should the kept items renumbered Yes/No
* @param object $template if the template is given so the items are bound to it
* @return void
*/
function feedback_delete_item($itemid, $renumber = true){
function feedback_delete_item($itemid, $renumber = true, $template = false){
global $DB;
@ -1412,13 +1409,25 @@ function feedback_delete_item($itemid, $renumber = true){
//deleting the files from the item
$fs = get_file_storage();
if (!$cm = get_coursemodule_from_instance('feedback', $item->feedback)) {
return false;
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if($template) {
if($template->ispublic) {
$context = get_system_context();
}else {
$context = get_context_instance(CONTEXT_COURSE, $template->course);
}
if ($templatefiles = $fs->get_area_files($context->id, 'mod_feedback', 'template', $item->id, "id", false)) {
$fs->delete_area_files($context->id, 'mod_feedback', 'template', $item->id);
}
}else {
if (!$cm = get_coursemodule_from_instance('feedback', $item->feedback)) {
return false;
}
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if ($itemfiles = $fs->get_area_files($context->id, 'mod_feedback', 'item', $item->id, "id", false)) {
$fs->delete_area_files($context->id, 'mod_feedback', 'item', $item->id);
if ($itemfiles = $fs->get_area_files($context->id, 'mod_feedback', 'item', $item->id, "id", false)) {
$fs->delete_area_files($context->id, 'mod_feedback', 'item', $item->id);
}
}
$DB->delete_records("feedback_value", array("item"=>$itemid));