• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

handlers/views_handler_area_result.inc

Go to the documentation of this file.
00001 <?php
00002 
00013 class views_handler_area_result extends views_handler_area {
00014 
00015   function option_definition() {
00016     $options = parent::option_definition();
00017 
00018     $options['content'] = array(
00019       'default' => 'Displaying @start - @end of @total',
00020       'translatable' => TRUE,
00021     );
00022 
00023     return $options;
00024   }
00025 
00026   function options_form(&$form, &$form_state) {
00027     parent::options_form($form, $form_state);
00028     $variables = array(
00029       'items' => array(
00030         '@start -- the initial record number in the set',
00031         '@end -- the last record number in the set',
00032         '@total -- the total records in the set',
00033         '@name -- the human-readable name of the view',
00034         '@per_page -- the number of items per page',
00035         '@current_page -- the current page number',
00036         '@page_count -- the total page count',
00037       ),
00038     );
00039     $list = theme('item_list', $variables);
00040     $form['content'] = array(
00041       '#title' => t('Display'),
00042       '#type' => 'textarea',
00043       '#rows' => 3,
00044       '#default_value' => $this->options['content'],
00045       '#description' => t('You may use HTML code in this field. The following tokens are supported:') . $list,
00046     );
00047   }
00048 
00049 
00053   function render($empty = FALSE) {
00054     // Must have options and does not work on summaries.
00055     if (!isset($this->options['content']) || $this->view->plugin_name == 'default_summary') {
00056       return;
00057     }
00058     $output = '';
00059     $format = $this->options['content'];
00060     // Calculate the page totals.
00061     $current_page = (int) $this->view->get_current_page() + 1;
00062     $per_page = (int) $this->view->get_items_per_page();
00063     $count = count($this->view->result);
00064     $total = $this->view->total_rows;
00065     $name = check_plain($this->view->human_name);
00066     if ($per_page === 0) {
00067       $page_count = 1;
00068       $start = 1;
00069       $end = $total;
00070     }
00071     else {
00072       $page_count = (int) ceil($total / $per_page);
00073       $total_count = $current_page * $per_page;
00074       if ($total_count > $total) {
00075         $total_count = $total;
00076       }
00077       $start = ($current_page - 1) * $per_page + 1;
00078       $end = $total_count;
00079     }
00080     // Get the search information.
00081     $items = array('start', 'end', 'total', 'name', 'per_page', 'current_page', 'page_count');
00082     $replacements = array();
00083     foreach ($items as $item) {
00084       $replacements["@$item"] = ${$item};
00085     }
00086     // Send the output.
00087     if (!empty($total)) {
00088       $output .= filter_xss_admin(str_replace(array_keys($replacements), array_values($replacements), $format));
00089     }
00090     return $output;
00091   }
00092 }
00093 

Generated on Sun Feb 26 2012 12:52:51 for Views by  doxygen 1.7.1