| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 | 
							- <?php
 
- // This file is part of
 
- //
 
- // 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/>.
 
- /**
 
-  * Queries all feedbacks for a student on gradeimporter_feedback table
 
-  * @param int $gradeimporterid - Which gradeimporter instance the feedbacks are related to
 
-  * @return array $records - With all feedbacks this student has on this gradeimporter instance
 
-  */
 
- function query_feedbacks ($gradeimporterid) {
 
-   global $DB, $USER, $CFG;
 
-   // Get moodle table prefix, usually 'mdl_'
 
-   $tp = $CFG->prefix;
 
-   // Build database query to fetch feedbacks for the student
 
-   $query = " SELECT
 
-         gf.id as id,
 
-         gst.name as typename,
 
-         gst.id as typeid,
 
-         gst.intro as typeintro,
 
-         gs.name as submissionname,
 
-         gs.id as submissionid,
 
-         gf.grade as grade,
 
-         gf.comment as comment,
 
-         gf.name as filename,
 
-         gf.contextid as contextid,
 
-         gs.intro as submissionintro,
 
-         gs.position as position
 
-         FROM {$tp}gradeimporter_feedback as gf
 
-         JOIN {$tp}gradeimporter_submission as gs
 
-           ON gf.submissionid = gs.id
 
-         JOIN {$tp}gradeimporter_submissiontype as gst
 
-           ON gs.type = gst.id
 
-         WHERE gs.gradeimporterid = {$gradeimporterid}
 
-           AND gf.studentid = {$USER->id}
 
-           AND gs.visibility = 1
 
-       ";
 
-   // Query database to find students feedbacks
 
-   $records = $DB->get_records_sql($query);
 
-   // Return query result
 
-   return $records;
 
- }
 
- /**
 
-  * Builds table to show all feedbacks
 
-  * @param array $feedbacks - array with all feedbacks of the student, fetched with query_feedbacks()
 
-  * @param int $cmid - Course module id, to build pluginfile as we have to know which course the feedbacks are related to
 
-  * @return html_writer $table - String with table html with all feedbacks, ready to be shown
 
-  */
 
- function make_feedback_table ($feedbacks, $cmid) {
 
-   $table = new html_table();
 
-   $table->head = array(get_string('type', 'gradeimporter'),
 
-           get_string('submission', 'gradeimporter'),
 
-           get_string('grade', 'gradeimporter'),
 
-           get_string('comment', 'gradeimporter'),
 
-           get_string('file', 'gradeimporter')
 
-         );
 
-   $table->aling = array('center', 'center', 'center', 'center', 'center');
 
-   $table->attributes = array('class' => 'generaltable mod_index');
 
-   if (count($feedbacks)) {
 
-     // If feedbacks is not an empty list
 
-     foreach ($feedbacks as $type => $feedback) {
 
-       $rowvalues = array('type_name',
 
-                 $feedback->submissionname,
 
-                 $feedback->grade,
 
-                 $feedback->comment,
 
-                 get_file($feedback, $cmid)
 
-               );
 
-       $row = new html_table_row($rowvalues);
 
-       $table->data[] = $row;
 
-     }
 
-   }
 
-   echo html_writer::table($table);
 
- }
 
- function get_file ($feedback, $cmid) {
 
-   $context = context_module::instance($cmid);
 
-   $url = moodle_url::make_pluginfile_url($feedback->contextid,
 
-                       'mod_gradeimporter',
 
-                       'submissionfiles',
 
-                       $feedback->submissionid,
 
-                       "/",
 
-                       $feedback->filename,
 
-                       true
 
-                     );
 
-   // Return pluginfile url, will use function mod_gradeimporter_pluginfile at lib.php to serve the file
 
-   return "<a href='{$url}'>$feedback->filename</a>";
 
- }
 
 
  |