Révision 11b63505
Ajouté par Assos Assos il y a plus de 9 ans
drupal7/sites/all/modules/views_pdf/field_plugins/views_pdf_handler_page_break.inc | ||
---|---|---|
14 | 14 |
*/ |
15 | 15 |
class views_pdf_handler_page_break extends views_handler_field { |
16 | 16 |
|
17 |
protected $countRecords = 0; |
|
18 |
|
|
19 | 17 |
/** |
20 | 18 |
* This method is used to query data. In our case |
21 | 19 |
* we want that no data is queried. |
... | ... | |
63 | 61 |
} |
64 | 62 |
|
65 | 63 |
/** |
66 |
* This method renders the page break. It uses the PDF class to |
|
67 |
* add a page break. |
|
64 |
* This method renders the page break. |
|
65 |
* |
|
66 |
* Various settings from options form are taken into an account before |
|
67 |
* deciding whether to add pagebreak or not. |
|
68 | 68 |
*/ |
69 | 69 |
function render($values) { |
70 |
if (isset($this->view->pdf) && is_object($this->view->pdf)) {
|
|
71 |
if ($this->options['last_row'] == TRUE && ($this->countRecords + 1 >= $this->view->total_rows)) {
|
|
72 |
return '';
|
|
73 |
}
|
|
70 |
// Row index starts from 0 so substract 1 one from result count.
|
|
71 |
$last_row = $this->view->row_index == count($this->view->result) - 1;
|
|
72 |
// Calculate if 'every_nth' rule matches for this row.
|
|
73 |
$add_pagebreak = ($this->view->row_index + 1) % $this->options['every_nth'] == 0;
|
|
74 | 74 |
|
75 |
$this->countRecords++; |
|
76 |
if ($this->countRecords == $this->view->total_rows + 1) { |
|
77 |
$this->countRecords = 1; |
|
78 |
} |
|
79 |
|
|
80 |
$output = ''; |
|
81 |
if ($this->countRecords % $this->options['every_nth'] == 0) { |
|
82 |
$output .= '<br pagebreak="true" />'; |
|
83 |
} |
|
84 |
else { |
|
85 |
$output .= ''; |
|
86 |
} |
|
87 |
return $output; |
|
75 |
// Last row setting takes priority over 'every_nth' rule if we're infact |
|
76 |
// rendering last row. |
|
77 |
if (($this->options['last_row'] == FALSE || !$last_row) && $add_pagebreak) { |
|
78 |
return '<br pagebreak="true" />'; |
|
88 | 79 |
} |
80 |
|
|
81 |
return ''; |
|
89 | 82 |
} |
90 | 83 |
|
91 | 84 |
/** |
Formats disponibles : Unified diff
Weekly update of contrib modules