| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 <?php 2 // $Id: content_handler_sort.inc,v 1.1.2.6 2008/10/25 00:36:41 yched Exp $ 3 4 /** 5 * @file 6 * Handles sorts and deals properly with multiple 7 * values by allowing the views administrator to select deltas. 8 */ 9 class content_handler_sort extends views_handler_sort { 10 var $content_field; 11 12 function construct() { 13 parent::construct(); 14 15 $this->content_field = content_fields($this->definition['content_field_name']); 16 $this->additional_fields = $this->definition['additional fields']; 17 } 18 19 function option_definition() { 20 $options = parent::option_definition(); 21 $options['delta'] = array('default' => -1); 22 23 return $options; 24 } 25 26 /** 27 * Add a delta selector for multiple fields. 28 */ 29 function options_form(&$form, &$form_state) { 30 $field = $this->content_field; 31 parent::options_form($form, $form_state); 32 33 // Only add the form gadget if the field is multiple. 34 if ($field['multiple']) { 35 $max_delta = $field['multiple']; 36 // 1 means unlimited. 37 if ($max_delta == 1) { 38 $max_delta = 10; 39 } 40 41 $options = array('-1' => t('All')); 42 for ($i = 0; $i < $max_delta; $i++) { 43 $options[$i] = $i + 1; 44 } 45 $form['delta'] = array( 46 '#type' => 'select', 47 '#options' => $options, 48 '#default_value' => $this->options['delta'], 49 '#title' => t('Delta'), 50 '#description' => t('The delta allows you to select which item in a multiple value field will be used for sorting. Select "1" to use the first item, "2" for the second item, and so on. If you select "All", each item in the field will create a new row, which may appear to cause duplicates.'), 51 ); 52 } 53 } 54 55 function ensure_my_table() { 56 if (!isset($this->table_alias)) { 57 $join = $this->get_join(); 58 if (!isset($join->extra)) { 59 $join->extra = array(); 60 } 61 $delta = isset($this->options['delta']) ? $this->options['delta'] : -1; 62 if ($delta != -1) { 63 $join->extra[] = array( 64 'field' => 'delta', 65 'value' => $delta, 66 'numeric' => TRUE, 67 ); 68 } 69 70 $this->table_alias = $this->query->ensure_table($this->table, $this->relationship, $join); 71 } 72 return $this->table_alias; 73 } 74 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |