Esempio n. 1
0
 protected function render_attendance_report_data(attendance_report_data $reportdata)
 {
     $table = new html_table();
     $table->attributes['class'] = 'generaltable attwidth';
     // User picture.
     $table->head[] = '';
     $table->align[] = 'left';
     $table->size[] = '1px';
     $table->head[] = $this->construct_fullname_head($reportdata);
     $table->align[] = 'left';
     $table->size[] = '';
     $sessionstats = array();
     foreach ($reportdata->sessions as $sess) {
         $sesstext = userdate($sess->sessdate, get_string('strftimedm', 'attendance'));
         $sesstext .= html_writer::empty_tag('br');
         $sesstext .= userdate($sess->sessdate, '(' . get_string('strftimehm', 'attendance') . ')');
         if (is_null($sess->lasttaken) and $reportdata->perm->can_take() or $reportdata->perm->can_change()) {
             $sesstext = html_writer::link($reportdata->url_take($sess->id, $sess->groupid), $sesstext);
         }
         $sesstext .= html_writer::empty_tag('br');
         $sesstext .= $sess->groupid ? $reportdata->groups[$sess->groupid]->name : get_string('commonsession', 'attendance');
         $table->head[] = $sesstext;
         $table->align[] = 'center';
         $table->size[] = '1px';
     }
     foreach ($reportdata->statuses as $status) {
         $table->head[] = $status->acronym;
         $table->align[] = 'center';
         $table->size[] = '1px';
         $sessionstats[$status->id] = 0;
     }
     if ($reportdata->gradable) {
         $table->head[] = get_string('grade');
         $table->align[] = 'center';
         $table->size[] = '1px';
     }
     if ($reportdata->sessionslog) {
         $table->head[] = get_string('remarks', 'attendance');
         $table->align[] = 'center';
         $table->size[] = '200px';
     }
     foreach ($reportdata->users as $user) {
         $row = new html_table_row();
         $row->cells[] = $this->output->user_picture($user);
         $row->cells[] = html_writer::link($reportdata->url_view(array('studentid' => $user->id)), fullname($user));
         $cellsgenerator = new user_sessions_cells_html_generator($reportdata, $user);
         $row->cells = array_merge($row->cells, $cellsgenerator->get_cells());
         foreach ($reportdata->statuses as $status) {
             if (array_key_exists($status->id, $reportdata->usersstats[$user->id])) {
                 $row->cells[] = $reportdata->usersstats[$user->id][$status->id]->stcnt;
             } else {
                 // No attendance data for this $status => no statistic for this status.
                 $row->cells[] = 0;
             }
         }
         if ($reportdata->gradable) {
             $row->cells[] = $reportdata->grades[$user->id] . ' / ' . $reportdata->maxgrades[$user->id];
         }
         if ($reportdata->sessionslog) {
             if (isset($sess) && isset($reportdata->sessionslog[$user->id][$sess->id]->remarks)) {
                 $row->cells[] = $reportdata->sessionslog[$user->id][$sess->id]->remarks;
             } else {
                 $row->cells[] = '';
             }
         }
         $table->data[] = $row;
     }
     // Calculate the sum of statuses for each user
     $statrow = new html_table_row();
     $statrow->cells[] = '';
     $statrow->cells[] = get_string('summary');
     foreach ($reportdata->sessions as $sess) {
         foreach ($reportdata->users as $user) {
             foreach ($reportdata->statuses as $status) {
                 if (!empty($reportdata->sessionslog[$user->id][$sess->id])) {
                     if ($reportdata->sessionslog[$user->id][$sess->id]->statusid == $status->id) {
                         $sessionstats[$status->id]++;
                     }
                 }
             }
         }
         $statsoutput = '<br/>';
         foreach ($reportdata->statuses as $status) {
             $statsoutput .= "{$status->description}:" . $sessionstats[$status->id] . " <br/>";
         }
         $statrow->cells[] = $statsoutput;
     }
     $table->data[] = $statrow;
     return html_writer::table($table) . html_writer::tag('div', get_string('users') . ': ' . count($reportdata->users));
 }
 protected function render_attendance_report_data(attendance_report_data $reportdata)
 {
     global $PAGE;
     // Initilise Javascript used to (un)check all checkboxes.
     $this->page->requires->js_init_call('M.mod_attendance.init_manage');
     // Check if the user should be able to bulk send messages to other users on the course.
     $bulkmessagecapability = has_capability('moodle/course:bulkmessaging', $PAGE->context);
     $table = new html_table();
     $table->attributes['class'] = 'generaltable attwidth';
     // User picture.
     $table->head[] = '';
     $table->align[] = 'left';
     $table->size[] = '1px';
     $table->head[] = $this->construct_fullname_head($reportdata);
     $table->align[] = 'left';
     $table->size[] = '';
     $sessionstats = array();
     foreach ($reportdata->sessions as $sess) {
         $sesstext = userdate($sess->sessdate, get_string('strftimedm', 'attendance'));
         $sesstext .= html_writer::empty_tag('br');
         $sesstext .= userdate($sess->sessdate, '(' . get_string('strftimehm', 'attendance') . ')');
         if (is_null($sess->lasttaken) and $reportdata->perm->can_take() or $reportdata->perm->can_change()) {
             $sesstext = html_writer::link($reportdata->url_take($sess->id, $sess->groupid), $sesstext);
         }
         $sesstext .= html_writer::empty_tag('br');
         $sesstext .= $sess->groupid ? $reportdata->groups[$sess->groupid]->name : get_string('commonsession', 'attendance');
         $table->head[] = $sesstext;
         $table->align[] = 'center';
         $table->size[] = '1px';
     }
     foreach ($reportdata->statuses as $status) {
         $table->head[] = $status->acronym;
         $table->align[] = 'center';
         $table->size[] = '1px';
         $sessionstats[$status->id] = 0;
     }
     if ($reportdata->gradable) {
         $table->head[] = get_string('grade');
         $table->align[] = 'center';
         $table->size[] = '1px';
     }
     if ($bulkmessagecapability) {
         // Display the table header for bulk messaging.
         // The checkbox must have an id of cb_selector so that the JavaScript will pick it up.
         $table->head[] = html_writer::checkbox('cb_selector', 0, false, '', array('id' => 'cb_selector'));
         $table->align[] = 'center';
         $table->size[] = '1px';
     }
     foreach ($reportdata->users as $user) {
         $row = new html_table_row();
         $row->cells[] = $this->user_picture($user);
         // Show different picture if it is a temporary user.
         $row->cells[] = html_writer::link($reportdata->url_view(array('studentid' => $user->id)), fullname($user));
         $cellsgenerator = new user_sessions_cells_html_generator($reportdata, $user);
         $row->cells = array_merge($row->cells, $cellsgenerator->get_cells(true));
         foreach ($reportdata->statuses as $status) {
             if (array_key_exists($status->id, $reportdata->usersstats[$user->id])) {
                 $row->cells[] = $reportdata->usersstats[$user->id][$status->id]->stcnt;
             } else {
                 // No attendance data for this $status => no statistic for this status.
                 $row->cells[] = 0;
             }
         }
         if ($reportdata->gradable) {
             $row->cells[] = format_float($reportdata->grades[$user->id]) . ' / ' . format_float($reportdata->maxgrades[$user->id]);
         }
         if ($bulkmessagecapability) {
             // Create the checkbox for bulk messaging.
             $row->cells[] = html_writer::checkbox('user' . $user->id, 'on', false);
         }
         $table->data[] = $row;
     }
     // Calculate the sum of statuses for each user
     $statrow = new html_table_row();
     $statrow->cells[] = '';
     $statrow->cells[] = get_string('summary');
     foreach ($reportdata->sessions as $sess) {
         foreach ($reportdata->users as $user) {
             foreach ($reportdata->statuses as $status) {
                 if (!empty($reportdata->sessionslog[$user->id][$sess->id])) {
                     if ($reportdata->sessionslog[$user->id][$sess->id]->statusid == $status->id) {
                         $sessionstats[$status->id]++;
                     }
                 }
             }
         }
         $statsoutput = '<br/>';
         foreach ($reportdata->statuses as $status) {
             $statsoutput .= "{$status->description}:" . $sessionstats[$status->id] . " <br/>";
         }
         $statrow->cells[] = $statsoutput;
     }
     $table->data[] = $statrow;
     if ($bulkmessagecapability) {
         // Require that the user can bulk message users.
         // Display check boxes that will allow the user to send a message to the students that have been checked.
         $output = html_writer::empty_tag('input', array('name' => 'sesskey', 'type' => 'hidden', 'value' => sesskey()));
         $output .= html_writer::empty_tag('input', array('name' => 'formaction', 'type' => 'hidden', 'value' => 'messageselect.php'));
         $output .= html_writer::empty_tag('input', array('name' => 'id', 'type' => 'hidden', 'value' => $GLOBALS['COURSE']->id));
         $output .= html_writer::empty_tag('input', array('name' => 'returnto', 'type' => 'hidden', 'value' => s(me())));
         $output .= html_writer::table($table) . html_writer::tag('div', get_string('users') . ': ' . count($reportdata->users));
         $output .= html_writer::tag('div', html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('messageselectadd'))), array('class' => 'buttons'));
         $url = new moodle_url('/user/action_redir.php');
         return html_writer::tag('form', $output, array('action' => $url->out(), 'method' => 'post'));
     } else {
         return html_writer::table($table) . html_writer::tag('div', get_string('users') . ': ' . count($reportdata->users));
     }
 }
Esempio n. 3
0
 protected function render_attforblock_report_data(attforblock_report_data $reportdata)
 {
     $table = new html_table();
     $table->attributes['class'] = 'generaltable attwidth';
     // user picture
     $table->head[] = '';
     $table->align[] = 'left';
     $table->size[] = '1px';
     $table->head[] = $this->construct_fullname_head($reportdata);
     $table->align[] = 'left';
     $table->size[] = '';
     foreach ($reportdata->sessions as $sess) {
         $sesstext = userdate($sess->sessdate, get_string('strftimedm', 'attforblock'));
         $sesstext .= html_writer::empty_tag('br');
         $sesstext .= userdate($sess->sessdate, '(' . get_string('strftimehm', 'attforblock') . ')');
         if (is_null($sess->lasttaken) and $reportdata->perm->can_take() or $reportdata->perm->can_change()) {
             $sesstext = html_writer::link($reportdata->url_take($sess->id, $sess->groupid), $sesstext);
         }
         $sesstext .= html_writer::empty_tag('br');
         $sesstext .= $sess->groupid ? $reportdata->groups[$sess->groupid]->name : get_string('commonsession', 'attforblock');
         $table->head[] = $sesstext;
         $table->align[] = 'center';
         $table->size[] = '1px';
     }
     foreach ($reportdata->statuses as $status) {
         $table->head[] = $status->acronym;
         $table->align[] = 'center';
         $table->size[] = '1px';
     }
     if ($reportdata->gradable) {
         $table->head[] = get_string('grade');
         $table->align[] = 'center';
         $table->size[] = '1px';
     }
     foreach ($reportdata->users as $user) {
         $row = new html_table_row();
         $row->cells[] = $this->output->user_picture($user);
         $row->cells[] = html_writer::link($reportdata->url_view(array('studentid' => $user->id)), fullname($user));
         $cellsgenerator = new user_sessions_cells_html_generator($reportdata, $user);
         $row->cells = array_merge($row->cells, $cellsgenerator->get_cells());
         foreach ($reportdata->statuses as $status) {
             if (array_key_exists($status->id, $reportdata->usersstats[$user->id])) {
                 $row->cells[] = $reportdata->usersstats[$user->id][$status->id]->stcnt;
             } else {
                 // no attendance data for this $status => no statistic for this status
                 $row->cells[] = 0;
             }
         }
         if ($reportdata->gradable) {
             $row->cells[] = $reportdata->grades[$user->id] . ' / ' . $reportdata->maxgrades[$user->id];
         }
         $table->data[] = $row;
     }
     return html_writer::table($table);
 }