Exemple #1
0
 /**
  * Renders the teamwork grading report
  *
  * @param teamwork_grading_report $gradingreport
  * @return string html code
  */
 protected function render_teamwork_grading_report(teamwork_grading_report $gradingreport)
 {
     $data = $gradingreport->get_data();
     $options = $gradingreport->get_options();
     $grades = $data->grades;
     $userinfo = $data->userinfo;
     if (empty($grades)) {
         return '';
     }
     $table = new html_table();
     $table->attributes['class'] = 'grading-report';
     $sortbyfirstname = $this->helper_sortable_heading(get_string('firstname'), 'firstname', $options->sortby, $options->sorthow);
     $sortbylastname = $this->helper_sortable_heading(get_string('lastname'), 'lastname', $options->sortby, $options->sorthow);
     if (self::fullname_format() == 'lf') {
         $sortbyname = $sortbylastname . ' / ' . $sortbyfirstname;
     } else {
         $sortbyname = $sortbyfirstname . ' / ' . $sortbylastname;
     }
     $table->head = array();
     $table->head[] = $sortbyname;
     $table->head[] = $this->helper_sortable_heading(get_string('submission', 'teamwork'), 'submissiontitle', $options->sortby, $options->sorthow);
     $table->head[] = $this->helper_sortable_heading(get_string('receivedgrades', 'teamwork'));
     if ($options->showsubmissiongrade) {
         $table->head[] = $this->helper_sortable_heading(get_string('submissiongradeof', 'teamwork', $data->maxgrade), 'submissiongrade', $options->sortby, $options->sorthow);
     }
     $table->head[] = $this->helper_sortable_heading(get_string('givengrades', 'teamwork'));
     if ($options->showgradinggrade) {
         $table->head[] = $this->helper_sortable_heading(get_string('gradinggradeof', 'teamwork', $data->maxgradinggrade), 'gradinggrade', $options->sortby, $options->sorthow);
     }
     $table->rowclasses = array();
     $table->colclasses = array();
     $table->data = array();
     foreach ($grades as $participant) {
         $numofreceived = count($participant->reviewedby);
         $numofgiven = count($participant->reviewerof);
         $published = $participant->submissionpublished;
         // compute the number of <tr> table rows needed to display this participant
         if ($numofreceived > 0 and $numofgiven > 0) {
             $numoftrs = teamwork::lcm($numofreceived, $numofgiven);
             $spanreceived = $numoftrs / $numofreceived;
             $spangiven = $numoftrs / $numofgiven;
         } elseif ($numofreceived == 0 and $numofgiven > 0) {
             $numoftrs = $numofgiven;
             $spanreceived = $numoftrs;
             $spangiven = $numoftrs / $numofgiven;
         } elseif ($numofreceived > 0 and $numofgiven == 0) {
             $numoftrs = $numofreceived;
             $spanreceived = $numoftrs / $numofreceived;
             $spangiven = $numoftrs;
         } else {
             $numoftrs = 1;
             $spanreceived = 1;
             $spangiven = 1;
         }
         for ($tr = 0; $tr < $numoftrs; $tr++) {
             $row = new html_table_row();
             if ($published) {
                 $row->attributes['class'] = 'published';
             }
             // column #1 - participant - spans over all rows
             if ($tr == 0) {
                 $cell = new html_table_cell();
                 $cell->text = $this->helper_grading_report_participant($participant, $userinfo);
                 $cell->rowspan = $numoftrs;
                 $cell->attributes['class'] = 'participant';
                 $row->cells[] = $cell;
             }
             // column #2 - submission - spans over all rows
             if ($tr == 0) {
                 $cell = new html_table_cell();
                 $cell->text = $this->helper_grading_report_submission($participant);
                 $cell->rowspan = $numoftrs;
                 $cell->attributes['class'] = 'submission';
                 $row->cells[] = $cell;
             }
             // column #3 - received grades
             if ($tr % $spanreceived == 0) {
                 $idx = intval($tr / $spanreceived);
                 $assessment = self::array_nth($participant->reviewedby, $idx);
                 $cell = new html_table_cell();
                 $cell->text = $this->helper_grading_report_assessment($assessment, $options->showreviewernames, $userinfo, get_string('gradereceivedfrom', 'teamwork'));
                 $cell->rowspan = $spanreceived;
                 $cell->attributes['class'] = 'receivedgrade';
                 if (is_null($assessment) or is_null($assessment->grade)) {
                     $cell->attributes['class'] .= ' null';
                 } else {
                     $cell->attributes['class'] .= ' notnull';
                 }
                 $row->cells[] = $cell;
             }
             // column #4 - total grade for submission
             if ($options->showsubmissiongrade and $tr == 0) {
                 $cell = new html_table_cell();
                 $cell->text = $this->helper_grading_report_grade($participant->submissiongrade, $participant->submissiongradeover);
                 $cell->rowspan = $numoftrs;
                 $cell->attributes['class'] = 'submissiongrade';
                 $row->cells[] = $cell;
             }
             // column #5 - given grades
             if ($tr % $spangiven == 0) {
                 $idx = intval($tr / $spangiven);
                 $assessment = self::array_nth($participant->reviewerof, $idx);
                 $cell = new html_table_cell();
                 $cell->text = $this->helper_grading_report_assessment($assessment, $options->showauthornames, $userinfo, get_string('gradegivento', 'teamwork'));
                 $cell->rowspan = $spangiven;
                 $cell->attributes['class'] = 'givengrade';
                 if (is_null($assessment) or is_null($assessment->grade)) {
                     $cell->attributes['class'] .= ' null';
                 } else {
                     $cell->attributes['class'] .= ' notnull';
                 }
                 $row->cells[] = $cell;
             }
             // column #6 - total grade for assessment
             if ($options->showgradinggrade and $tr == 0) {
                 $cell = new html_table_cell();
                 $cell->text = $this->helper_grading_report_grade($participant->gradinggrade);
                 $cell->rowspan = $numoftrs;
                 $cell->attributes['class'] = 'gradinggrade';
                 $row->cells[] = $cell;
             }
             $table->data[] = $row;
         }
     }
     return html_writer::table($table);
 }
 public function test_lcm()
 {
     $this->resetAfterTest(true);
     // fixture setup + exercise SUT + verify in one step
     $this->assertEquals(teamwork::lcm(1, 4), 4);
     $this->assertEquals(teamwork::lcm(2, 4), 4);
     $this->assertEquals(teamwork::lcm(4, 2), 4);
     $this->assertEquals(teamwork::lcm(2, 3), 6);
     $this->assertEquals(teamwork::lcm(6, 4), 12);
 }