Project

General

Profile

« Previous | Next » 

Revision fbde64c6

Added by Andreas Kohlbecker over 13 years ago

#1484 & #1483 : implement footnote framework into data portal & display multiple references for distributions as footnotes in portal

View differences:

.gitattributes
61 61
modules/cdm_dataportal/cdm_taxontree/visible_implicit_small.gif -text
62 62
modules/cdm_dataportal/cdm_taxontree/visible_small.gif -text
63 63
modules/cdm_dataportal/cdm_ws_urls.txt -text
64
modules/cdm_dataportal/classes/footnote.php -text
65
modules/cdm_dataportal/classes/footnotemanager.php -text
64 66
modules/cdm_dataportal/ext_links/ext_links.info -text
65 67
modules/cdm_dataportal/ext_links/ext_links.js -text
66 68
modules/cdm_dataportal/ext_links/ext_links.module -text
......
167 169
modules/cdm_dataportal/js/cluetip/jquery.dimensions.js -text
168 170
modules/cdm_dataportal/js/cluetip/jquery.hoverIntent.js -text
169 171
modules/cdm_dataportal/js/cluetip/wait.gif -text
172
modules/cdm_dataportal/js/footnotes.js -text
170 173
modules/cdm_dataportal/js/jquery-lightbox-0.5/css/jquery.lightbox-0.5.css -text
171 174
modules/cdm_dataportal/js/jquery-lightbox-0.5/images/lightbox-blank.gif -text
172 175
modules/cdm_dataportal/js/jquery-lightbox-0.5/images/lightbox-btn-close.gif -text
modules/cdm_dataportal/cdm_dataportal.css
313 313
  text-decoration:underline;
314 314
}
315 315

  
316
.footnote{
317
	font-size: 90%;
318
}
319

  
320
.footnote-key{
321
  vertical-align: super;
322
  font-size: 80%;
323
  font-style: italic;
324
}
316 325

  
modules/cdm_dataportal/cdm_dataportal.module
13 13

  
14 14
require_once('node_types.php');
15 15
require_once('cdm_dataportal.theme.php');
16
require_once('classes/footnotemanager.php');
17
require_once('classes/footnote.php');
16 18

  
17 19
define(CDM_DATAPORTAL_SEARCH_ITEMS_ON_PAGE, 25);
18 20
define(CDM_DATAPORTAL_NOMREF_IN_TITLE, 1);
modules/cdm_dataportal/cdm_dataportal.theme.php
42 42
    ', 'inline');
43 43
}
44 44

  
45
function _add_js_footnotes(){
46
  drupal_add_js(drupal_get_path('module', 'cdm_dataportal').'/js/footnotes.js');
47
}
48

  
45 49

  
46 50
function _add_js_cluetip(){
47 51

  
......
2373 2377
				$block->module = "cdm_dataportal-feature";
2374 2378

  
2375 2379
				//get the text for the feature block
2376
				$block->content = theme('cdm_descriptionElements', $node->descriptionElements, $block->delta);
2380
				$block->content = theme('cdm_descriptionElements', $node->descriptionElements, $node->feature->uuid);
2377 2381
				// get media for the feature block
2378 2382
				$media_list = cdm_dataportal_media_from_descriptionElements($node->descriptionElements);
2379 2383
				$captionElements = array('title', 'rights');
......
2449 2453
	return $outArrayOfMedia;
2450 2454
}
2451 2455

  
2452
function theme_cdm_descriptionElements($descriptionElements){
2456
/**
2457
 * Theme a list of description elements, usually of a specific feature type
2458
 * @param $descriptionElements
2459
 * @return unknown_type
2460
 */
2461
function theme_cdm_descriptionElements($descriptionElements, $featureUuid){
2453 2462
	$outArray = array();
2454 2463
	$glue = '';
2455 2464
	$sortOutArray = false;
2456 2465
	$enclosingHtml = 'ul';
2457
	$distributionElements=array();
2466
	$distributionElements = array();
2458 2467

  
2459 2468
	foreach($descriptionElements as $descriptionElement){
2460
		//var_dump($descriptionElement);
2461
		//var_dump("</br> =============================================================================== </br>");
2462

  
2469
		
2463 2470
		if($descriptionElement->feature->uuid == UUID_DISTRIBUTION){
2464 2471
			if($descriptionElement->class == 'Distribution'){
2465
				//$repr = $descriptionElement->area->representation_L10n;
2466
				$distributionElements[]= $descriptionElement->area->representation_L10n;
2467

  
2472
				$distributionElements[]= $descriptionElement;
2468 2473
			} else if($descriptionElement->class == 'TextData'){
2469
				//$repr = $descriptionElement->multilanguageText_L10n->text;
2470 2474
				$asListElement = false;
2471
				$repr = "<t/>". theme ('cdm_descriptionElementTextData', $descriptionElement, $asListElement);
2475
				$repr = theme ('cdm_descriptionElementTextData', $descriptionElement, $asListElement);
2472 2476
					
2473 2477
				if( !array_search($repr, $outArray)){
2474 2478
					$outArray[] = $repr;
......
2480 2484
		} else if($descriptionElement->class == 'TextData'){
2481 2485
			$asListElement = true;
2482 2486
			$outArray[] = theme('cdm_descriptionElementTextData', $descriptionElement, $asListElement);
2483
		} else if($descriptionElement->class == 'media'){
2484
				
2485 2487
		} else {
2486 2488
			$outArray[] = '<li>No method for rendering unknown description class: '.$descriptionElement->classType.'</li>';
2487 2489
		}
2488 2490

  
2489 2491
	}
2490 2492

  
2491
	$outArray[] = theme(cdm_descriptionElementDistribution, $distributionElements);
2493
	$outArray[] = theme('cdm_descriptionElementDistribution', $distributionElements);
2494
	
2495
	
2492 2496
	// take the feature of the last $descriptionElement
2493 2497
	$feature = $descriptionElement->feature;
2494
	return theme('cdm_descriptionElementArray', $outArray, $feature, $glue, $sortOutArray, $enclosingHtml);
2498
	$out = theme('cdm_descriptionElementArray', $outArray, $feature, $glue, $sortOutArray, $enclosingHtml);
2499
	$out .= '<div class="footnote_list">'. FootnoteManager::renderFootnoteList($featureUuid) . '</div>';
2500
	return $out;
2495 2501
}
2496 2502

  
2497 2503
function theme_cdm_descriptionElementDistribution($descriptionElements){
2498 2504

  
2499
	$descriptions = '';
2505
	$out = '';
2506
	$separator = ', ';
2500 2507

  
2501
	foreach($descriptionElements as $description){
2502
		$descriptions .= $description . ", ";
2508
	foreach($descriptionElements as $descriptionElement){
2509
		//$footnoteKey = FootnoteManager::addNewFootnote($descriptionElement->feature->uuid, $descriptionElement->area->representation_L10n);
2510
	  $footnoteKeyList = '';
2511
		foreach($descriptionElement->sources as $source){
2512
  		$footnoteKey = FootnoteManager::addNewFootnote($descriptionElement->feature->uuid, $source, 'cdm_DescriptionElementSource');
2513
  		$footnoteKeyList .= theme('cdm_footnode_key', $footnoteKey) . ' ';
2514
		}
2515
    $out .= $descriptionElement->area->representation_L10n . $footnoteKeyList . $separator;
2503 2516
	}
2504
	$descriptions = substr($descriptions, 0, strlen($descriptions)-2);
2517
	$out = substr($out, 0, strlen($out)-strlen($separator) );
2518
	
2505 2519
	$taxonTrees =  cdm_ws_get(CDM_WS_TAXONOMY);
2506 2520
	foreach($taxonTrees as $taxonTree){
2507 2521
		if ($taxonTree -> uuid == variable_get('cdm_taxonomictree_uuid', FALSE)){
......
2510 2524
		}
2511 2525
	}
2512 2526

  
2513
	if ($reference->title === "World Checklist of Arecaceae"){
2514
		$referenceCitation = l('<span class="reference">(World Checklist of Monocotyledons)</span>', path_to_reference($reference->uuid), array("class"=>"reference"), NULL, NULL, FALSE ,TRUE);
2515
	}else
2516
	{
2517
		$referenceCitation = l('<span class="reference">('.$reference->title.')</span>', path_to_reference($reference->uuid), array("class"=>"reference"), NULL, NULL, FALSE ,TRUE);
2518
	}
2519
	if($descriptions && strlen($descriptions) > 0 ){
2520
		$sourceRefs .= ' '.$referenceCitation;
2521
	}
2527
//  $referenceCitation = l('<span class="reference">('.$reference->title.')</span>', path_to_reference($reference->uuid), array("class"=>"reference"), NULL, NULL, FALSE ,TRUE);
2528
//	if($descriptions && strlen($descriptions) > 0 ){
2529
//		$sourceRefs .= ' '.$referenceCitation;
2530
//	}
2522 2531

  
2523
	if(strlen($sourceRefs) > 0){
2524
		$sourceRefs = '<span class="sources">' . $sourceRefs . '</span>';
2525
	}
2526
	return $descriptions. $sourceRefs ;
2532
	return $out;
2527 2533

  
2534
}
2528 2535

  
2536
function theme_cdm_DescriptionElementSource($descriptionElementSource, $doLink = TRUE){
2537
  
2538
    //ev. delegate to theme_cdm_ReferencedEntityBase
2539
    $out = '';
2540
    if($descriptionElementSource->citation){
2541
      $datePublished = $descriptionElementSource->citation->datePublished;
2542
      if (strlen($datePublished->start) >0){
2543
        $year=substr($datePublished->start,0,strpos($datePublished->start,'-'));
2544
      }
2545
      $author_team_titlecache = $descriptionElementSource->citation->authorTeam->titleCache;
2546
      if (strlen($year)>0){
2547
        $reference = $author_team_titlecache.' '. $year;
2548
      }else {
2549
        $reference = $author_team_titlecache ;
2550
      }
2551
      
2552
      if($doLink){
2553
        $out = l('<span class="reference">'.$reference.'</span>'
2554
          , path_to_reference($descriptionElementSource->citation->uuid)
2555
          , array("class"=>"reference")
2556
          , NULL, NULL, FALSE ,TRUE);
2557
      } else {
2558
       $out = $reference;
2559
      }
2560
      if($descriptionElementSource->citationMicroReference){
2561
        $out .= ': '. $descriptionElementSource->citationMicroReference;
2562
      }
2563
    }
2564
    return $out;
2529 2565
}
2530 2566

  
2531 2567
function theme_cdm_descriptionElementArray($elementArray, $feature, $glue = '', $sortArray = false, $enclosingHtml = 'ul'){
......
2557 2593
  $res_date;
2558 2594
    
2559 2595
  foreach($element->sources as $source){
2560
    $referenceCitation = '';
2561
    if($source->citation){
2562
      $datePublished = $source->citation->datePublished;
2563
      if (strlen($datePublished->start) >0){
2564
        $year=substr($datePublished->start,0,strpos($datePublished->start,'-'));
2565
      }
2566
      /* new implementation */
2567
      $author_team_titlecache = $source->citation->authorTeam->titleCache; //$source->citation->authorTeam->titlecache
2568
      if (strlen($year)>0){
2569
        $reference = $author_team_titlecache.' '. $year;
2570
      }else {
2571
        $reference = $author_team_titlecache ;
2572
      }
2573
      
2574
      $referenceCitation = l('<span class="reference">'.'(' .$reference.')'.'</span>', path_to_reference($source->citation->uuid), array("class"=>"reference"), NULL, NULL, FALSE ,TRUE);
2575
      if($source->citationMicroReference){
2576
        $referenceCitation .= ': '. $source->citationMicroReference;
2577
      }
2578
      if($description && strlen($description) > 0 ){
2579
        $sourceRefs .= ' '.$referenceCitation ;
2580
      }
2596
    $referenceCitation = theme('cdm_DescriptionElementSource', $source);
2597
    if($description && strlen($description) > 0 && $referenceCitation ){
2598
        $sourceRefs .= ' ('.$referenceCitation.')' ;
2581 2599
    }
2582 2600
  }
2583 2601
  if(strlen($sourceRefs) > 0){
......
2588 2606
  }else{
2589 2607
    $res_text = $description . $sourceRefs;
2590 2608
  }
2591
    return $res_text;
2609
  return $res_text;
2592 2610
}
2593 2611

  
2594 2612
function theme_cdm_search_results($pager, $path, $parameters){
......
2637 2655
	return $out;
2638 2656
}
2639 2657

  
2658
function theme_cdm_footnode_key($footnoteKey){
2659
  $out = '<a href="#footnote-'.$footnoteKey.'" class="footnote-key">'.$footnoteKey.'</a>';
2660
  return $out;
2661
}
2662

  
2663
function theme_cdm_footnode($footnoteKey, $footnodeText){
2664
  _add_js_footnotes();
2665
  $out = '<span class="footnote footnote-'.$footnoteKey.'"><a name="footnote-'.$footnoteKey.'"></a><span class="footnote-anchor">'.$footnoteKey.'.</span>&nbsp;'.$footnodeText.'</span>';
2666
  return $out;
2667
}
2668

  
2669

  
2640 2670

  
2641 2671
function theme_cdm_pager(&$pager, $path, $parameters){
2642 2672
	$out = '';
modules/cdm_dataportal/classes/footnote.php
1
<?php
2

  
3
class Footnote
4
{
5
  
6
    public $key, $object, $theme, $themeArguments;
7
    
8
    
9
    // private constructor
10
    public function __construct($footnoteKey, $object, $theme = null, array $themeArguments = array()) {
11
        $this->key = $footnoteKey;
12
        $this->object = $object;
13
        $this->theme = $theme;
14
        if(!is_array($themeArguments)){
15
          $themeArguments = array();
16
        }
17
        $this->themeArguments = $themeArguments;
18
    }
19

  
20
    public function doRender(){
21
      
22
      if($this->theme){
23
      $args = $this->themeArguments;
24
      array_unshift($this->object);
25
      array_unshift($this->theme);
26

  
27
        $out = call_user_func_array('theme', $args);
28
      } else {
29
        $out = $this->object;
30
      }
31
      return theme('cdm_footnode', $this->key, $out);
32
    }
33

  
34
}
modules/cdm_dataportal/classes/footnotemanager.php
1
<?php
2

  
3
class FootnoteManager
4
{
5
  
6
    
7
    private static $fnstore = array();
8
    
9
    private static $nextFootnoteKey = 1;
10
    
11
    // private constructor
12
    private function __construct() {
13
      
14
    }
15

  
16
 
17
    /**
18
     * @param $footnoteListKey a string as key to the list of footnotes
19
     * @return an array of footnotes objects
20
     *  
21
     */
22
    public static function getFootnoteList($footnoteListKey){
23
      return array_key_exists($footnoteListKey, self::$fnstore) ? self::$fnstore[$footnoteListKey] : NULL;
24
    }
25
    
26
    /**
27
     * 
28
     * @param $footnoteListKey
29
     * @param $separator
30
     * @return unknown_type
31
     */
32
    public static function renderFootnoteList($footnoteListKey, $separator = ', '){
33
      $out = '';
34
      if(array_key_exists($footnoteListKey, self::$fnstore)){
35
        foreach(self::$fnstore[$footnoteListKey] as $fn){
36
          $out .= $fn->doRender() . $separator;
37
        }
38
        $out = substr($out, 0, strlen($out)-strlen($separator));
39
      }
40
      return $out;
41
    }
42
    
43
    /**
44
     * 
45
     * @param $footnoteListKey
46
     * @param $object
47
     * @param $theme
48
     * @param $themeArguments
49
     * @return unknown_type
50
     */
51
    public static function addNewFootnote($footnoteListKey, $object, $theme = NULL, $themeArguments = array()){
52

  
53
      if(!array_key_exists($footnoteListKey, self::$fnstore)){
54
          self::$fnstore[$footnoteListKey] = array();
55
      }
56
      
57
      $fnKey = NULL;
58
      if( !($fnKey = self::footnoteExists($footnoteListKey, $object)) ){
59
        $fnKey = self::$nextFootnoteKey++;
60
        $fn = new Footnote($fnKey, $object, $theme, $themeArguments);
61
        self::$fnstore[$footnoteListKey][$fnKey] = $fn;
62
        
63
      }
64
      
65
      return $fnKey;
66
    }
67
    
68
    /**
69
     * 
70
     * @param $footnoteListKey
71
     * @param $object
72
     * @return unknown_type
73
     */
74
    private static function footnoteExists($footnoteListKey, $object){
75
      foreach(self::$fnstore[$footnoteListKey] as $key=>$fn){
76
        /**
77
         * When using the comparison operator (==), object variables are compared in a simple manner, namely: 
78
         * Two object instances are equal if they have the same attributes and values, and are instances of the same class. 
79
         */
80
        if($object == $fn->object){
81
          return $key;
82
        }
83
      }
84
      return FALSE;
85
    }
86
    
87
    // stop users from cloning
88
    public function __clone() {
89
      
90
        trigger_error('Cloning instances of the singleton class FootNoteManager is prohibited', E_USER_ERROR);
91
    }
92

  
93
}
modules/cdm_dataportal/js/footnotes.js
1
if (Drupal.jsEnabled) {
2
  $(document).ready($(document).ready(function() {
3
	  
4
	  function getFootnoteClassName(object){
5
		  return '.'+$(object).attr('href').substr(1);
6
	  }
7
	  
8
	  $('a.footnote-key').mouseover(function(e){
9
		  var fnClassName = getFootnoteClassName(this);
10
		  $('.footnote').css('background-color', 'transparent').css('background-color', 'transparent').removeClass('active');
11
		  $(fnClassName).css('background-color', 'yellow');
12
	  	}
13
	  ).mouseout(function(e){
14
		  var fnClassName = getFootnoteClassName(this);
15
		  $(fnClassName).not('.active').css('background-color', 'transparent');
16
	  	}
17
	  ).click(function(e){
18
		  var fnClassName = getFootnoteClassName(this);
19
		  $('.footnote').css('background-color', 'transparent').removeClass('active');
20
		  $(fnClassName).css('background-color', 'yellow').addClass('active');
21
	  });
22
	  
23
  }));
24
}
themes/palmweb_2/template.php
90 90
  
91 91
}
92 92

  
93
function palmweb_2_cdm_descriptionElementDistribution($descriptionElements) {
94

  
95
  $descriptions = '';
96
  $separator = ', ';
97

  
98
  foreach($descriptionElements as $descriptionElement){
99
    $descriptions .= $descriptionElement->area->representation_L10n . $separator;
100
  }
101
  $descriptions = substr($descriptions, 0, strlen($descriptions)-2);
102
  $taxonTrees =  cdm_ws_get(CDM_WS_TAXONOMY);
103
  foreach($taxonTrees as $taxonTree){
104
    if ($taxonTree -> uuid == variable_get('cdm_taxonomictree_uuid', FALSE)){
105
      $reference = $taxonTree-> reference;
106
      break;
107
    }
108
  }
109
  $out = substr($out, 0, strlen($out)-strlen($separator) );
110

  
111
  $referenceCitation = '('.l('<span class="reference">World Checklist of Monocotyledons</span>', path_to_reference($reference->uuid), array("class"=>"reference"), NULL, NULL, FALSE ,TRUE).')';
112
  
113
  if($descriptions && strlen($descriptions) > 0 ){
114
    $sourceRefs .= ' '.$referenceCitation;
115
  }
116

  
117
  if(strlen($sourceRefs) > 0){
118
    $sourceRefs = '<span class="sources">' . $sourceRefs . '</span>';
119
  }
120
  return $descriptions. $sourceRefs ;
121

  
122
}
123

  
93 124

  
94 125
/**
95 126
 * Sets the body-tag class attribute.

Also available in: Unified diff