Project

General

Profile

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

    
4

    
5
/*
6
 * Copyright (C) 2007 EDIT
7
 * European Distributed Institute of Taxonomy
8
 * http://www.e-taxonomy.eu
9
 *
10
 */
11

    
12
/**
13
 function _init_vocabulary_tids(){
14
 //FIXME: execute this during module installation
15
 //FIXME: check for  variable_get('expertsdb_vocabs') && tids are valid for system status
16
 $expertsdb_vocabs = array(
17
 'expertdb_taxomony' =>	12,
18
 'expertdb_georegions' => 13,
19
 'expertdb_environment' => 10,
20
 'expertdb_activity' =>	6,
21
 'expertdb_methods' => 5,
22
 );
23

    
24
 taxonomy_get_vocabulary()
25

    
26
 variable_set('expertsdb_vocabs', $expertsdb_vocabs);
27
 }
28
 */
29

    
30

    
31

    
32
/**
33
 * Template for BLOCK of view 'taxonomic_interest_by_uid'
34
 *
35
 * @param unknown_type $view
36
 * @param unknown_type $nodes
37
 */
38
function phptemplate_views_view_table_interest_by_uid($view, $nodes){
39

    
40
	// allow creation of interests only on own profile page
41
	if((user_access('edit own expertsdb_interest content') && _taxon_experts_user_is_owner()) || user_access('edit expertsdb_interest content')){
42
		$add_op_link = l(t('Add Interest'),'node/add/expertsdb_interest', null, drupal_get_destination().'&field_parent_person='._taxon_experts_get_profile_nid('expertsdb_person'));
43
	}
44

    
45
	$operations = array('view');
46
	if((user_access('edit own expertsdb_interest content') && _taxon_experts_user_is_owner()) || user_access('edit expertsdb_interest content')){
47
		$operations[] = t('edit');
48
		$operations[] = t('delete');
49
	}
50

    
51
	return theme('views_view_optable', $view, $nodes, 'table', $add_op_link, $operations);
52
}
53

    
54

    
55
//projects_by_interest
56
function phptemplate_views_view_table_projects_by_interest($view, $nodes){
57

    
58
	// allow creation of projects only on own profile page
59
	if((user_access('edit own expertsdb_project content') && _taxon_experts_user_is_owner()) || user_access('edit expertsdb_project content')){
60
		$add_op_link = l(t('Add Project'),'node/60/edit', null, drupal_get_destination().'#field_taxon_project');
61
	}
62

    
63
	$operations = array('view');
64
	if((user_access('edit own expertsdb_project content') && _taxon_experts_user_is_owner()) || user_access('edit expertsdb_project content')){
65
		$operations[] = t('edit');
66
		$operations[] = t('delete');
67
	}
68

    
69
	return theme('views_view_optable', $view, $nodes, 'table', $add_op_link, $operations);
70

    
71
}
72

    
73
/**
74
 * Template for BLOCK of view 'institutional_memberships_by_uid'
75
 *
76
 * @param unknown_type $view
77
 * @param unknown_type $nodes
78
 */
79
function phptemplate_views_view_table_institutional_memberships_by_uid($view, $nodes){
80

    
81
	// allow creation of memberships only on own profile page
82
	if((user_access('edit own expertsdb_instmembership content') && _taxon_experts_user_is_owner()) || user_access('edit expertsdb_instmembership content')){
83
		$add_op_link = l(t('Add Institutional Membership'),'node/add/expertsdb-instmembership', null, drupal_get_destination().'&field_parent_member='._taxon_experts_get_profile_nid('expertsdb_person'));
84
	}
85

    
86
	$operations = array('view');
87
	if((user_access('edit own expertsdb_instmembership content') && _taxon_experts_user_is_owner()) || user_access('edit expertsdb_instmembership content')){
88
		$operations[] = t('edit');
89
		$operations[] = t('delete');
90
	}
91

    
92
	return theme('views_view_optable', $view, $nodes, 'table', $add_op_link, $operations);
93
}
94

    
95
/**
96
 * Template for BLOCK of view 'members_by_institute'
97
 *
98
 * @param unknown_type $view
99
 * @param unknown_type $nodes
100
 */
101
function phptemplate_views_view_table_members_by_institute($view, $nodes){
102

    
103
	return theme('views_view_optable', $view, $nodes, 'table', NULL, NULL);
104
}
105

    
106
/*
107
 * Theme function for the nodeprofile display as teaser
108
 */
109
function phptemplate_nodeprofile_display_teaser(&$element) {
110

    
111
	if ($node = nodeprofile_load($element['#content_type'], $element['#uid'])) {
112

    
113
		// pull in the stylesheet
114
		drupal_add_css(drupal_get_path('module', 'taxon_experts') .'/taxon_experts_view.css');
115
  			  		
116
		switch($element['#content_type']){
117

    
118
			case 'expertsdb_person':
119
				// render profile node as FULL nodes, not as teaser
120
				$node = node_build_content($node, FALSE, FALSE);
121
				
122
				// render edit link
123
				$output .=  _taxon_experts_menu_custom($node->nid, $element['#uid']);
124
			
125
				$output .= '<div class="nodeprofile-person">';
126
				//$output = '<h2 class="person">'.l($node->title, 'node/'.$node->nid).'&nbsp;<span class="operations">['. l('edit', 'node/'.$node->nid.'/edit', null, drupal_get_destination()).']</span></h2>';
127
				//$output = '<h2 class="person">'.l($node->title, 'node/'.$node->nid).'</h2>';
128
				$output .= '<h2 class="title">' . l($node->title, 'user/'.$node->uid);
129

    
130
				// append name aliases
131
				if(!empty($node->field_name_aliases[0])){
132
					$output .= ' <span class="name-aliases">' . $node->field_name_aliases[0]['view'] . '</span>';
133
				}
134

    
135
				$output .= '</h2>'; // end of h2.title
136

    
137
				$output .= '<div class="nodeprofile-dates">';
138

    
139
				// display lifespan
140
				if( $node->field_lifespan && !empty($node->field_lifespan[0]['timespan_from']) && !(isset($node->field_lifespan['#access']) && $node->field_lifespan['#access']=== false) ){
141
					$output .= $node->field_lifespan[0]['view'];
142
				}
143

    
144
				// display retirement year
145
				if($node->field_retirement_year && !empty($node->field_retirement_year[0]['retirement_year']) && !empty($node->field_retirement_year[0]['view']) && !(isset($node->field_retirement_year['#access']) && $node->field_retirement_year['#access'] === false) ) {
146
					// Change widget label, if retirement year is in the past (Person already retired)
147
					$label = ($node->field_retirement_year[0]['retirement_year'] < date('Y')) ? t('Year of Retirement:') : t('Foreseen Year of Retirement:');
148
					$output .= '<div class="field-retirement-year"><span class="label">' . $label . '</span>&nbsp;'.$node->field_retirement_year[0]['view'].'</div>'.chr(10);
149
				}
150

    
151
				$output .= '</div>'; // end of div.dates
152

    
153
				// render complete contact from nodeprofile
154
				$output .= drupal_render($node->content['group_contact']);
155

    
156
				$output .= '</div>'; // end of div.person
157

    
158
				// clear block
159
				$output .= '<div class="clear-float"> </div>';
160

    
161
				// configure views
162
				$views = array(
163
        	'institutional_memberships_by_uid' => array(
164
        		'title' => t('Institutional Memberships')
165
				),
166
        	'interest_by_uid' => array(
167
        		'title' => t('Taxonomic Interests'),
168
				),
169
				);
170

    
171
				foreach($views as $view_name => $view_settings){
172
					$view = views_get_view($view_name);
173
					if(views_access($view)){
174
						// get view data
175
						$view_data = views_build_view('block', $view, array($node->nid));
176
						if(!$view_data){
177
							// provide an empty table, if there is no data
178
							$view_data = theme('views_view_table_' . $view_name, $view, array());
179
						}
180
						$output .= '<h3 class="title">' . $view_settings['title'] . '</h3>';
181
						$output .= '<div class="nodeprofile-display">';
182
						$output .= $view_data;
183
						$output .= '</div>';
184
					}
185
				}
186

    
187
				// clear block
188
				$output .= '<div class="clear-float"> </div>';
189

    
190
				return $output;
191

    
192

    
193
			default:
194
				// copied from theme_nodeprofile_display_teaser
195
				if (node_access('view', $node)) {
196
					$element['#node'] = $node;
197
					return theme('nodeprofile_display_box', $element, node_view($node, TRUE, TRUE, FALSE).$content_addon);
198
				}
199
				//# end default
200
		}//# end switch
201
	}
202
}
203

    
204

    
205
/**
206
 * Theme a user page
207
 * @param $account the user object
208
 * @param $fields a multidimensional array for the fields, in the form of array (
209
 *   'category1' => array(item_array1, item_array2), 'category2' => array(item_array3,
210
 *    .. etc.). Item arrays are formatted as array(array('title' => 'item title',
211
 * 'value' => 'item value', 'class' => 'class-name'), ... etc.). Module names are incorporated
212
 * into the CSS class.
213
 */
214
function phptemplate_user_profile($account, $fields) {
215
	$output = '<div class="profile">';
216
	$output .= theme('user_picture', $account);
217

    
218
	foreach ($fields as $category => $items) {
219
		switch ($category){
220
			case 'Person':
221
				$output .= $items['expertsdb_person']['value'];
222
				break;
223
			default:
224
				if (strlen($category) > 0) {
225
					$output .= '<h3 class="title">'.$category .'</h3>';
226
				}
227
				$output .= '<dl>';
228
				foreach ($items as $item) {
229
					if (isset($item['title'])) {
230
						$output .= '<dt class="'. $item['class'] .'">'. $item['title'] .'</dt>';
231
					}
232
					$output .= '<dd class="'. $item['class'] .'">'. $item['value'] .'</dd>';
233
				}
234
				$output .= '</dl>';
235
		}
236
	}
237
	$output .= '</div>';
238

    
239
	return $output;
240
}
241

    
242

    
243
/*function phptemplate_date_display_combination($field, $dates, $node = NULL) {
244
 switch ($field['field_name']){
245
 case 'field_lifespan': //field_retirement_year
246
 return theme_date_lifespan($field, $dates, $node);
247

    
248
 default:
249
 return theme_date_display_combination($field, $dates, $node);
250
 }
251
 }*/
252

    
253
/*
254
 * Theming function to override the field_handler for Views Fusion node titles
255
 *
256
 * Attention: vX depends on the fused view. Set Breakpoint in views.module, line 1268
257
 *
258
 */
259
function phptemplate_views_handle_field_v4node_title($fields, $field, $data){
260
	switch($field['label']){
261
		case "Person":
262
			$field['handler'] = 'taxon_experts_handler_user_link';
263
			return theme_views_handle_field($fields, $field, $data);
264

    
265
		default:
266
			return theme_views_handle_field($fields, $field, $data);
267
	}
268
}
269

    
270
/*
271
 * handler for node title link in search_person view
272
 */
273
function phptemplate_views_handle_field_search_person_node_title($fields, $field, $data){
274
	$field['handler'] = 'taxon_experts_handler_user_link';
275
	return theme_views_handle_field($fields, $field, $data);
276
}
277

    
278
/*
279
 * handler for parent_member field
280
 */
281
function phptemplate_views_handle_field_node_data_field_parent_member_field_parent_member_nid($fields, $field, $data){
282
	$field['handler'] = 'taxon_experts_handler_expert_link';
283
	return theme_views_handle_field($fields, $field, $data, $value);
284
}
285

    
286
/*
287
 * handler for parent_person field
288
 */
289
function phptemplate_views_handle_field_node_data_field_parent_person_field_parent_person_nid($fields, $field, $data){
290
	$field['handler'] = 'taxon_experts_handler_expert_link';
291
	return theme_views_handle_field($fields, $field, $data, $value);
292
}
293

    
294
/*
295
 * handle node id fields; in search_interests this is the interest itself
296
 */
297
function phptemplate_views_handle_field_node_nid($fields, $field, $data){
298
	$field['handler'] = 'taxon_experts_handler_user_interest_link';
299
	return theme_views_handle_field($fields, $field, $data, $value);
300
}
301

    
302
/*
303
 * handler for person link in institution_by_ref view
304
 */
305
function phptemplate_views_handle_field_parent_member_field_parent_member_nid($fields, $field, $data){
306
	$field['handler'] = 'taxon_experts_handler_user_link';
307
	return theme_views_handle_field($fields, $field, $data);
308
}
309

    
310

    
311
/*
312
 * function to format serialized expertsdb_timespan fields for field_membership_period
313
 *
314
 */
315
function phptemplate_views_handle_field_node_data_field_membership_period_field_membership_period_expertsdb_timespan($fields, $field, $data){
316
	$field['handler'] = 'expertsdb_timespan_handler_view';
317
	return theme_views_handle_field($fields, $field, $data);
318
}
319

    
320
/*
321
 * function to format serialized expertsdb_timespan fields for field_lifespan
322
 *
323
 */
324
function phptemplate_views_handle_field_node_data_field_lifespan_field_lifespan_expertsdb_timespan($fields, $field, $data){
325
	$field['handler'] = 'expertsdb_timespan_handler_view';
326
	return theme_views_handle_field($fields, $field, $data);
327
}
328

    
329
function phptemplate_views_filters($form) {
330
	switch($form['#view_name']){
331

    
332
		case 'search_interest':
333
			// pull in the style sheet
334
			drupal_add_css(drupal_get_path('module', 'taxon_experts') .'/taxon_experts_search_interests.css');
335

    
336
			// set order of exposed filter bei label, as the field names may be different
337
			// Filter labels may be different as well, so filter labels must be consistent with labels in the view,
338
			// but maintainig filter labels consitent seems to be much easier than maintaining field names
339
			$num_cols = 1;
340
			$filter_order = array(
341
				'Person' => 0,
342
    			'Field of Taxonomic Expertise' => 1,
343
    			'Geografical Range' => 2,
344
    			'Environment' => 4,
345
    			'Activity' => 5,
346
    			'Methodology' => 6,
347
			);
348

    
349
			// provide filter descriptions for each filter
350
			$filter_descripton = array(
351
				'Person' => '',
352
    			'Field of Taxonomic Expertise' => t('To <strong>select items</strong>, click the items in the <em>left box</em>. To <strong>deselect items</strong>, click the items in the <em>right box</em>.'),
353
    			'Geografical Range' => t('To <strong>select items</strong>, click the items in the <em>left box</em>. To <strong>deselect items</strong>, click the items in the <em>right box</em>.'),
354
    			'Environment' => t('Hold <strong>Ctrl</strong> or <strong>Strg</strong> to select multiple items or deselect items.'),
355
    			'Activity' => t('Hold <strong>Ctrl</strong> or <strong>Strg</strong> to select multiple items or deselect items.'),
356
    			'Methodology' => t('Hold <strong>Ctrl</strong> or <strong>Strg</strong> to select multiple items or deselect items.'),
357
			);
358

    
359
			$view = $form['view']['#value'];
360
			// build the filter layout
361
			foreach($view->exposed_filter as $delta => $filter){
362
				/*
363
				 * Hide filter options on taxonomy and georegions
364
				 *
365
				 */
366

    
367
				if($filter['label'] == 'Field of Taxonomic Expertise' || $filter['label'] == 'Geografical Range'){
368
					$form["op$delta"]['#type'] = 'hidden';
369
					$form["op$delta"]['#default_value'] = 'AND';
370
				}
371
				/* Tweak the filter options in the Person filter
372
				 *
373
				 * @TODO: Verify, that this way of theming the filter options is appropriate;
374
				 * There *might* be another way of theming the selection
375
				 */
376
				if($filter['label'] == 'Person'){
377
					$allowed_filters = array('contains','not');
378
					if($form["op$delta"] && $form["op$delta"]['#options']){
379
						foreach($form["op$delta"]['#options'] as $key => $text){
380
							if(!in_array($key,$allowed_filters)) unset ($form["op$delta"]['#options'][$key]);
381
						}
382
					}
383

    
384
					/*
385
					 * Bugfix:
386
					 * Due to an unknown reason, the default value from the person filter ($form["filter$delta"]['#value'])
387
					 * is set to an empty array instead of an empty string - which is very annoying.
388
					 * This is a workaround
389
					 *
390
					 * @TODO: remove the next lines and track down the bug
391
					 */
392
					if (is_array($form["filter$delta"]['#value']) && count($form["filter$delta"]['#value']) == 0){
393
						$form["filter$delta"]['#value'] = '';
394
					}
395

    
396
				}
397

    
398
				/*
399
				 * Build collapsible fieldsets for all filters
400
				 */
401

    
402
				if($_GET['filter'.$delta]){
403
					$used_filter = ' (active)';
404
					$state = '';
405
				}
406
				else{
407
					$used_filter = '';
408
					$state = ' collapsed';
409
				}
410

    
411
				$form['op'.$delta]['#weight'] = $filter_order[$filter['label']]*10;
412
				$form['op'.$delta]['#prefix'] = '<fieldset class="collapsible' . $state . '"><legend>Filter ' . $filter['label'] . $used_filter . '</legend>';
413
				$form['op'.$delta]['#prefix'] .= '<p>' .  $filter_descripton[$filter['label']] . '</p>';
414
				$form['filter'.$delta]['#weight'] = $filter_order[$filter['label']]*10+1;
415
				$form['filter'.$delta]['#suffix'] = '</fieldset>';
416

    
417
			}
418

    
419
			// add the new submit button
420
			$form['submit'] = array(
421
    		'#type' => 'views_imagebutton',
422
				'#name' => 'submit',
423
				'#title' => t('Click to filter results'),
424
    			'#image' => drupal_get_path('module','cdm_taxontree') . '/images/filter_results_button.png',  // provide the path to your image here
425
    			'#default_value' => t('Submit'), // original value of button text
426
				'#weight' => count($view->exposed_filter)*10+2,
427
				'#id' => 'submit_filters'
428
			);
429

    
430
			$form['reset'] = array(
431
    		'#type' => 'resetbutton',
432
				'#name' => 'reset',
433
				'#title' => t('Click to reset all filters'),
434
    			'#image' => drupal_get_path('module','cdm_taxontree') . '/images/reset_filters_button.png',  // provide the path to your image here
435
    			'#default_value' => t('Reset'), // original value of button text
436
				'#weight' => count($view->exposed_filter)*10+3,
437
				'#url' => $view->url,
438
			);
439

    
440
			// add the collapse script
441
			drupal_add_js('misc/collapse.js');
442

    
443
			return drupal_render($form);
444

    
445

    
446
		case 'search_person':
447
			$view = $form['view']['#value'];
448
			foreach($view->exposed_filter as $delta => $filter){
449

    
450
				/* Tweak the filter options in the Person filter
451
				 *
452
				 * @TODO: Verify, that this way of theming the filter options is appropriate;
453
				 * There *might* be another way of theming the selection
454
				 */
455
				if($filter['label'] == 'Person'){
456
					$allowed_filters = array('contains','not');
457
					if($form["op$delta"] && $form["op$delta"]['#options']){
458
						foreach($form["op$delta"]['#options'] as $key => $text){
459
							if(!in_array($key,$allowed_filters)) unset ($form["op$delta"]['#options'][$key]);
460
						}
461
					}
462
				}
463
			}
464

    
465
			foreach ($view->exposed_filter as $count => $expose) {
466
				$layout = $filter_layout[$expose['field']];
467
				$rows[$layout['row']][] = '<div class="field-label">'.$expose['label'].'</div>'.drupal_render($form["op$count"]) . drupal_render($form["filter$count"]);
468
			}
469

    
470
			$form['submit'] = array(
471
    		'#type' => 'views_imagebutton',
472
				'#name' => 'submit',
473
				'#title' => t('Click to filter results'),
474
    			'#image' => drupal_get_path('module','cdm_taxontree') . '/images/filter_results_button.png',  // provide the path to your image here
475
    			'#default_value' => t('Submit'), // original value of button text
476
			);
477

    
478
			$rows[count($rows)][] = array(
479
				'data' => drupal_render($form['submit']),
480
				'colspan' => $num_cols,
481
				'class' => 'row-submit',
482
			);
483
			$label[] = ''; // so the column count is the same.
484
			return theme('table', null, $rows) . drupal_render($form);
485
			break;
486

    
487
		default:
488
			return theme_views_filters($form);
489
	}
490
}
491

    
492
function phptemplate_field(&$node, &$field, &$items, $teaser, $page) {
493
	$field_empty = TRUE;
494
	foreach ($items as $delta => $item) {
495
		if (!empty($item['view']) || $item['view'] === "0") {
496
			$field_empty = FALSE;
497
			break;
498
		}
499
	}
500

    
501
	$variables = array(
502
    'node' => $node,
503
    'field' => $field,
504
    'field_type' => $field['type'],
505
    'field_name' => $field['field_name'],
506
    'field_type_css' => strtr($field['type'], '_', '-'),
507
    'field_name_css' => strtr($field['field_name'], '_', '-'),
508
    'label' => t($field['widget']['label']),
509
    'label_display' => isset($field['display_settings']['label']['format']) ? $field['display_settings']['label']['format'] : 'above',
510
    'field_empty' => $field_empty,
511
    'items' => $items,
512
    'teaser' => $teaser,
513
    'page' => $page,
514
	);
515

    
516
	return _phptemplate_callback('field', $variables, array('field-'. $field['field_name']));
517
}
518

    
519

    
520
/**
521
 * Custom form element create an image based reset button (which is actually a link)
522
 */
523
function resetbutton_elements() {
524
  $type['resetbutton'] = array('#input' => TRUE, '#button_type' => 'reset',);
525
  return $type;
526
}
527

    
528
function theme_resetbutton($element) {
529
  return '<a href="' .url($element['#url']) . '" title="' . $element['#title'] . '"><img src="' . $element['#image'] . '" name="'. $element['#name'] .'" alt="' . $element['#title'] . '" ' . drupal_attributes($element['#attributes']) .' /></a>';
530
}
531

    
532
function resetbutton_value() {
533
  // null function guarantees default_value doesn't get moved to #value.
534
}
535

    
(9-9/9)