$data[] = get_string($plugintype, 'block_ilp'); if ($row->position != 1) { //if the field is in any position except 1 it needs a up icon $title = get_string('moveup', 'block_ilp'); $icon = $OUTPUT->pix_url("/t/up"); $movetype = "up"; $data[] = "<a href='{$CFG->wwwroot}/blocks/ilp/actions/move_field.php?reportfield_id={$row->id}&report_id={$report_id}&move=" . ILP_MOVE_UP . "&position={$row->position}'>\r\n\t\t\t\t\t\t\t\t\t<img class='move' src='{$icon}' alt='{$title}' title='{$title}' />\r\n\t\t\t\t\t\t\t\t \t</a>"; } else { $data[] = ""; } if ($totalreportfields != $row->position) { //if the field is in any position except last it needs a down icon $title = get_string('movedown', 'block_ilp'); $icon = $OUTPUT->pix_url("/t/down"); $movetype = "down"; $data[] = "<a href='{$CFG->wwwroot}/blocks/ilp/actions/move_field.php?reportfield_id={$row->id}&report_id={$report_id}&move=" . ILP_MOVE_DOWN . "&position={$row->position}'>\r\n\t\t\t\t\t\t\t\t\t<img class='move' src='{$icon}' alt='{$title}' title='{$title}' />\r\n\t\t\t\t\t\t\t\t \t</a>"; } else { $data[] = ""; } //set the edit field $data[] = "<a href='{$CFG->wwwroot}/blocks/ilp/actions/edit_field.php?reportfield_id={$row->id}&report_id={$report_id}&plugin_id={$row->plugin_id}'>\r\n\t\t\t\t\t\t\t\t\t<img class='edit' src='" . $OUTPUT->pix_url("/i/edit") . "' alt='" . get_string('edit') . "' title='" . get_string('edit') . "' />\r\n\t\t\t\t\t\t\t\t </a>"; //set the required field $title = !empty($row->req) ? get_string('required', 'block_ilp') : get_string('notrequired', 'block_ilp'); $icon = $CFG->wwwroot . "/blocks/ilp/pix/icons/"; $icon .= !empty($row->req) ? "required.gif" : "notrequired.gif"; $data[] = "<a href='{$CFG->wwwroot}/blocks/ilp/actions/edit_field_required.php?reportfield_id={$row->id}&report_id={$report_id}'>\r\n\t\t\t\t\t\t\t\t\t<img class='required' src='{$icon}' alt='{$title}' title='{$title}' />\r\n\t\t\t\t\t\t\t\t</a>"; $data[] = "<a href='{$CFG->wwwroot}/blocks/ilp/actions/delete_field.php?reportfield_id={$row->id}&report_id={$report_id}'>\r\n\t\t\t\t\t\t\t\t\t<img class='delete' src='" . $OUTPUT->pix_url("/t/delete") . "' alt='" . get_string('delete') . "' title='" . get_string('delete') . "' />\r\n\t\t\t\t\t\t\t\t </a>"; $flextable->add_data($data); } } require_once $CFG->dirroot . '/blocks/ilp/views/view_reportfields_table.html';
/** * * This function creates the register grid that is displayed * @param recordset $data recordset containing student register data * @param int $term the term that will be displayed if not supplied all terms are shown * @param unknown_type $course */ function term_attendance($data, $term = 0, $course = false) { global $CFG, $USER; $cidfield = get_config('block_ilp', 'mis_plugin_register_courseid'); $cdatefield = get_config('block_ilp', 'mis_plugin_register_datetime'); $markfield = get_config('block_ilp', 'mis_plugin_register_mark'); $timefield = get_config('block_ilp', 'mis_plugin_register_starttime'); $timefield = !empty($timefield) ? $timefield : 0; $cnamefield = get_config('block_ilp', 'mis_plugin_register_coursename'); $startdate = $this->terms[0]['startts']; if (!empty($term)) { $yearstart = $this->terms[0]['start']; $termstart = $this->terms[$term - 1]['start']; $termend = $this->terms[$term - 1]['end']; } else { $yearstart = $this->terms[0]['start']; $termstart = $this->terms[0]['start']; $termend = $this->terms[$this->numterms - 1]['end']; } //these variables define the academic weeks of $termstart and $termend $academicstart = $this->academic_week($termstart, $yearstart); $academicend = $this->academic_week($termend, $yearstart); $weekofseconds = 604800; //assign the tables column names $tablecolumns = array('class', 'late', 'att', 'date', 'time'); //set the displayed headers $tableheaders = array(get_string('ilp_mis_attendance_plugin_register_disp_class', 'block_ilp'), get_string('ilp_mis_attendance_plugin_register_disp_late', 'block_ilp'), get_string('ilp_mis_attendance_plugin_register_disp_att', 'block_ilp'), get_string('ilp_mis_attendance_plugin_register_disp_day', 'block_ilp'), get_string('ilp_mis_attendance_plugin_register_disp_time', 'block_ilp')); //assign the week column names and set the week display header for ($z = $academicstart; $z < $academicend + 1; $z++) { $tablecolumns[] = 'week' . $z; $tableheaders[] = $z; } require_once $CFG->dirroot . '/blocks/ilp/classes/tables/ilp_tablelib.class.php'; $table = new ilp_flexible_table('user-attendence', true, 'ilp_mis_attendance_plugin_register'); $table->define_columns($tablecolumns); $table->define_headers($tableheaders); $table->define_baseurl($CFG->wwwroot . '/blocks/ilp/attendence.php?&id=1'); $table->sortable(false); $table->collapsible(false); $table->initialbars(false); $table->set_attribute('cellpadding', '6'); $table->set_attribute('id', 'ilp-attendance-grid'); $table->set_attribute('class', 'generalbox'); $table->set_attribute('width', '100%'); $table->set_attribute('align', 'left'); $table->set_attribute('font-size', '0.85em'); $table->setup(); //set the row displaying the week dates $dates = array('', '', '', '', '<div class="termweeks">Week:</div>'); for ($z = $academicstart; $z < $academicend + 1; $z++) { $weekindays = ($z - 1) * 7; $timestampweek = strtotime("+{$weekindays} days", $startdate); //$timestampweek = $weekofseconds * ($z - 1); //$dates[] = '<div class="termweeks">' . $this->getMonday($startdate + $timestampweek) . '</div>'; $dates[] = '<div class="termweeks">' . $this->getMonday($timestampweek) . '</div>'; } $table->add_data($dates); $registers = array(); //we will now take the attendance data and construct an array separating class on day and time basis foreach ($data as $att) { $tempday = $this->courseday($att[$cdatefield]); $temptime = isset($att[$timefield]) ? $this->coursetime($att[$timefield]) : 'N/A'; $registers[$att[$cidfield]][$tempday][$temptime][] = $att; } $total = array(); foreach (array_keys($registers) as $groupKey) { $class = array('', '', '', '', ''); $termsweeks = array(); for ($z = $academicstart; $z < $academicend + 1; $z++) { $base_class[] = ''; $base_termsweeks[] = $z; } $class = $base_class; $termsweeks = $base_termsweeks; $total[$groupKey] = array(); foreach ($registers[$groupKey] as $cday => $timeslot) { foreach ($timeslot as $ctime => $classtime) { $total[$groupKey][$cday][$ctime] = array(array(0, 0, 0, 0), array(0, 0, 0, 0), array(0, 0, 0, 0), array(0, 0, 0, 0)); foreach ($classtime as $item) { //$item['Week_No'] = $this->weekno($item[$cdatefield]); $marktimestamp = strtotime($this->normalise_date($item[$cdatefield])); $item['Week_No'] = $this->academic_week(date('W', $marktimestamp), $yearstart); if (in_array($item['Week_No'], $termsweeks)) { if (!in_array($item[$markfield], $this->noclasscodes) && strlen($mark[$markfield]) > 0) { $total[$groupKey][$cday][$ctime][0][0]++; } if (in_array($item[$markfield], $this->presentcodes)) { $total[$groupKey][$cday][$ctime][1][0]++; } if (in_array($item[$markfield], $this->absentcodes)) { $total[$groupKey][$cday][$ctime][2][0]++; } if (in_array($item[$markfield], $this->latecodes)) { $total[$groupKey][$cday][$ctime][3][0]++; } $class['class'] = $item[$cidfield] . ': ' . $item[$cnamefield]; $startdate = explode('-', $item[$cdatefield]); $class['date'] = $this->courseday($item[$cdatefield]); $class['time'] = $ctime; $att_class = 'amber'; if (in_array($item[$markfield], $this->presentcodes)) { $att_class = get_config('block_ilp', 'mis_plugin_register_presentcolour'); } if (in_array($item[$markfield], $this->absentcodes)) { $att_class = get_config('block_ilp', 'mis_plugin_register_absentcolour'); } if (in_array($item[$markfield], $this->latecodes)) { $att_class = get_config('block_ilp', 'mis_plugin_register_latecolour'); } $class['week' . $item['Week_No']] = '<span style="display:block; text-align:center; background-color:' . $att_class . '" title="">' . $item[$markfield] . '</span>'; } } //calculate the attendance and late averages if ($total[$groupKey][$cday][$ctime][0][$term] != 0) { $class['late'] = round($total[$groupKey][$cday][$ctime][3][$term] / $total[$groupKey][$cday][$ctime][0][$term] * 100, 0) . '%'; $class['att'] = round($total[$groupKey][$cday][$ctime][1][$term] / $total[$groupKey][$cday][$ctime][0][$term] * 100, 0) . '%'; } $classdata[] = $class; //reset $class and $termsweeks to their original states $class = $base_class; $termsweeks = $base_termsweeks; } } } foreach ($classdata as $class) { $table->add_data_keyed($class); } $table->print_html(); }