Skip to content

Commit

Permalink
Merge branch 'MDL-65954-master' of git://github.com/junpataleta/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Jul 16, 2019
2 parents c8898e7 + b3f4d77 commit e752e12
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions dataformat/pdf/classes/writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public function start_sheet($columns) {
public function write_record($record, $rownum) {
$rowheight = 0;

// If $record is an object convert it to an array.
if (is_object($record)) {
$record = (array)$record;
}

foreach ($record as $cell) {
$rowheight = max($rowheight, $this->pdf->getStringHeight($this->colwidth, $cell, false, true, '', 1));
}
Expand All @@ -99,12 +104,19 @@ public function write_record($record, $rownum) {
$this->print_heading();
}

$total = count($record);
$counter = 1;
foreach ($record as $cell) {
$nextposition = ($counter == $total) ? 1 : 0;
// Get the last key for this record.
end($record);
$lastkey = key($record);

// Reset the record pointer.
reset($record);

// Loop through each element.
foreach ($record as $key => $cell) {
// Determine whether we're at the last element of the record.
$nextposition = ($lastkey === $key) ? 1 : 0;
// Write the element.
$this->pdf->Multicell($this->colwidth, $rowheight, $cell, 1, 'L', false, $nextposition);
$counter++;
}
}

Expand Down

0 comments on commit e752e12

Please sign in to comment.