Project

General

Profile

Paste
Download (2.42 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / views_pdf / field_plugins / views_pdf_handler_page_break.inc @ 11b63505

1
<?php
2
/**
3
 * @file
4
 * The page break plugin for PDF page display.
5
 *
6
 * This plugin is used to add a page break to a PDF display.
7
 *
8
 */
9

    
10
/**
11
 * Plugin class that holds the functionality for the
12
 * page break in a PDF display.
13
 *
14
 */
15
class views_pdf_handler_page_break extends views_handler_field {
16

    
17
  /**
18
   * This method  is used to query data. In our case
19
   * we want that no data is queried.
20
   *
21
   */
22
  function query() {
23
    // Override parent::query() and don't alter query.
24
    $this->field_alias = 'pdf_page_break_' . $this->position;
25
  }
26

    
27
  /**
28
   * This method contains the defintion of the options for the page
29
   * break.
30
   *
31
   */
32
  function option_definition() {
33
    $options = parent::option_definition();
34

    
35
    $options['last_row'] = array('default' => FALSE);
36
    $options['every_nth'] = array('default' => 1);
37

    
38
    return $options;
39
  }
40

    
41
  /**
42
   * Option form
43
   */
44
  function options_form(&$form, &$form_state) {
45
    parent::options_form($form, $form_state);
46

    
47
    $form['last_row'] = array(
48
      '#type' => 'checkbox',
49
      '#title' => t('Exclude from last row'),
50
      '#default_value' => $this->options['last_row'],
51
      '#description' => t('Check this box to not add new page on last row.'),
52
    );
53
    $form['every_nth'] = array(
54
      '#type' => 'textfield',
55
      '#title' => t('Insert break after how many rows?'),
56
      '#size' => 10,
57
      '#default_value' => $this->options['every_nth'],
58
      '#element_validate' => array('element_validate_integer_positive'),
59
      '#description' => t('Enter a value greater than 1 if you want to have multiple rows on one page')
60
    );
61
  }
62

    
63
  /**
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
   */
69
  function render($values) {
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

    
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" />';
79
    }
80

    
81
    return '';
82
  }
83

    
84
  /**
85
   * We dont want to use advanced rendering.
86
   */
87
  function allow_advanced_render() {
88
    return FALSE;
89
  }
90
}