Projet

Général

Profil

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

root / drupal7 / sites / all / modules / views / handlers / views_handler_area_result.inc @ 651307cd

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of views_handler_area_result.
6
 */
7

    
8
/**
9
 * Views area handler to display some configurable result summary.
10
 *
11
 * @ingroup views_area_handlers
12
 */
13
class views_handler_area_result extends views_handler_area {
14

    
15
  function option_definition() {
16
    $options = parent::option_definition();
17

    
18
    $options['content'] = array(
19
      'default' => 'Displaying @start - @end of @total',
20
      'translatable' => TRUE,
21
    );
22

    
23
    return $options;
24
  }
25

    
26
  function options_form(&$form, &$form_state) {
27
    parent::options_form($form, $form_state);
28
    $variables = array(
29
      'items' => array(
30
        '@start -- the initial record number in the set',
31
        '@end -- the last record number in the set',
32
        '@total -- the total records in the set',
33
        '@name -- the human-readable name of the view',
34
        '@per_page -- the number of items per page',
35
        '@current_page -- the current page number',
36
        '@current_record_count -- the current page record count',
37
        '@page_count -- the total page count',
38
      ),
39
    );
40
    $list = theme('item_list', $variables);
41
    $form['content'] = array(
42
      '#title' => t('Display'),
43
      '#type' => 'textarea',
44
      '#rows' => 3,
45
      '#default_value' => $this->options['content'],
46
      '#description' => t('You may use HTML code in this field. The following tokens are supported:') . $list,
47
    );
48
  }
49

    
50

    
51
  /**
52
   * Find out the information to render.
53
   */
54
  function render($empty = FALSE) {
55
    // Must have options and does not work on summaries.
56
    if (!isset($this->options['content']) || $this->view->plugin_name == 'default_summary') {
57
      return;
58
    }
59
    $output = '';
60
    $format = $this->options['content'];
61
    // Calculate the page totals.
62
    $current_page = (int) $this->view->get_current_page() + 1;
63
    $per_page = (int) $this->view->get_items_per_page();
64
    // @TODO: Maybe use a possible is views empty functionality.
65
    // Not every view has total_rows set, use view->result instead.
66
    $total = isset($this->view->total_rows) ? $this->view->total_rows : count($this->view->result);
67
    $name = check_plain($this->view->human_name);
68
    if ($per_page === 0) {
69
      $page_count = 1;
70
      $start = 1;
71
      $end = $total;
72
    }
73
    else {
74
      $page_count = (int) ceil($total / $per_page);
75
      $total_count = $current_page * $per_page;
76
      if ($total_count > $total) {
77
        $total_count = $total;
78
      }
79
      $start = ($current_page - 1) * $per_page + 1;
80
      $end = $total_count;
81
    }
82
    $current_record_count = ($end - $start) + 1;
83
    // Get the search information.
84
    $items = array('start', 'end', 'total', 'name', 'per_page', 'current_page', 'current_record_count', 'page_count');
85
    $replacements = array();
86
    foreach ($items as $item) {
87
      $replacements["@$item"] = ${$item};
88
    }
89
    // Send the output.
90
    if (!empty($total)) {
91
      $output .= filter_xss_admin(str_replace(array_keys($replacements), array_values($replacements), $format));
92
    }
93
    return $output;
94
  }
95
}