Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/feedback/analysis_course.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00025 require_once("../../config.php");
00026 require_once("lib.php");
00027 
00028 $current_tab = 'analysis';
00029 
00030 $id = required_param('id', PARAM_INT);  //the POST dominated the GET
00031 $coursefilter = optional_param('coursefilter', '0', PARAM_INT);
00032 $courseitemfilter = optional_param('courseitemfilter', '0', PARAM_INT);
00033 $courseitemfiltertyp = optional_param('courseitemfiltertyp', '0', PARAM_ALPHANUM);
00034 $searchcourse = optional_param('searchcourse', '', PARAM_RAW);
00035 $courseid = optional_param('courseid', false, PARAM_INT);
00036 
00037 $url = new moodle_url('/mod/feedback/analysis_course.php', array('id'=>$id));
00038 if ($courseid !== false) {
00039     $url->param('courseid', $courseid);
00040 }
00041 if ($coursefilter !== '0') {
00042     $url->param('coursefilter', $coursefilter);
00043 }
00044 if ($courseitemfilter !== '0') {
00045     $url->param('courseitemfilter', $courseitemfilter);
00046 }
00047 if ($courseitemfiltertyp !== '0') {
00048     $url->param('courseitemfiltertyp', $courseitemfiltertyp);
00049 }
00050 if ($searchcourse !== '') {
00051     $url->param('searchcourse', $searchcourse);
00052 }
00053 $PAGE->set_url($url);
00054 
00055 if (($searchcourse OR $courseitemfilter OR $coursefilter) AND !confirm_sesskey()) {
00056     print_error('invalidsesskey');
00057 }
00058 
00059 if (! $cm = get_coursemodule_from_id('feedback', $id)) {
00060     print_error('invalidcoursemodule');
00061 }
00062 
00063 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
00064     print_error('coursemisconf');
00065 }
00066 
00067 if (! $feedback = $DB->get_record("feedback", array("id"=>$cm->instance))) {
00068     print_error('invalidcoursemodule');
00069 }
00070 
00071 if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) {
00072         print_error('badcontext');
00073 }
00074 
00075 require_login($course->id, true, $cm);
00076 
00077 if (!($feedback->publish_stats OR has_capability('mod/feedback:viewreports', $context))) {
00078     print_error('error');
00079 }
00080 
00082 $strfeedbacks = get_string("modulenameplural", "feedback");
00083 $strfeedback  = get_string("modulename", "feedback");
00084 
00085 $PAGE->set_heading(format_string($course->fullname));
00086 $PAGE->set_title(format_string($feedback->name));
00087 echo $OUTPUT->header();
00088 
00090 require('tabs.php');
00091 
00092 //print the analysed items
00093 echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
00094 
00095 if (has_capability('mod/feedback:viewreports', $context)) {
00096     //button "export to excel"
00097     echo $OUTPUT->container_start('mdl-align');
00098     $aurl = new moodle_url('analysis_to_excel.php',
00099                            array('sesskey' => sesskey(),
00100                                  'id' => $id,
00101                                  'coursefilter' => $coursefilter));
00102 
00103     echo $OUTPUT->single_button($aurl, get_string('export_to_excel', 'feedback'));
00104     echo $OUTPUT->container_end();
00105 }
00106 
00107 //get the groupid
00108 //lstgroupid is the choosen id
00109 $mygroupid = false;
00110 //get completed feedbacks
00111 $completedscount = feedback_get_completeds_group_count($feedback, $mygroupid, $coursefilter);
00112 
00113 //show the count
00114 echo '<b>'.get_string('completed_feedbacks', 'feedback').': '.$completedscount. '</b><br />';
00115 
00116 // get the items of the feedback
00117 $params = array('feedback' => $feedback->id, 'hasvalue' => 1);
00118 $items = $DB->get_records('feedback_item', $params, 'position');
00119 //show the count
00120 if (is_array($items)) {
00121     echo '<b>'.get_string('questions', 'feedback').': ' .count($items). ' </b><hr />';
00122     echo '<a href="analysis_course.php?id=' . $id . '&courseid='.$courseid.'">';
00123     echo get_string('show_all', 'feedback');
00124     echo '</a>';
00125 } else {
00126     $items=array();
00127 }
00128 
00129 echo '<form name="report" method="post" id="analysis-form">';
00130 echo '<div class="mdl-align"><table width="80%" cellpadding="10">';
00131 if ($courseitemfilter > 0) {
00132     $avgvalue = 'avg(value)';
00133     if ($DB->get_dbfamily() == 'postgres') { // TODO: this should be moved to standard sql DML function ;-)
00134          $avgvalue = 'avg(cast (value as integer))';
00135     }
00136 
00137     $sql = "SELECT fv.course_id, c.shortname, $avgvalue AS avgvalue
00138             FROM {feedback_value} fv, {course} c, {feedback_item} fi
00139             WHERE fv.course_id = c.id AND fi.id = fv.item AND fi.typ = ? AND fv.item = ?
00140             GROUP BY course_id, shortname
00141             ORDER BY avgvalue desc";
00142 
00143     if ($courses = $DB->get_records_sql($sql, array($courseitemfiltertyp, $courseitemfilter))) {
00144         $item = $DB->get_record('feedback_item', array('id'=>$courseitemfilter));
00145         echo '<tr><th colspan="2">'.$item->name.'</th></tr>';
00146         echo '<tr><td><table align="left">';
00147         echo '<tr><th>Course</th><th>Average</th></tr>';
00148         $sep_dec = get_string('separator_decimal', 'feedback');
00149         $sep_thous = get_string('separator_thousand', 'feedback');
00150 
00151         foreach ($courses as $c) {
00152             $coursecontext = get_context_instance(CONTEXT_COURSE, $c->course_id);
00153             $shortname = format_string($c->shortname, true, array('context' => $coursecontext));
00154 
00155             echo '<tr>';
00156             echo '<td>'.$shortname.'</td>';
00157             echo '<td align="right">';
00158             echo number_format(($c->avgvalue), 2, $sep_dec, $sep_thous);
00159             echo '</td>';
00160             echo '</tr>';
00161         }
00162          echo '</table></td></tr>';
00163     } else {
00164          echo '<tr><td>'.get_string('noresults').'</td></tr>';
00165     }
00166 } else {
00167 
00168     echo get_string('search_course', 'feedback') . ': ';
00169     echo '<input type="text" name="searchcourse" value="'.s($searchcourse).'"/> ';
00170     echo '<input type="submit" value="'.get_string('search').'"/>';
00171     echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';
00172     echo '<input type="hidden" name="id" value="'.$id.'" />';
00173     echo '<input type="hidden" name="courseitemfilter" value="'.$courseitemfilter.'" />';
00174     echo '<input type="hidden" name="courseitemfiltertyp" value="'.$courseitemfiltertyp.'" />';
00175     echo '<input type="hidden" name="courseid" value="'.$courseid.'" />';
00176     echo html_writer::script('', $CFG->wwwroot.'/mod/feedback/feedback.js');
00177     $sql = 'select DISTINCT c.id, c.shortname from {course} c, '.
00178                                           '{feedback_value} fv, {feedback_item} fi '.
00179                                           'where c.id = fv.course_id and fv.item = fi.id '.
00180                                           'and fi.feedback = ? '.
00181                                           'and
00182                                           ('.$DB->sql_like('c.shortname', '?', false).'
00183                                           OR '.$DB->sql_like('c.fullname', '?', false).')';
00184     $params = array($feedback->id, "%$searchcourse%", "%$searchcourse%");
00185 
00186     if ($courses = $DB->get_records_sql_menu($sql, $params)) {
00187 
00188          echo ' ' . get_string('filter_by_course', 'feedback') . ': ';
00189 
00190          echo html_writer::select($courses, 'coursefilter', $coursefilter,
00191                                   null, array('id'=>'coursefilterid'));
00192 
00193          $PAGE->requires->js_init_call('M.util.init_select_autosubmit',
00194                                         array('analysis-form', 'coursefilterid', false));
00195     }
00196     echo '<hr />';
00197     $itemnr = 0;
00198     //print the items in an analysed form
00199     echo '<tr><td>';
00200     foreach ($items as $item) {
00201         if ($item->hasvalue == 0) {
00202             continue;
00203         }
00204         echo '<table width="100%" class="generalbox">';
00205         //get the class from item-typ
00206         $itemobj = feedback_get_item_class($item->typ);
00207         $itemnr++;
00208         if ($feedback->autonumbering) {
00209             $printnr = $itemnr.'.';
00210         } else {
00211             $printnr = '';
00212         }
00213         $itemobj->print_analysed($item, $printnr, $mygroupid, $coursefilter);
00214         if (preg_match('/rated$/i', $item->typ)) {
00215             $onclick = 'onclick="setcourseitemfilter'.
00216                         "(".$item->id.",'".$item->typ."');".
00217                         ' return false;"';
00218 
00219             $anker = '<a href="#" '.$onclick.'>'.
00220                      get_string('sort_by_course', 'feedback').
00221                      '</a>';
00222 
00223             echo '<tr><td colspan="2">'.$anker.'</td></tr>';
00224         }
00225         echo '</table>';
00226     }
00227     echo '</td></tr>';
00228 }
00229 echo '</table></div>';
00230 echo '</form>';
00231 echo $OUTPUT->box_end();
00232 
00233 echo $OUTPUT->footer();
00234 
 All Data Structures Namespaces Files Functions Variables Enumerations