Projet

Général

Profil

Paste
Télécharger (2,39 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / views_pdf / field_plugins / views_pdf_handler_page_break.inc @ 3dfa8105

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
  protected $countRecords = 0;
18

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

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

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

    
40
    return $options;
41
  }
42

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

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

    
65
  /**
66
   * This method renders the page break. It uses the PDF class to
67
   * add a page break.
68
   */
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
      }
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;
88
    }
89
  }
90

    
91
  /**
92
   * We dont want to use advanced rendering.
93
   */
94
  function allow_advanced_render() {
95
    return FALSE;
96
  }
97
}