forked from bostelm/moodle-mod_scheduler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exportlib.php
1100 lines (892 loc) · 31 KB
/
exportlib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Library for export functions
*
* @package mod_scheduler
* @copyright 2016 Henning Bostelmann and others (see README.txt)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/lib/excellib.class.php');
require_once($CFG->dirroot.'/lib/odslib.class.php');
require_once($CFG->dirroot.'/lib/csvlib.class.php');
require_once($CFG->dirroot.'/lib/pdflib.php');
/**
* A data field included in an export from Scheduler.
*/
abstract class scheduler_export_field {
protected $renderer;
public function set_renderer(mod_scheduler_renderer $renderer) {
$this->renderer = $renderer;
}
/**
* Is the field available in this scheduler?
* @return boolean whether the field is available
*/
public function is_available(scheduler_instance $scheduler) {
return true;
}
/**
* Retrieve the unique id (a string) for this field
*/
public abstract function get_id();
/**
* Retrieve the group that this field belongs to -
* either 'slot' or 'student' or 'appointment',
*
* @return string the group id as above
*/
public abstract function get_group();
/**
* Retrieve the header (in the sense of table header in the output)
* used for this field.
*
* @param $scheduler the scheduler instance in question
* @return string the header for this field
*/
public function get_header(scheduler_instance $scheduler) {
return get_string('field-'.$this->get_id(), 'scheduler');
}
/**
* Retrieve the label used in the configuration form to label this field.
* By default, this equals the table header.
*
* @param $scheduler the scheduler instance in question
* @return string the form label for this field
*/
public function get_formlabel(scheduler_instance $scheduler) {
return $this->get_header($scheduler);
}
/**
* Retrieve the typical width (in characters) of this field.
* This is used to set the width of columns in the output, where this is relevant.
*
* @param $scheduler the scheduler instance in question
* @return int the width of this field (number of characters)
*/
public function get_typical_width(scheduler_instance $scheduler) {
return strlen($this->get_formlabel($scheduler));
}
/**
* Does this field use wrapped text?
*
* @return boolean whether wrapping is used for this field
*/
public function is_wrapping() {
return false;
}
/**
* Retrieve the value of this field in a particular data record
*
* @param $slot the scheduler slot to get data from
* @param $appointment the appointment to evaluate (may be null for an empty slot)
* @return string the value of this field for the given data
*/
public abstract function get_value(scheduler_slot $slot, $appointment);
}
/**
* Get a list of all export fields available.
*
* @return array the fields as an array of scheduler_export_field objects.
*/
function scheduler_get_export_fields() {
$result = array();
$result[] = new scheduler_slotdate_field();
$result[] = new scheduler_starttime_field();
$result[] = new scheduler_endtime_field();
$result[] = new scheduler_location_field();
$result[] = new scheduler_teachername_field();
$result[] = new scheduler_maxstudents_field();
$result[] = new scheduler_slotnotes_field();
$result[] = new scheduler_student_field('studentfullname', 'fullname', 25);
$result[] = new scheduler_student_field('studentfirstname', 'firstname');
$result[] = new scheduler_student_field('studentlastname', 'lastname');
$result[] = new scheduler_student_field('studentemail', 'email');
$result[] = new scheduler_student_field('studentusername', 'username');
$result[] = new scheduler_student_field('studentidnumber', 'idnumber');
$result[] = new scheduler_attended_field();
$result[] = new scheduler_grade_field();
$result[] = new scheduler_appointmentnote_field();
$result[] = new scheduler_teachernote_field();
return $result;
}
/**
* Export field: Date of the slot
*/
class scheduler_slotdate_field extends scheduler_export_field {
public function get_id() {
return 'date';
}
public function get_group() {
return 'slot';
}
public function get_typical_width(scheduler_instance $scheduler) {
return strlen(mod_scheduler_renderer::userdate(1)) + 3;
}
public function get_value(scheduler_slot $slot, $appointment) {
return mod_scheduler_renderer::userdate($slot->starttime);
}
}
/**
* Export field: Start time of the slot
*/
class scheduler_starttime_field extends scheduler_export_field {
public function get_id() {
return 'starttime';
}
public function get_group() {
return 'slot';
}
public function get_value(scheduler_slot $slot, $appointment) {
return mod_scheduler_renderer::usertime($slot->starttime);
}
}
/**
* Export field: End time of the slot
*/
class scheduler_endtime_field extends scheduler_export_field {
public function get_id() {
return 'endtime';
}
public function get_group() {
return 'slot';
}
public function get_value(scheduler_slot $slot, $appointment) {
return mod_scheduler_renderer::usertime($slot->endtime);
}
}
/**
* Export field: Full name of the teacher
*/
class scheduler_teachername_field extends scheduler_export_field {
public function get_id() {
return 'teachername';
}
public function get_group() {
return 'slot';
}
public function get_header(scheduler_instance $scheduler) {
return $scheduler->get_teacher_name();
}
public function get_typical_width(scheduler_instance $scheduler) {
return 20;
}
public function get_value(scheduler_slot $slot, $appointment) {
return fullname($slot->teacher);
}
}
/**
* Export field: Appointment location
*/
class scheduler_location_field extends scheduler_export_field {
public function get_id() {
return 'location';
}
public function get_group() {
return 'slot';
}
public function get_value(scheduler_slot $slot, $appointment) {
return format_string($slot->appointmentlocation);
}
}
/**
* Export field: Maximum number of students / appointments in the slot
*/
class scheduler_maxstudents_field extends scheduler_export_field {
public function get_id() {
return 'maxstudents';
}
public function get_group() {
return 'slot';
}
public function get_value(scheduler_slot $slot, $appointment) {
if ($slot->exclusivity <= 0) {
return get_string('unlimited', 'scheduler');
} else {
return $slot->exclusivity;
}
}
}
/**
* Export field: A field in the student record (to be chosen via the constructor)
*/
class scheduler_student_field extends scheduler_export_field {
protected $id;
protected $studfield;
protected $typicalwidth;
public function __construct($id, $studfield, $typicalwidth=0) {
$this->id = $id;
$this->studfield = $studfield;
$this->typicalwidth = $typicalwidth;
}
public function get_id() {
return $this->id;
}
public function get_group() {
return 'student';
}
public function get_typical_width(scheduler_instance $scheduler) {
if ($this->typicalwidth > 0) {
return $this->typicalwidth;
} else {
return parent::get_typical_width($scheduler);
}
}
public function get_value(scheduler_slot $slot, $appointment) {
if (! $appointment instanceof scheduler_appointment) {
return '';
}
$student = $appointment->get_student();
if (is_null($student)) {
return '';
}
if ($this->studfield == 'fullname') {
return fullname($student);
} else {
return $student->{$this->studfield};
}
}
}
/**
* Export field: Whether the appointment has been attended
*/
class scheduler_attended_field extends scheduler_export_field {
public function get_id() {
return 'attended';
}
public function get_group() {
return 'appointment';
}
public function get_value(scheduler_slot $slot, $appointment) {
if (! $appointment instanceof scheduler_appointment) {
return '';
}
$str = $appointment->is_attended() ? get_string('yes') : get_string('no');
return $str;
}
}
/**
* Export field: Slot notes
*/
class scheduler_slotnotes_field extends scheduler_export_field {
public function get_id() {
return 'slotnotes';
}
public function get_group() {
return 'slot';
}
public function get_typical_width(scheduler_instance $scheduler) {
return 30;
}
public function is_wrapping() {
return true;
}
public function get_value(scheduler_slot $slot, $appointment) {
return strip_tags($slot->notes);
}
}
/**
* Export field: Appointment notes
*/
class scheduler_appointmentnote_field extends scheduler_export_field {
public function get_id() {
return 'appointmentnote';
}
public function get_group() {
return 'appointment';
}
public function get_typical_width(scheduler_instance $scheduler) {
return 30;
}
public function is_wrapping() {
return true;
}
public function is_available(scheduler_instance $scheduler) {
return $scheduler->uses_appointmentnotes();
}
public function get_value(scheduler_slot $slot, $appointment) {
if (! $appointment instanceof scheduler_appointment) {
return '';
}
return strip_tags($appointment->appointmentnote);
}
}
/**
* Export field: Teacher notes
*/
class scheduler_teachernote_field extends scheduler_export_field {
public function get_id() {
return 'teachernote';
}
public function get_group() {
return 'appointment';
}
public function get_typical_width(scheduler_instance $scheduler) {
return 30;
}
public function is_wrapping() {
return true;
}
public function is_available(scheduler_instance $scheduler) {
return $scheduler->uses_teachernotes();
}
public function get_value(scheduler_slot $slot, $appointment) {
if (! $appointment instanceof scheduler_appointment) {
return '';
}
return strip_tags($appointment->teachernote);
}
}
/**
* Export field: Grade for the appointment
*/
class scheduler_grade_field extends scheduler_export_field {
public function get_id() {
return 'grade';
}
public function get_group() {
return 'appointment';
}
public function is_available(scheduler_instance $scheduler) {
return $scheduler->uses_grades();
}
public function get_value(scheduler_slot $slot, $appointment) {
if (! $appointment instanceof scheduler_appointment) {
return '';
}
return $this->renderer->format_grade($slot->get_scheduler(), $appointment->grade);
}
}
/**
* An "output device" for scheduler exports
*/
abstract class scheduler_canvas {
public $formatheader;
public $formatbold;
public $formatboldit;
public $formatwrap;
/**
* Start a new page (tab, etc.) with an optional title.
*
* @param $title the title of the page
*/
public abstract function start_page($title);
/**
* Write a string into a certain position of the canvas.
*
* @param $row the row into which to write (starts with 0)
* @param $column the column into which to write (starts with 0)
* @param $str the string to write
* @param $format the format to use (one of the $format... fields of this object), can be null
*/
public abstract function write_string($row, $col, $str, $format);
/**
* Write a number into a certain position of the canvas.
*
* @param $row the row into which to write (starts with 0)
* @param $column the column into which to write (starts with 0)
* @param $num the number to write
* @param $format the format to use (one of the $format... fields of this object), can be null
*/
public abstract function write_number($row, $col, $num, $format);
/**
* Merge a range of cells in the same row.
*
* @param $row the row in which to merge
* @param $fromcol the first column to merge
* @param $tocol the last column to merge
*/
public abstract function merge_cells($row, $fromcol, $tocol);
/**
* Set the width of a particular column. (This will make sense only for certain outout formats,
* it can be ignored otherwise.)
*
* @param $col the affected column
* @param $width the width of that column
*/
public function set_column_width($col, $width) {
// Ignore widths by default.
}
protected $title;
/**
* Set the title of the entire output file.
*
* This is stored in the field $title, and can be used as appropriate for the particular implementation.
*
* @param title the title to set
*/
public function set_title($title) {
$this->title = $title;
}
/**
* Send the output file via HTTP, as a downloadable file.
*
* @param $filename the file name to send
*/
public abstract function send($filename);
}
/**
* Output device: Excel file
*/
class scheduler_excel_canvas extends scheduler_canvas {
protected $workbook;
protected $worksheet;
public function __construct() {
// Create a workbook.
$this->workbook = new MoodleExcelWorkbook("-");
// Set up formats.
$this->formatheader = $this->workbook->add_format();
$this->formatbold = $this->workbook->add_format();
$this->formatbold = $this->workbook->add_format();
$this->formatboldit = $this->workbook->add_format();
$this->formatwrap = $this->workbook->add_format();
$this->formatheader->set_bold();
$this->formatbold->set_bold();
$this->formatboldit->set_bold();
$this->formatboldit->set_italic();
$this->formatwrap->set_text_wrap();
}
public function start_page($title) {
$this->worksheet = $this->workbook->add_worksheet($title);
}
private function ensure_open_page() {
if (!$this->worksheet) {
$this->start_page('');
}
}
public function write_string($row, $col, $str, $format=null) {
$this->ensure_open_page();
$this->worksheet->write_string($row, $col, $str, $format);
}
public function write_number($row, $col, $num, $format=null) {
$this->ensure_open_page();
$this->worksheet->write_number($row, $col, $num, $format);
}
public function merge_cells($row, $fromcol, $tocol) {
$this->ensure_open_page();
$this->worksheet->merge_cells($row, $fromcol, $row, $tocol);
}
public function set_column_width($col, $width) {
$this->worksheet->set_column($col, $col, $width);
}
public function send($filename) {
$this->workbook->send($filename);
$this->workbook->close();
}
}
/**
* Output device: ODS file
*/
class scheduler_ods_canvas extends scheduler_canvas {
protected $workbook;
protected $worksheet;
public function __construct() {
// Create a workbook.
$this->workbook = new MoodleODSWorkbook("-");
// Set up formats.
$this->formatheader = $this->workbook->add_format();
$this->formatbold = $this->workbook->add_format();
$this->formatboldit = $this->workbook->add_format();
$this->formatwrap = $this->workbook->add_format();
$this->formatheader->set_bold();
$this->formatbold->set_bold();
$this->formatboldit->set_bold();
$this->formatboldit->set_italic();
$this->formatwrap->set_text_wrap();
}
public function start_page($title) {
$this->worksheet = $this->workbook->add_worksheet($title);
}
private function ensure_open_page() {
if (!$this->worksheet) {
$this->start_page('');
}
}
public function write_string($row, $col, $str, $format=null) {
$this->ensure_open_page();
$this->worksheet->write_string($row, $col, $str, $format);
}
public function write_number($row, $col, $num, $format=null) {
$this->ensure_open_page();
$this->worksheet->write_number($row, $col, $num, $format);
}
public function merge_cells($row, $fromcol, $tocol) {
$this->ensure_open_page();
$this->worksheet->merge_cells($row, $fromcol, $row, $tocol);
}
public function set_column_width($col, $width) {
$this->worksheet->set_column($col, $col, $width);
}
public function send($filename) {
$this->workbook->send($filename);
$this->workbook->close();
}
}
/**
* An output device that is based on first collecting all text in an array.
*/
abstract class scheduler_cached_text_canvas extends scheduler_canvas {
protected $pages;
protected $curpage;
public function __construct() {
$this->formatheader = 'header';
$this->formatbold = 'bold';
$this->formatboldit = 'boldit';
$this->formatwrap = 'wrap';
$this->start_page('');
}
protected function get_col_count($page) {
$maxcol = 0;
foreach ($page->cells as $rownum => $row) {
foreach ($row as $colnum => $col) {
if ($colnum > $maxcol) {
$maxcol = $colnum;
}
}
}
return $maxcol + 1;
}
protected function get_row_count($page) {
$maxrow = 0;
foreach ($page->cells as $rownum => $row) {
if ($rownum > $maxrow) {
$maxrow = $rownum;
}
}
return $maxrow + 1;
}
protected function compute_relative_widths($page) {
$cols = $this->get_col_count($page);
$sum = 0;
foreach ($page->columnwidths as $width) {
$sum += $width;
}
$relwidths = array();
for ($col = 0; $col < $cols; $col++) {
if ($sum > 0 && isset($page->columnwidths[$col])) {
$relwidths[$col] = (int) ($page->columnwidths[$col] / $sum * 100);
} else {
$relwidths[$col] = 0;
}
}
return $relwidths;
}
public function start_page($title) {
$onemptypage = $this->curpage && !$this->curpage->cells && !$this->curpage->mergers && !$this->curpage->title;
if ($onemptypage) {
$this->curpage->title = $title;
} else {
$newpage = new stdClass;
$newpage->title = $title;
$newpage->cells = array();
$newpage->formats = array();
$newpage->mergers = array();
$newpage->columnwidths = array();
$this->pages[] = $newpage;
$this->curpage = $newpage;
}
}
public function write_string($row, $col, $str, $format=null) {
$this->curpage->cells[$row][$col] = $str;
$this->curpage->formats[$row][$col] = $format;
}
public function write_number($row, $col, $num, $format=null) {
$this->write_string($row, $col, $num, $format);
}
public function merge_cells($row, $fromcol, $tocol) {
$this->curpage->mergers[$row][$fromcol] = $tocol - $fromcol + 1;
}
public function set_column_width($col, $width) {
$this->curpage->columnwidths[$col] = $width;
}
}
/**
* Output device: HTML file
*/
class scheduler_html_canvas extends scheduler_cached_text_canvas {
public function as_html($rowcutoff, $usetitle = true) {
global $OUTPUT;
$o = '';
if ($usetitle && $this->title) {
$o .= html_writer::tag('h1', $this->title);
}
foreach ($this->pages as $page) {
if ($page->title) {
$o .= html_writer::tag('h2', $page->title);
}
// Find extent of the table.
$rows = $this->get_row_count($page);
$cols = $this->get_col_count($page);
if ($rowcutoff && $rows > $rowcutoff) {
$rows = $rowcutoff;
}
$relwidths = $this->compute_relative_widths($page);
$table = new html_table();
$table->cellpadding = 3;
for ($row = 0; $row < $rows; $row++) {
$hrow = new html_table_row();
$col = 0;
while ($col < $cols) {
$span = 1;
if (isset($page->mergers[$row][$col])) {
$mergewidth = (int) $page->mergers[$row][$col];
if ($mergewidth >= 1) {
$span = $mergewidth;
}
}
$cell = new html_table_cell('');
$text = '';
if (isset($page->cells[$row][$col])) {
$text = $page->cells[$row][$col];
}
if (isset($page->formats[$row][$col])) {
$cell->header = ($page->formats[$row][$col] == 'header');
if ($page->formats[$row][$col] == 'boldit') {
$text = html_writer::tag('i', $text);
$text = html_writer::tag('b', $text);
}
if ($page->formats[$row][$col] == 'bold') {
$text = html_writer::tag('b', $text);
}
}
if ($span > 1) {
$cell->colspan = $span;
}
if ($row == 0 & $relwidths[$col] > 0) {
$cell->width = $relwidths[$col].'%';
}
$cell->text = $text;
$hrow->cells[] = $cell;
$col = $col + $span;
}
$table->data[] = $hrow;
}
$o .= html_writer::table($table);
}
return $o;
}
public function send($filename) {
global $OUTPUT, $PAGE;
$PAGE->set_pagelayout('print');
echo $OUTPUT->header();
echo $this->as_html(0, true);
echo $OUTPUT->footer();
}
}
/**
* Output device: CSV (text) file
*/
class scheduler_csv_canvas extends scheduler_cached_text_canvas {
protected $delimiter;
public function __construct($delimiter) {
parent::__construct();
$this->delimiter = $delimiter;
}
public function send($filename) {
$writer = new csv_export_writer($this->delimiter);
$writer->set_filename($filename);
foreach ($this->pages as $page) {
if ($page->title) {
$writer->add_data(array('*** '.$page->title.' ***'));
}
// Find extent of the table.
$rows = $this->get_row_count($page);
$cols = $this->get_col_count($page);
for ($row = 0; $row < $rows; $row++) {
$data = array();
$col = 0;
while ($col < $cols) {
if (isset($page->cells[$row][$col])) {
$data[] = $page->cells[$row][$col];
} else {
$data[] = '';
}
$span = 1;
if (isset($page->mergers[$row][$col])) {
$mergewidth = (int) $page->mergers[$row][$col];
if ($mergewidth >= 1) {
$span = $mergewidth;
}
}
$col += $span;
}
$writer->add_data($data);
}
}
$writer->download_file();
}
}
/**
* Output device: PDF file
*/
class scheduler_pdf_canvas extends scheduler_cached_text_canvas {
protected $orientation;
public function __construct($orientation) {
parent::__construct();
$this->orientation = $orientation;
}
public function send($filename) {
$doc = new pdf($this->orientation);
if ($this->title) {
$doc->setHeaderData('', 0, $this->title);
$doc->setPrintHeader(true);
} else {
$doc->setPrintHeader(false);
}
$doc->setPrintFooter(false);
foreach ($this->pages as $page) {
$doc->AddPage();
if ($page->title) {
$doc->writeHtml('<h2>'.$page->title.'</h2>');
}
// Find extent of the table.
$rows = $this->get_row_count($page);
$cols = $this->get_col_count($page);
$relwidths = $this->compute_relative_widths($page);
$o = html_writer::start_tag('table', array('border' => 1, 'cellpadding' => 1));
for ($row = 0; $row < $rows; $row++) {
$o .= html_writer::start_tag('tr');
$col = 0;
while ($col < $cols) {
$span = 1;
if (isset($page->mergers[$row][$col])) {
$mergewidth = (int) $page->mergers[$row][$col];
if ($mergewidth >= 1) {
$span = $mergewidth;
}
}
$opts = array();
if ($row == 0 && $relwidths[$col] > 0) {
$opts['width'] = $relwidths[$col].'%';
}
if ($span > 1) {
$opts['colspan'] = $span;
}
$o .= html_writer::start_tag('td', $opts);
$cell = '';
if (isset($page->cells[$row][$col])) {
$cell = s($page->cells[$row][$col]);
if (isset($page->formats[$row][$col])) {
$thisformat = $page->formats[$row][$col];
if ($thisformat == 'header') {
$cell = html_writer::tag('b', $cell);
} else if ($thisformat == 'boldit') {
$cell = html_writer::tag('i', $cell);
}
}
}
$o .= $cell;
$o .= html_writer::end_tag('td');
$col += $span;
}
$o .= html_writer::end_tag('tr');
}
$o .= html_Writer::end_tag('table');
$doc->writeHtml($o);
}
$doc->Output($filename.'.pdf');
}
}
/**
* A class that generates the export file with given settings.
*/
class scheduler_export {
protected $canvas;
protected $studfilter = null;
public function __construct(scheduler_canvas $canvas) {
$this->canvas = $canvas;
}
public function build(scheduler_instance $scheduler, array $fields, $mode, $userid, $groupid, $includeempty, $pageperteacher) {
if ($groupid) {
$this->studfilter = array_keys(groups_get_members($groupid, 'u.id'));