Differences Between: [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * prints an analysed excel-spreadsheet of the feedback 19 * 20 * @copyright Andreas Grabs 21 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License 22 * @package mod_feedback 23 */ 24 25 require_once("../../config.php"); 26 require_once ("lib.php"); 27 require_once("$CFG->libdir/excellib.class.php"); 28 29 $id = required_param('id', PARAM_INT); // Course module id. 30 $courseid = optional_param('courseid', '0', PARAM_INT); 31 32 $url = new moodle_url('/mod/feedback/analysis_to_excel.php', array('id' => $id)); 33 if ($courseid) { 34 $url->param('courseid', $courseid); 35 } 36 $PAGE->set_url($url); 37 38 list($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback'); 39 require_login($course, false, $cm); 40 $context = context_module::instance($cm->id); 41 require_capability('mod/feedback:viewreports', $context); 42 43 $feedback = $PAGE->activityrecord; 44 45 // Buffering any output. This prevents some output before the excel-header will be send. 46 ob_start(); 47 ob_end_clean(); 48 49 // Get the questions (item-names). 50 $feedbackstructure = new mod_feedback_structure($feedback, $cm, $course->id); 51 if (!$items = $feedbackstructure->get_items(true)) { 52 print_error('no_items_available_yet', 'feedback', $cm->url); 53 } 54 55 $mygroupid = groups_get_activity_group($cm); 56 57 // Creating a workbook. 58 $filename = "feedback_" . clean_filename($cm->get_formatted_name()) . ".xls"; 59 $workbook = new MoodleExcelWorkbook($filename); 60 61 // Creating the worksheet. 62 error_reporting(0); 63 $worksheet1 = $workbook->add_worksheet(); 64 error_reporting($CFG->debug); 65 $worksheet1->hide_gridlines(); 66 $worksheet1->set_column(0, 0, 10); 67 $worksheet1->set_column(1, 1, 30); 68 $worksheet1->set_column(2, 20, 15); 69 70 // Creating the needed formats. 71 $xlsformats = new stdClass(); 72 $xlsformats->head1 = $workbook->add_format(['bold' => 1, 'size' => 12]); 73 $xlsformats->head2 = $workbook->add_format(['align' => 'left', 'bold' => 1, 'bottum' => 2]); 74 $xlsformats->default = $workbook->add_format(['align' => 'left', 'v_align' => 'top']); 75 $xlsformats->value_bold = $workbook->add_format(['align' => 'left', 'bold' => 1, 'v_align' => 'top']); 76 $xlsformats->procent = $workbook->add_format(['align' => 'left', 'bold' => 1, 'v_align' => 'top', 'num_format' => '#,##0.00%']); 77 78 // Writing the table header. 79 $rowoffset1 = 0; 80 $worksheet1->write_string($rowoffset1, 0, userdate(time()), $xlsformats->head1); 81 82 // Get the completeds. 83 $completedscount = $feedbackstructure->count_completed_responses($mygroupid); 84 // Write the count of completeds. 85 // Keep consistency and write count of completeds even when they are 0. 86 $rowoffset1++; 87 $worksheet1->write_string($rowoffset1, 88 0, 89 get_string('completed_feedbacks', 'feedback').': '.strval($completedscount), 90 $xlsformats->head1); 91 92 $rowoffset1++; 93 $worksheet1->write_string($rowoffset1, 94 0, 95 get_string('questions', 'feedback').': '. strval(count($items)), 96 $xlsformats->head1); 97 98 $rowoffset1 += 2; 99 $worksheet1->write_string($rowoffset1, 0, get_string('item_label', 'feedback'), $xlsformats->head1); 100 $worksheet1->write_string($rowoffset1, 1, get_string('question', 'feedback'), $xlsformats->head1); 101 $worksheet1->write_string($rowoffset1, 2, get_string('responses', 'feedback'), $xlsformats->head1); 102 $rowoffset1++; 103 104 foreach ($items as $item) { 105 // Get the class of item-typ. 106 $itemobj = feedback_get_item_class($item->typ); 107 $rowoffset1 = $itemobj->excelprint_item($worksheet1, 108 $rowoffset1, 109 $xlsformats, 110 $item, 111 $mygroupid, 112 $courseid); 113 } 114 115 $workbook->close();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body