Tripal v1.0 (6.x-1.0)
|
00001 <?php 00002 00011 class chado_views_handler_field extends views_handler_field { 00012 00013 function init(&$view, $options) { 00014 include_once('chado_wrapper_functions.inc'); 00015 parent::init($view, $options); 00016 } 00017 00021 function option_definition() { 00022 $options = parent::option_definition(); 00023 00024 $options['type'] = array('default' => 'separator'); 00025 $options['separator'] = array('default' => ', '); 00026 00027 return $options; 00028 } 00029 00033 function options_form(&$form, &$form_state) { 00034 parent::options_form($form, $form_state); 00035 00036 // Add a link to node checkbox 00037 // but only if this base table is linked to a node and this field is from the base_table 00038 if (tripal_core_is_tripal_node_type($this->table) && $this->table == $this->view->base_table) { 00039 // If there is a Node: NID field then show a link to node checkbox 00040 if (isset($this->view->display['default']->display_options['fields']['nid'])) { 00041 $form['link_to_node'] = array( 00042 '#type' => 'checkbox', 00043 '#title' => t('Link to Node'), 00044 '#description' => t('If a given row is associated with a drupal node then ' 00045 .'this field will appear as a link, linking the user to that node. Otherwise,' 00046 .' no link will be displayed.'), 00047 '#default_value' => $this->options['link_to_node'], 00048 ); 00049 } 00050 // Otherwise inform the user that they need to add a Node:Nid field 00051 // to get this functionality 00052 else { 00053 $form['link_to_node'] = array( 00054 '#type' => 'item', 00055 '#value' => "This field has the ability to link to it's corresponding node. " 00056 . "However, you first need to add the NID field associated with the node. " 00057 . "Simple set the NID field to hidden when adding it to ensure it's not " 00058 . "shown in the resulting view." 00059 ); 00060 } 00061 } 00062 00063 $form['type'] = array( 00064 '#type' => 'radios', 00065 '#title' => t('Display type'), 00066 '#options' => array( 00067 'ul' => t('Unordered list'), 00068 'ol' => t('Ordered list'), 00069 'separator' => t('Simple separator'), 00070 ), 00071 '#default_value' => $this->options['type'], 00072 ); 00073 00074 $form['separator'] = array( 00075 '#type' => 'textfield', 00076 '#title' => t('Separator'), 00077 '#default_value' => $this->options['separator'], 00078 '#process' => array('views_process_dependency'), 00079 '#dependency' => array('radio:options[type]' => array('separator')), 00080 ); 00081 } 00082 00087 function query() { 00088 parent::query(); 00089 $this->aggregated = chado_wrapper_is_aggregated_by_join($this); 00090 } 00091 00095 function pre_render(&$values) { 00096 00097 // further check the results to see if this field is a postgresql array 00098 $this->aggregated = chado_wrapper_is_aggregated_by_result($this, $values); 00099 00100 // Split Aggregated Results 00101 chado_wrapper_split_array_agg_results($this, $values); 00102 00103 } 00104 00114 function render($values) { 00115 if ($this->options['link_to_node']) { 00116 $link_text = chado_wrapper_render_items($this, $values); 00117 return $this->render_node_link($link_text, $values); 00118 } 00119 else { 00120 return chado_wrapper_render_items($this, $values); 00121 } 00122 } 00123 00133 function render_node_link($link_text, $values) { 00134 00135 $node_field = $this->view->field['nid']; 00136 $nid = $values->{$node_field->aliases['nid']}; 00137 00138 if ($nid) { 00139 return l($link_text, 'node/' . $nid); 00140 } 00141 else { 00142 return $link_text; 00143 } 00144 } 00145 00146 function parent_render($val) { 00147 return parent::render($val); 00148 } 00149 00150 }