Commit 7b38884c authored by svipsa's avatar svipsa
Browse files

Added new options and themplates

parent ae471275
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -29,4 +29,5 @@ Follow the instructions from README.txt of the Views Data Export module.

Credits
-------

Sergey Grigorenko <https://www.drupal.org/u/svipsa>
+19 −6
Original line number Diff line number Diff line
@@ -22,13 +22,26 @@ class views_data_export_pdf_plugin_display_export extends views_data_export_plug
  public function generate_pdf($html, $filename = NULL) {
    if (($library = libraries_load('phpwkhtmltopdf')) && !empty($library['loaded'])) {
      try {
        $options = array('binary' => variable_get('views_data_export_pdf_wkhtmltopdf', '/usr/local/bin/wkhtmltopdf'));
        $options = ['binary' => variable_get('views_data_export_pdf_wkhtmltopdf', '/usr/local/bin/wkhtmltopdf')];

        $is_landscape = (isset($this->options['style_options']['landscape']) && $this->options['style_options']['landscape']) ? TRUE : FALSE;
        if ($is_landscape) {
          $options['orientation'] = 'landscape';
        }

        $page_width = (isset($this->options['style_options']['page_width'])) ? $this->options['style_options']['page_width'] : "";
        $page_height = (isset($this->options['style_options']['page_height'])) ? $this->options['style_options']['page_height'] : "";

        if (!empty($page_width) && !empty($page_height)) {
          $options['page-width'] = $page_width;
          $options['page-height'] = $page_height;
        }

        $options['header-html'] = url("views_data_export_pdf/header-html/" . $this->view->name, array("absolute" => TRUE));
        $options['footer-html'] = url("views_data_export_pdf/footer-html/" . $this->view->name, array("absolute" => TRUE));

        drupal_alter("views_data_export_wkhtmltopdf_options", $options);

        $pdf = new WkHtmlToPdf($options);

        $pdf->addPage($html);
@@ -130,9 +143,9 @@ class views_data_export_pdf_plugin_display_export extends views_data_export_plug
    if (empty($this->view->live_preview) && isset($this->options['style_options']['provide_file']) && $this->options['style_options']['provide_file']) {
      $this->add_http_headers();
    }
    $headers = array(
    $headers = [
      'Content-Length' => $this->outputfile_entity()->filesize,
    );
    ];

    file_transfer($this->outputfile_path(), $headers);
  }
@@ -143,9 +156,9 @@ class views_data_export_pdf_plugin_display_export extends views_data_export_plug
   */
  function option_definition() {
    $options = parent::option_definition();
    $options['use_batch'] = array('default' => 'no_batch');
    $options['items_per_page'] = array('default' => '0');
    $options['return_path'] = array('default' => '');
    $options['use_batch'] = ['default' => 'no_batch'];
    $options['items_per_page'] = ['default' => '0'];
    $options['return_path'] = ['default' => ''];
    $options['style_plugin']['default'] = 'views_data_export_pdf';

    // This is the default size of a segment when doing a batched export.
+63 −27
Original line number Diff line number Diff line
@@ -15,15 +15,30 @@ class views_data_export_pdf_plugin_style_export extends views_data_export_plugin
  function option_definition() {
    $options = parent::option_definition();

    $options['landscape'] = array(
    $options['each_group_separate_table'] = [
      'default' => FALSE,
      'translatable' => FALSE,
    );
    ];

    $options['user_style_sheet'] = array(
    $options['landscape'] = [
      'default' => FALSE,
      'translatable' => FALSE,
    ];

    $options['page_width'] = [
      'default' => "",
      'translatable' => FALSE,
    ];

    $options['page_height'] = [
      'default' => "",
      'translatable' => FALSE,
    );
    ];

    $options['user_style_sheet'] = [
      'default' => "",
      'translatable' => FALSE,
    ];
    return $options;
  }

@@ -34,29 +49,50 @@ class views_data_export_pdf_plugin_style_export extends views_data_export_plugin
   * Form array to add additional fields to.
   * @param $form_state
   * State of the form.
   *
   * @return
   * None.
   */
  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);

    $form['landscape'] = array(
    $form['/'] = [
      '#type' => 'checkbox',
      '#title' => t('Each group as separate table'),
      '#default_value' => $this->options['each_group_separate_table'],
      '#description' => t('If used grouping, this option provide rendering each group as separate table.'),
    ];

    $form['landscape'] = [
      '#type' => 'checkbox',
      '#title' => t('Landscape'),
      '#default_value' => $this->options['landscape'],
      '#description' => t('PDF Landscape format.'),
    );
    $form['user_style_sheet'] = array(
    ];

    $form['page_width'] = [
      '#type' => 'textfield',
      '#title' => t('Page width'),
      '#default_value' => $this->options['page_width'],
      '#description' => t('Page width in mm. Left empty for default A4 format.'),
    ];
    $form['page_height'] = [
      '#type' => 'textfield',
      '#title' => t('Page height'),
      '#default_value' => $this->options['page_height'],
      '#description' => t('Page height in mm. Left empty for default A4 format.'),
    ];
    $form['user_style_sheet'] = [
      '#type' => 'textfield',
      '#title' => t('User style sheet path'),
      '#default_value' => $this->options['user_style_sheet'],
      '#description' => t('Add user style sheet from path. Example sites/default/files/pdf_style.css'),
    );
    ];

  }

  function render_header() {
    $rows = array();
    $rows = [];
    $title = '';
    $output = '';
    $head = '';
@@ -65,10 +101,10 @@ class views_data_export_pdf_plugin_style_export extends views_data_export_plugin
    if (!empty($is_style_sheet)) {
      $path = ltrim($is_style_sheet, "/");
      if (!empty($path) && file_exists($path)) {
        $styles = array(
        $styles = [
          '#type' => 'styles',
          '#items' => array(
            $path => array(
          '#items' => [
            $path => [
              'type' => 'file',
              'group' => CSS_DEFAULT,
              'weight' => 0,
@@ -76,27 +112,27 @@ class views_data_export_pdf_plugin_style_export extends views_data_export_plugin
              'media' => 'all',
              'preprocess' => FALSE,
              'data' => $path,
              'browsers' => array(
              'browsers' => [
                'IE' => TRUE,
                '!IE' => TRUE,
              ),
            )
          ),
        );
              ],
            ],
          ],
        ];
        $head = drupal_render($styles);
      }
      else {
        watchdog("views_data_export_pdf", "File not found :path", array(":path" => $is_style_sheet));
        watchdog("views_data_export_pdf", "File not found :path", [":path" => $is_style_sheet]);
      }
    }

    $output .= theme($this->theme_functions($this->definition['additional themes base'] . '_header'), array(
    $output .= theme($this->theme_functions($this->definition['additional themes base'] . '_header'), [
      'view' => $this->view,
      'options' => $this->options,
      'rows' => $rows,
      'title' => $title,
      'head' => $head
    ));
      'head' => $head,
    ]);
    return $output;
  }

@@ -114,14 +150,14 @@ class views_data_export_pdf_plugin_style_export extends views_data_export_plugin
    $output = '';

    if (!isset($batch_sandbox['group_titles'])) {
      $batch_sandbox['group_titles'] = array();
      $batch_sandbox['group_titles'] = [];
    }

    $group_titles = (isset($batch_sandbox['group_titles'])) ? $batch_sandbox['group_titles'] : array();
    $group_titles = (isset($batch_sandbox['group_titles'])) ? $batch_sandbox['group_titles'] : [];

    foreach ($sets as $title => $records) {
      if ($this->uses_row_plugin()) {
        $rows = array();
        $rows = [];
        foreach ($records as $row_index => $row) {
          $this->view->row_index = $row_index;
          $rows[] = $this->row_plugin->render($row);
@@ -131,13 +167,13 @@ class views_data_export_pdf_plugin_style_export extends views_data_export_plugin
        $rows = $records;
      }

      $output .= theme($this->theme_functions($this->definition['additional themes base'] . '_body'), array(
      $output .= theme($this->theme_functions($this->definition['additional themes base'] . '_body'), [
        'view' => $this->view,
        'options' => $this->options,
        'rows' => $rows,
        'title' => $title,
        'group_titles' => $group_titles
      ));
        'group_titles' => $group_titles,
      ]);

      if (!in_array($title, $batch_sandbox['group_titles'])) {
        $batch_sandbox['group_titles'][] = $title;
+1 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@

/**
 * @file
 * Theme export DPF body.
 * Theme export PDF body.
 */
?>

+2 −3
Original line number Diff line number Diff line
@@ -2,10 +2,9 @@

/**
 * @file
 * Theme export DPF footer.
 * Theme export PDF footer.
 */
?>
      </tbody>
    </table>

  </body>
</html>
Loading