Project

General

Profile

Download (7.62 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
// $Id$
3

    
4
// include the module specific template extention for this module
5
require_once('template.taxon_experts.php');
6

    
7
/**
8
 * @file
9
 * A online information service on  taxonomic experts, their expertise
10
 * and ongoing and planned taxonomic research projects.
11
 * This module is brought to you by the European Distributed Institute of Taxonomy - EDIT
12
 *
13
 * @author Berlin, BGBM, Andreas Kohlbecker 2007 - http://www.bgbm.org/BioDivInf/default.htm
14
 */
15

    
16
/**
17
 * @param $display_options: e.g.: array(
18
 *    12 => array('term_path'=> true, 'notes'=>'$node->field_taxon_notes'),
19
 *    10 => array('term_path'=> true, 'notes'=>'$node->field_geo_notes',))
20
 */
21
function theme_expertdb_interest_categories($taxonomies, $display_options = array(), $table = true){
22

    
23
  static $vocab_labels = array(
24
    'expertdb_taxomony' => 'Field of Expertise',
25
    'expertdb_georegions' => 'Geographic Region',
26
    'expertdb_environment' => 'Environment',
27
    'expertdb_activity' => 'Taxonomic Activity',
28
    'expertdb_methods' => 'Methodology',
29
  );
30

    
31

    
32
  $terms = array();
33
  foreach($taxonomies as $tid => $term){
34
    $terms[$term->vid][] = $term;
35
  }
36
  if($table){
37
    $rows = array();
38
    foreach($terms as $vid => $term_items){
39
      $vocab = taxonomy_get_vocabulary($vid);
40

    
41
      $header_cell = array('data'=>t($vocab_labels[$vocab->name]).':', 'header'=>true, 'class'=>'category');
42
      $terms_cell = array('data'=>'', 'class'=>'term');
43
      
44
      $show_term_path = isset($display_options[$vid]['term_path']);
45
      
46
      foreach($term_items as $t){
47
        // calculate path from root term to $t if desired                
48
        if($show_term_path){
49
          $p_terms = taxonomy_get_parents_all($t->tid);
50
        } else {
51
          $p_terms = array($t);
52
        }
53
        $term_path = '';
54
        while($item = array_pop($p_terms)){
55
          $term_path .= $item->name.(count($p_terms) ? ' -&gt; ':'');
56
        }
57
        // create table cell
58
        $terms_cell['data'] .= '<span class="term" title="'.$t->description.'">'.$term_path.'</span>';
59
      }
60
      // append notes
61
      if($display_options[$vid]['notes']){
62
        $terms_cell['data'] .= '<span class="notes">'.$display_options[$vid]['notes'].'</span>'; 
63
      }
64
      
65
      $rows[] = array($header_cell, $terms_cell);
66
    }
67
    return theme('table', null, $rows, array('class'=>'interest_data'));
68

    
69
  } else {
70
    $output = '';
71
    foreach($terms as $vid => $term_items){
72
      $vocab = taxonomy_get_vocabulary($vid);
73
      $output .= '<div class="field taxonomy">';
74
      $output .= '<div class="field-label field-label-category">'.t($vocab_labels[$vocab->name]).'</div>';
75
      $output .= '<div class="field-items field-items-terms">';
76
      foreach($term_items as $t){
77
        $output .= '<span class="field-item field-item-term" title="'.$t->description.'">'.$t->name.'</span>';
78
      }
79
      $output .= '</div></div>';
80
    }
81
    return $output;
82
  }
83
}
84

    
85

    
86

    
87
/**
88
 * Display the nodes of a view as a table and add an edit & delete links to each row.
89
 * An additional add link will be added as last row to the table.
90
 * see theme_views_view_list for a definition of $type
91
 */
92
function theme_views_view_optable($view, $nodes, $type, $add_op_link = null, $operations = array()) {
93

    
94
  $rows[] = array();
95
  $fields = _views_get_fields();
96
  foreach ($nodes as $node) {
97
    $row = array();
98
    foreach ($view->field as $field) {
99
      $cell['data'] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
100
      $cell['class'] = "view-field view-field-$field[queryname]";
101
      $row[] = $cell;
102
    }
103
    if( count($operations) || $add_op_link ){
104
      // add links for the edit & delete operations
105
      $cell['data'] = '';
106
      if(in_array('view', $operations)){
107
        $cell['data'] .= l(t('View'), "node/$node->nid").'&nbsp;';
108
      }
109
      if(in_array('edit', $operations)){
110
        $cell['data'] .= l(t('Edit'), "node/$node->nid/edit", null, drupal_get_destination()).'&nbsp;';
111
      }
112
      if(in_array('delete', $operations)){
113
        $cell['data'] .= l(t('Delete'), "node/$node->nid/delete", null, drupal_get_destination());
114
      }
115
      $cell['class'] = "view-field view-field-operations";
116
      $row[] = $cell;  
117
    }
118
    $rows[] = $row;
119
  }
120

    
121
  if($add_op_link){
122
    // fill empty fields
123
    $row = array();
124
    foreach ($view->field as $field) {
125
      $cell['data'] = '';
126
      $cell['class'] = "view-field view-field-empty";
127
      $row[] = $cell;
128
    }
129
    // append add link as last cell
130
    $cell['data'] = $add_op_link;
131
    $cell['class'] = "view-field view-field-operations";
132
    $row[] = $cell;
133

    
134
    $rows[] = $row;
135
  }
136

    
137
  $header = $view->table_header;
138
  if(count($operations)){
139
    $header[] = array('data'=>t('Operations'));    
140
  }
141

    
142
  return theme('table', $header, $rows);
143
}
144

    
145

    
146
function theme_date_lifespan($field, $dates, $node = NULL) {
147
    
148
      $date1 = $dates['value']['formatted'];
149
      $date2 = $dates['value2']['formatted'];
150
      if (empty($date1) && empty($date2)) {
151
        return '';
152
      }
153
      elseif ($date1 == $date2 || empty($date2)) {
154
        return '<div class="date_lifespan">*<span class="date-display-single">'. $date1 .'</span></div>';
155
      }
156
      else {
157
        return '<div class="date_lifespan">*<span class="date-display-single">'. $date1 .'</span>'
158
        .'<span class="date-display-separator"> - </span>'
159
        .'&dagger;<span class="date-display-end">'. $date2 .'</span></div>';
160
      }
161
}
162

    
163

    
164
/**
165
 * Enter description here...
166
 *
167
 * @param unknown_type $rows
168
 * @param unknown_type $cell array e.g:
169
 * 			$cell = array( 
170
 *               'empty' =>  array( 
171
 * 					'data'  => '',
172
 * 					'class' => 'view-field view-field-operations'),
173
 *               'addcell' =>  array( 
174
 * 					'data'  => $add_op_link,
175
 * 					'class' => 'view-field view-field-operations'));
176
 * 
177
 * @param integer $position in which column to put the cell in, 
178
 * 			defaults to the last cell, 
179
 * 			if $position > last column the cell will be put into the last column
180
 * 
181
 * Usage example:
182
 *     if($add_op_link){
183
      $lastrow_cells = array( 
184
                'empty' =>  array( 
185
  					'data'  => '',
186
  					'class' => 'view-field view-field-empty'),
187
                'addcell' =>  array( 
188
  					'data'  => $add_op_link,
189
  					'class' => 'view-field view-field-operations')
190
      );
191
      _add_as_last_row($rows, $lastrow_cells);
192
    }
193
 */
194
function _add_as_last_row(&$rows, $cells, $position = false){
195
  
196
    $row = array();
197
    foreach ($rows[0] as $idx => $field) {
198
        $row[] = $cell['empty'];
199
    }
200
    
201
    if($position){
202
      // put cell in position
203
      $row[$position] = $cells['addcell'];
204
    } else {
205
      // append add link as last cell
206
      $row[count($row)-1] = $cells['addcell'];
207
    }
208
    $rows[] = $row;
209
}
210

    
211

    
212
function _autotitle_expertsdb_address(&$node){
213
  $contact_nid = $node->field_parent_contact[0]['nid'];
214
  $contact_node = node_load($contact_nid);
215
  print 'Address for '.$contact_node->title;  
216
}
217

    
218
/**
219
 * Alternative link rendering to point to the user account of the node author 
220
 * instead of ponting to the node itself
221
 * 
222
 * used for view search_person 
223
 */
224
function taxon_experts_handler_user_link($fieldinfo, $fielddata, $value, $data){
225
  if ($fielddata['options'] == 'nolink') {
226
    return check_plain($value);
227
  }
228
  $node = node_load($data->nid);
229
  return l($value, "user/$node->uid");
230
}
231

    
232

    
233
function _taxon_experts_get_profile_nid($type){
234
    if(arg(0) == 'user'){
235
      $profile_node = node_load(array('type'=>$type, 'uid'=>arg(1)));
236
      return $profile_node->nid;
237
    } else {
238
      return arg(1);
239
    }
240
}
241

    
242

    
(5-5/6)