|
@@ -13,151 +13,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
-class Teacherview {
|
|
|
- private $cmid;
|
|
|
- private $gradeimporterid;
|
|
|
- private $context;
|
|
|
- private $cellstyle = "border:1px solid black; text-align:center";
|
|
|
-
|
|
|
- public function __construct (int $cmid, int $gradeimporterid) {
|
|
|
- $this->cmid = $cmid;
|
|
|
- $this->gradeimporterid = $gradeimporterid;
|
|
|
- $this->context = context_module::instance($cmid);
|
|
|
- }
|
|
|
|
|
|
- private function get_cmid () {
|
|
|
- return $this->cmid;
|
|
|
- }
|
|
|
- private function get_gradeimporterid () {
|
|
|
- return $this->gradeimporterid;
|
|
|
- }
|
|
|
- private function get_context () {
|
|
|
- return $this->context;
|
|
|
- }
|
|
|
- private function get_cellstyle () {
|
|
|
- return $this->cellstyle;
|
|
|
- }
|
|
|
|
|
|
- public function make_table () {
|
|
|
- global $DB, $CFG;
|
|
|
-
|
|
|
-
|
|
|
- $studentlist = $this->get_studentlist();
|
|
|
- $submissions = $this->get_submissions();
|
|
|
-
|
|
|
-
|
|
|
- $table = new html_table();
|
|
|
- $table->align = array('center');
|
|
|
- $table->attributes = array('class' => 'generaltable mod_index');
|
|
|
-
|
|
|
- $submissions = $this->get_submissions();
|
|
|
- if (!$submissions) {
|
|
|
- $this->no_submissions();
|
|
|
- return;
|
|
|
- }
|
|
|
- $table->data[] = $this->get_table_head($submissions);
|
|
|
- foreach ($studentlist as $student) {
|
|
|
- $table->data[] = $this->get_studentsubmissions($student, $submissions);
|
|
|
- }
|
|
|
-
|
|
|
- return html_writer::table($table);
|
|
|
+class Teacherview {
|
|
|
+
|
|
|
+ * @property gradeimporterid used to query DB at get_submissions()
|
|
|
+ * @property context used to get studentslist at get_studentlist()
|
|
|
+ * @property cellstyle style used by table cells. Black border and centered text
|
|
|
+ */
|
|
|
+ private $gradeimporterid;
|
|
|
+ private $context;
|
|
|
+ private $cellstyle = "border:1px solid black; text-align:center";
|
|
|
+
|
|
|
+
|
|
|
+ * @param int cmid to get context
|
|
|
+ * @param int gradeimporterid to query database
|
|
|
+ * constructor
|
|
|
+ */
|
|
|
+ public function __construct (int $cmid, int $gradeimporterid) {
|
|
|
+ $this->gradeimporterid = $gradeimporterid;
|
|
|
+ $this->context = context_module::instance($cmid);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function get_gradeimporterid () {
|
|
|
+ return $this->gradeimporterid;
|
|
|
+ }
|
|
|
+ private function get_context () {
|
|
|
+ return $this->context;
|
|
|
+ }
|
|
|
+ private function get_cellstyle () {
|
|
|
+ return $this->cellstyle;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * builds teacherview table using php html_table class
|
|
|
+ * Gets all submissions from get_submissions()
|
|
|
+ * Header is built with get_table_head() passing submissions as param
|
|
|
+ * Each row is a different student
|
|
|
+ * Gets each row with get_studentsubmissions()
|
|
|
+ * @return table as html string
|
|
|
+ */
|
|
|
+ public function make_table () {
|
|
|
+ global $DB, $CFG;
|
|
|
+
|
|
|
+
|
|
|
+ $studentlist = $this->get_studentlist();
|
|
|
+ $submissions = $this->get_submissions();
|
|
|
+
|
|
|
+
|
|
|
+ $table = new html_table();
|
|
|
+ $table->align = array('center');
|
|
|
+ $table->attributes = array('class' => 'generaltable mod_index');
|
|
|
+
|
|
|
+ $submissions = $this->get_submissions();
|
|
|
+ if (!$submissions) {
|
|
|
+ $this->no_submissions();
|
|
|
+ return;
|
|
|
}
|
|
|
-
|
|
|
- private function get_studentlist () {
|
|
|
-
|
|
|
- $enrolledusers = get_enrolled_users($this->get_context(), 'mod/gradeimporter:view',
|
|
|
- 0, 'u.id, u.firstname, u.lastname',
|
|
|
- 'u.firstname, u.lastname'
|
|
|
- );
|
|
|
- $studentlist = array();
|
|
|
- foreach ($enrolledusers as $user) {
|
|
|
- $studentlist[$user->id] = array('name' => $user->firstname." ".$user->lastname,
|
|
|
- 'id' => $user->id);
|
|
|
- }
|
|
|
-
|
|
|
- return $studentlist;
|
|
|
+ $table->data[] = $this->get_table_head($submissions);
|
|
|
+ foreach ($studentlist as $student) {
|
|
|
+ $table->data[] = $this->get_studentsubmissions($student, $submissions);
|
|
|
}
|
|
|
|
|
|
- private function get_table_head ($submissions) {
|
|
|
-
|
|
|
- $header = new html_table_row();
|
|
|
-
|
|
|
-
|
|
|
- $header->cells[] = $this->make_cell(get_string('nameCol', 'gradeimporter'), 1);
|
|
|
-
|
|
|
- foreach ($submissions as $submission) {
|
|
|
-
|
|
|
- $header->cells[] = $this->make_cell($submission->name, 2);
|
|
|
- }
|
|
|
- return $header;
|
|
|
+ return html_writer::table($table);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * Gets students list from moodle function get_enrolled_users
|
|
|
+ * Builds a list from $enrolledusers with:
|
|
|
+ * * Keys as student id;
|
|
|
+ * * Values as student fullname and student id.
|
|
|
+ * @return array $studentlist - students data (name and id)
|
|
|
+ */
|
|
|
+ private function get_studentlist () {
|
|
|
+
|
|
|
+ $enrolledusers = get_enrolled_users($this->get_context(), 'mod/gradeimporter:view',
|
|
|
+ 0, 'u.id, u.firstname, u.lastname',
|
|
|
+ 'u.firstname, u.lastname'
|
|
|
+ );
|
|
|
+ $studentlist = array();
|
|
|
+ foreach ($enrolledusers as $user) {
|
|
|
+ $studentlist[$user->id] = array('name' => $user->firstname." ".$user->lastname,
|
|
|
+ 'id' => $user->id);
|
|
|
}
|
|
|
|
|
|
- private function get_studentsubmissions ($student, $submissions) {
|
|
|
- global $DB;
|
|
|
-
|
|
|
- $row = new html_table_row();
|
|
|
-
|
|
|
-
|
|
|
- $row->cells[] = $this->make_cell($student["name"], 1);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- foreach ($submissions as $submission) {
|
|
|
- $feedback = $DB->get_record('gradeimporter_feedback',
|
|
|
- ['submissionid' => $submission->id,
|
|
|
- 'studentid' => $student['id']]
|
|
|
- );
|
|
|
- if ($feedback) {
|
|
|
- $fileurl = $this->feedback_url($feedback);
|
|
|
- $grade = $feedback->grade;
|
|
|
- } else {
|
|
|
- $fileurl = '-';
|
|
|
- $grade = '-';
|
|
|
- }
|
|
|
- $row->cells[] = $this->make_cell($grade, 1);
|
|
|
-
|
|
|
- $row->cells[] = $this->make_cell($fileurl, 1);
|
|
|
- }
|
|
|
- return $row;
|
|
|
- }
|
|
|
+ return $studentlist;
|
|
|
+ }
|
|
|
|
|
|
- private function get_submissions () {
|
|
|
- global $CFG, $DB;
|
|
|
-
|
|
|
- $tp = $CFG->prefix;
|
|
|
-
|
|
|
-
|
|
|
- $sql = "SELECT id, name, type
|
|
|
- FROM {$tp}gradeimporter_submission
|
|
|
- WHERE gradeimporterid ={$this->get_gradeimporterid()}
|
|
|
- ORDER BY type, id";
|
|
|
-
|
|
|
- $submissions = $DB->get_records_sql($sql);
|
|
|
-
|
|
|
- return $submissions;
|
|
|
- }
|
|
|
+
|
|
|
+ * Builds a row with first column being "name" for students names
|
|
|
+ * Other rows are submissions names
|
|
|
+ * @return html_table_row $header
|
|
|
+ */
|
|
|
+ private function get_table_head ($submissions) {
|
|
|
+
|
|
|
+ $header = new html_table_row();
|
|
|
|
|
|
- private function no_submissions () {
|
|
|
- echo "No submissions";
|
|
|
- }
|
|
|
+
|
|
|
+ $header->cells[] = $this->make_cell(get_string('nameCol', 'gradeimporter'), 1);
|
|
|
|
|
|
- private function feedback_url ($feedback) {
|
|
|
- $url = moodle_url::make_pluginfile_url($feedback->contextid,
|
|
|
- 'mod_gradeimporter',
|
|
|
- 'submissionfiles',
|
|
|
- 0,
|
|
|
- "/",
|
|
|
- $feedback->name,
|
|
|
- true
|
|
|
- );
|
|
|
- return "<a href='{$url}'>$feedback->name</a>";
|
|
|
+ foreach ($submissions as $submission) {
|
|
|
+
|
|
|
+ $header->cells[] = $this->make_cell($submission->name, 2);
|
|
|
}
|
|
|
-
|
|
|
- private function make_cell ($text, $colspan) {
|
|
|
- $cell = new html_table_cell($text);
|
|
|
- $cell->style = $this->get_cellstyle();
|
|
|
- $cell->colspan = $colspan;
|
|
|
- return $cell;
|
|
|
+ return $header;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * Build a row for a student defined by param $student
|
|
|
+ * @param array $student, array with keys "name" and "id"
|
|
|
+ * @param $submissions, submissions list to find each submission for this student
|
|
|
+ * For each submission at $submissions tries do fetch feedback from DB:
|
|
|
+ * * If submission is found adds grade and link to feedback file to row
|
|
|
+ * * If doesn't have the submission sets grade and link to " - "
|
|
|
+ * @return html_table_row $row with each column being grade and feedbackfile for the submission
|
|
|
+ */
|
|
|
+ private function get_studentsubmissions ($student, $submissions) {
|
|
|
+ global $DB;
|
|
|
+
|
|
|
+ $row = new html_table_row();
|
|
|
+
|
|
|
+
|
|
|
+ $row->cells[] = $this->make_cell($student["name"], 1);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ foreach ($submissions as $submission) {
|
|
|
+ $feedback = $DB->get_record('gradeimporter_feedback',
|
|
|
+ ['submissionid' => $submission->id,
|
|
|
+ 'studentid' => $student['id']]
|
|
|
+ );
|
|
|
+ if ($feedback) {
|
|
|
+ $fileurl = $this->feedback_url($feedback);
|
|
|
+ $grade = $feedback->grade;
|
|
|
+ } else {
|
|
|
+ $fileurl = '-';
|
|
|
+ $grade = '-';
|
|
|
+ }
|
|
|
+ $row->cells[] = $this->make_cell($grade, 1);
|
|
|
+
|
|
|
+ $row->cells[] = $this->make_cell($fileurl, 1);
|
|
|
}
|
|
|
+ return $row;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * Fetch all submissions for this gradeimporter instance on gradeimporter_submissions table
|
|
|
+ * Build query using $this->gradeimporterid property
|
|
|
+ * @return $submissions fetched from gradeimporter_submission table
|
|
|
+ */
|
|
|
+ private function get_submissions () {
|
|
|
+ global $CFG, $DB;
|
|
|
+
|
|
|
+ $tp = $CFG->prefix;
|
|
|
+
|
|
|
+
|
|
|
+ $sql = "SELECT id, name, type
|
|
|
+ FROM {$tp}gradeimporter_submission
|
|
|
+ WHERE gradeimporterid ={$this->get_gradeimporterid()}
|
|
|
+ ORDER BY type, id";
|
|
|
+
|
|
|
+ $submissions = $DB->get_records_sql($sql);
|
|
|
+
|
|
|
+ return $submissions;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * Prints html when there are no submissions to show
|
|
|
+ * @underconstruction
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ private function no_submissions () {
|
|
|
+ echo "No submissions";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * Builds fileplugin url to feedback file
|
|
|
+ * @param array $feedback fetched from gradeimporter_feedback table
|
|
|
+ * @return html hyperlink to download feedback file
|
|
|
+ */
|
|
|
+ private function feedback_url ($feedback) {
|
|
|
+ $url = moodle_url::make_pluginfile_url($feedback->contextid,
|
|
|
+ 'mod_gradeimporter',
|
|
|
+ 'submissionfiles',
|
|
|
+ $feedback->id,
|
|
|
+ "/",
|
|
|
+ $feedback->name,
|
|
|
+ true
|
|
|
+ );
|
|
|
+ return "<a href='{$url}'>$feedback->name</a>";
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * Makes a cell object to be inserted into a row
|
|
|
+ * Cell style is predifined on class properties
|
|
|
+ * @param string $text - Text shown on the cell
|
|
|
+ * @param int $colspan - How many columns this cell ocuppies
|
|
|
+ * @return html_table_cell $cell - cell built on the function
|
|
|
+ */
|
|
|
+ private function make_cell ($text, $colspan) {
|
|
|
+ $cell = new html_table_cell($text);
|
|
|
+ $cell->style = $this->get_cellstyle();
|
|
|
+ $cell->colspan = $colspan;
|
|
|
+ return $cell;
|
|
|
+ }
|
|
|
}
|