Project

General

Profile

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

    
4
/**
5
 * Copyright (C) 2007 EDIT
6
 * European Distributed Institute of Taxonomy
7
 * http://www.e-taxonomy.eu
8
 *
9
 * The contents of this file are subject to the Mozilla Public License Version 1.1
10
 * See http://www.mozilla.org/MPL/MPL-1.1.html for the full license terms.
11
 */
12

    
13
function theme_cdm_search_results($pager, $path, $parameters){
14

    
15

    
16
  $showThumbnails = $_SESSION['pageoptions']['searchtaxa']['showThumbnails'];
17
  if( !is_numeric($showThumbnails)){
18
    $showThumbnails = 1;
19
  }
20
  $setSessionUri = url('cdm_api/setvalue/session', "var=[pageoption][searchtaxa][showThumbnails]&val=");
21
  drupal_add_js('$(document).ready(function() {
22

    
23
        // init
24
        if('.$showThumbnails.' == 1){
25
              $(\'.media_gallery\').show(20);
26
        } else {
27
          $(\'.media_gallery\').hide(20);
28
        }
29
        // add change hander
30
        $(\'#showThumbnails\').change(
31
          function(event){
32
            var state = 0;
33
            if($(this).is(\':checked\')){
34
              $(\'.media_gallery\').show(20);
35
              state = 1;
36
            } else {
37
              $(\'.media_gallery\').hide(20);
38
            }
39
            // store state in session variable
40
            var uri = \''.$setSessionUri.'\' + state;
41
            jQuery.get(uri);
42
          });
43
        });', "inline");
44

    
45
  drupal_set_title(t('Search results'));
46

    
47
  $out = ''; //l('Advanced Search', '/cdm_dataportal/search');
48

    
49
  $out = '<div class="page_options"><form name="pageoptions"><input id="showThumbnails" type="checkbox" name="showThumbnails" '.($showThumbnails == 1? 'checked="checked"': '').'> '.t('Show Thumbnails').'</form></div>';
50
  if(count($pager->records) > 0){
51
      $out .= '<div id="search_results">';
52
    $out .= theme('cdm_list_of_taxa', $pager->records);
53
    $out .= '</div>';
54
    $out .= theme('cdm_pager', $pager, $path, $parameters);
55
  } else {
56
    $out = '<h4 class="error">Sorry, no matching entries found.</h4>';
57
  }
58
  return $out;
59
}
60

    
61

    
62
/**
63
 * renders misapplied names and invalid designations.
64
 * Both relation types are currently treated the same!
65
 *
66
 * @param unknown_type $taxonRelationships
67
 * @return unknown
68
 */
69
function theme_cdm_taxonRelationships($taxonRelationships, $focusedTaxon){
70

    
71
  if(!$taxonRelationships){
72
    return;
73
  }
74

    
75
  RenderHints::pushToRenderStack('taxonRelationships');
76
  $footnoteListKey = 'taxonRelationships';
77
  RenderHints::setFootnoteListKey($footnoteListKey);
78

    
79
  $misapplied = array();
80
  $joinedAuthorTeams = array();
81

    
82
  $taxon_relationship_types = variable_get(CDM_TAXON_RELATIONSHIP_TYPES, unserialize(CDM_TAXON_RELATIONSHIP_TYPES_DEFAULT));
83

    
84
  // aggregate misapplied names having the same fullname:
85
  foreach($taxonRelationships as $taxonRelation){
86

    
87
      if( in_array($taxonRelation->type->uuid, $taxon_relationship_types)) {
88

    
89
        if( $taxonRelation->type->uuid == UUID_MISAPPLIED_NAME_FOR || $taxonRelation->type->uuid == UUID_INVALID_DESIGNATION_FOR ){
90

    
91
          $name = $taxonRelation->fromTaxon->name->titleCache;
92

    
93
          $authorteam = cdm_ws_get(CDM_WS_REFERENCE_AUTHORTEAM, $taxonRelation->fromTaxon->sec->uuid);
94
          $authorteam = $authorteam->titleCache;
95

    
96
          if(!isset($misapplied[$name])){
97
            // render the first name found as reprensntative for all others
98
            $misapplied[$name]['out'] = cdm_related_taxon($taxonRelation->fromTaxon, UUID_MISAPPLIED_NAME_FOR);
99
          } else {
100
            // we need to add the anchors for all of the other mispplied names not being rendered explicitely.
101
            $misapplied[$name]['out'] = uuid_anchor($taxonRelation->fromTaxon->uuid, $misapplied[$name]['out']);
102

    
103
          }
104

    
105
          // collect all authors for this fullname
106
          if(isset($authorteam)){
107
            $misapplied[$name]['authorteam'][$authorteam] = '';
108
            $joinedAuthorTeams[$authorteam] = 'sensu '.theme('cdm_reference', $taxonRelation->fromTaxon->sec);
109
          }
110

    
111
        } else {
112
          // all relationsship types but misapplied_name_for invalid_designation_for
113
           $taxonRelationshipsLines[] = cdm_taxonRelationship($taxonRelation, true, _is_invers_taxonRelationship($taxonRelation, $focusedTaxon), true);
114
        }
115
     }
116
  }
117

    
118
  // sort the joinedAuthorTeams and create footnotes and footnotekeys
119
  ksort($joinedAuthorTeams);
120
  foreach($joinedAuthorTeams as $authorteam=>$sensuCitation){
121
    $footnoteKey = FootnoteManager::addNewFootnote($footnoteListKey, $sensuCitation);
122
    $joinedAuthorTeams[$authorteam] = '<span class="sensu">sensu '.$authorteam. theme('cdm_footnote_key', $footnoteKey).'</span>';
123
  }
124

    
125
  // generate output
126
  if(is_array($misapplied) && count($misapplied) >0 ){
127
      $out .= '<ul class="misapplied">';
128
      foreach($misapplied as $misapplied_name){
129

    
130
        $out .= '<li class="synonym"><span class="misapplied">' . $other_anchors . $misapplied_name['out'] . ' </span>';
131

    
132
        if(isset($misapplied_name['authorteam'])){
133
          // fill authors with the renderedFootnoteKey and sorting 'em
134
          foreach($misapplied_name['authorteam'] as $authorteam=>&$renderedFootnoteKey) {
135
            $renderedFootnoteKey = $joinedAuthorTeams[$authorteam];
136
          }
137
            ksort($misapplied_name['authorteam']);
138
            $out .= join('; ', $misapplied_name['authorteam']);
139
        }
140
        $out .= '</li>';
141

    
142
      }
143
      $out .= '</ul>';
144
  }
145

    
146
  if(is_array($taxonRelationshipsLines) && count($taxonRelationshipsLines) >0 ){
147
      $out .= '<ul class="taxonRelationships">';
148
      foreach($taxonRelationshipsLines as $taxonRelationshipLine){
149
        $out .= '<li class="synonym">'. $taxonRelationshipLine . '</li>';
150
      }
151
      $out .= '</ul>';
152
  }
153

    
154

    
155
  $tr_footnotes = theme('cdm_footnotes', $footnoteListKey, 'li');
156
  $tr_footnotes_exploded = explode('sensu', $tr_footnotes);
157
  $tr_footnotes_aux = '';
158
  foreach ($tr_footnotes_exploded as $element){
159
    $tr_footnotes_aux .= $element;
160
  }
161
  $out .= '<ul>' . $tr_footnotes_aux . '</ul>';
162

    
163
  RenderHints::popFromRenderStack();
164
  return $out;
165
}
166

    
167

    
168

    
169
function theme_cdm_acceptedFor(){
170
  RenderHints::pushToRenderStack('acceptedFor');
171

    
172
  $out = '';
173
  if(isset($_REQUEST['acceptedFor'])){
174

    
175
    $synonym = cdm_ws_get(CDM_WS_PORTAL_TAXON, $_REQUEST['acceptedFor']);
176

    
177
    if($synonym){
178
      $out .= '<span class="acceptedFor">';
179
      $out .= t('is accepted for ');
180
      if(isset($synonym->name->nomenclaturalReference)){
181
        $referenceUri = url(path_to_reference($synonym->name->nomenclaturalReference->uuid));
182
      }
183
      $out .= theme('cdm_taxonName', $synonym->name, null, $referenceUri);
184
      $out .= theme('cdm_annotations_as_footnotekeys', $synonym);
185
      $out .= '</span>';
186
    }
187
  }
188
  RenderHints::popFromRenderStack();
189
  return $out;
190
}
191

    
192

    
193

    
194
function theme_cdm_list_of_taxa($records, $showMedia = false){
195

    
196
  RenderHints::pushToRenderStack('list_of_taxa');
197

    
198
  $form_name = 'search_gallery';
199
  //$default_values = unserialize(CDM_DATAPORTAL_GALLERY_SETTINGS);
200
    //$gallery_settings = variable_get($form_name, $default_values);
201

    
202
    $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME);
203

    
204
  $showMedia_taxa = $gallery_settings['cdm_dataportal_show_taxon_thumbnails'];
205
  $showMedia_synonyms = $gallery_settings['cdm_dataportal_show_synonym_thumbnails'];
206
  //$showMedia_taxa = variable_get('cdm_dataportal_findtaxa_show_taxon_thumbnails', 1);
207
  //$showMedia_synonyms = variable_get('cdm_dataportal_findtaxa_show_synonym_thumbnails', 0);
208

    
209
  $classification_uuid = get_taxonomictree_uuid_selected();
210

    
211
  // .. well, for sure not as performant as before, but better than nothing.
212
  $synonym_uuids = array();
213
  $misappied_uuids = array();
214
  foreach($records as $taxon){
215

    
216
    if($taxon->class == "Synonym") {
217
      if(!array_key_exists($taxon->uuid, $synonym_uuids)){
218
        $synonym_uuids[$taxon->uuid] = $taxon->uuid;
219
      }
220
    } else if( !_cdm_dataportal_acceptedByCurrentView($taxon) ) {
221
      // assuming that it is a misappied name, will be further examined below
222
      $misappied_uuids[$taxon->uuid] = $taxon->uuid;
223
    }
224

    
225
  }
226

    
227
  // batch service not jet implemented:
228
  // $table_of_accepted = cdm_ws_property(CDM_WS_PORTAL_TAXON_ACCEPTED, join(',', $synonym_uuids));
229
  // thus ...
230
  $table_of_accepted = array();
231

    
232
  foreach($synonym_uuids as $relatedUuid){
233
    $table_of_accepted[$relatedUuid] = cdm_ws_get(CDM_WS_PORTAL_TAXON_ACCEPTED, array($relatedUuid, $classification_uuid));
234
  }
235

    
236
  foreach($misappied_uuids as $relatedUuid){
237
    $taxonRelations = cdm_ws_get(CDM_WS_PORTAL_TAXON_RELATIONS, array($relatedUuid));
238
    foreach($taxonRelations as $relation) {
239
      if($relation->type->uuid == UUID_MISAPPLIED_NAME_FOR && _cdm_dataportal_acceptedByCurrentView($relation->toTaxon)) {
240
        $table_of_accepted[$relatedUuid][] = $relation->toTaxon;
241
      }
242
    }
243
  }
244

    
245
  $out = '<ul class="cdm_names" style="background-image: none;">';
246

    
247
  foreach($records as $taxon){
248

    
249
    if( isset($table_of_accepted[$taxon->uuid])) {
250
      // its a synonym or misapplied name
251
      $is_synonym = isset($synonym_uuids[$taxon->uuid]);
252
      $class_name = $is_synonym ? "Synonym" : "misapplied-name";
253

    
254
      $acceptedTaxa = $table_of_accepted[$taxon->uuid];
255

    
256
      if(count($acceptedTaxa) == 1){
257

    
258
        $acceptedTaxon = $acceptedTaxa[0];
259
        $taxonUri = uri_to_synonym($taxon->uuid, $acceptedTaxon->uuid, 'synonymy');
260
        if(isset($acceptedTaxon->name->nomenclaturalReference)){
261
          $referenceUri = url(path_to_reference($acceptedTaxon->name->nomenclaturalReference->uuid));
262
        }
263
        $out .= '<li class="' . $class_name . '">'.theme('cdm_taxonName', $taxon->name, $taxonUri, $referenceUri);
264
        if(!$is_synonym){
265
          $out .= '<span class="sensu"> sensu ' . theme('cdm_reference', $taxon->sec) . '</span>';
266
        }
267
        $out .= theme('cdm_annotations_as_footnotekeys', $taxon);
268
        if($showMedia_synonyms){
269
          $out .= theme('cdm_taxon_list_thumbnails', $acceptedTaxon);
270
        }
271
        $out .= '</li>';
272

    
273
      } else {
274

    
275
        //TODO avoid using Ajax in the cdm_dynabox .... why?
276
        //TODO add media
277
        $out .= cdm_dynabox(
278
          theme('cdm_taxonName', $taxon->name, null, null, false),
279
          cdm_compose_url(CDM_WS_PORTAL_TAXON_ACCEPTED, array($taxon->uuid, $classification_uuid)),
280
          'cdm_list_of_taxa',
281
          'Click for accepted taxon');
282

    
283
      }
284
    } else {
285
      // its a Taxon
286
      $taxonUri = url(path_to_taxon($taxon->uuid));
287
      if(isset($taxon->name->nomenclaturalReference)){
288
        $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
289
      }
290
      $out .= '<li class="Taxon">'.theme('cdm_taxonName', $taxon->name, $taxonUri, $referenceUri);
291
      $out .= theme('cdm_annotations_as_footnotekeys', $taxon);
292

    
293
      if($showMedia_taxa){
294
        $out .= theme('cdm_taxon_list_thumbnails', $taxon);
295
      }
296
      $out .= '</li>';
297
    }
298
  }
299

    
300
  $out .= '</ul>';
301
  RenderHints::popFromRenderStack();
302
  return $out;
303
}
304

    
305
/**
306
 * renders a representation of the given taxon relationship.
307
 * According name relatinships are also being rendered.
308
 *
309
 *
310
 * @param unknown_type $taxon
311
 * @param unknown_type $reltype_uuid
312
 * @param unknown_type $taxonRelationType
313
 * @param unknown_type $doLinkTaxon
314
 */
315
function cdm_taxonRelationship($taxonRelationship, $doLinkTaxon = false, $inverse = false, $showSecReference = false){
316

    
317
  // validate object
318
  if( ! (isset($taxonRelationship->toTaxon) && isset($taxonRelationship->fromTaxon) && isset($taxonRelationship->type)) ) {
319
    return;
320
  }
321

    
322
  $reltype_uuid = $taxonRelationship->type->uuid;
323
  $taxonRelationType = $taxonRelationship->type;
324

    
325

    
326
  $reltype_representation = '';
327

    
328
  if($inverse) {
329
    $toTaxon = $taxonRelationship->fromTaxon;
330
    $fromTaxon = $taxonRelationship->toTaxon;
331
    $relsign = $taxonRelationType->inverseRepresentation_L10n_abbreviatedLabel;
332
    $reltype_representation = $taxonRelationType->inverseRepresentation_L10n;
333
  } else {
334
    $toTaxon = $taxonRelationship->toTaxon;
335
    $fromTaxon = $taxonRelationship->fromTaxon;
336
    $relsign = $taxonRelationType->representation_L10n_abbreviatedLabel;
337
    $reltype_representation = $taxonRelationType->representation_L10n;
338
  }
339

    
340
  return cdm_related_taxon($toTaxon, null, $relsign, $reltype_representation, $doLinkTaxon, $showSecReference);
341
}
342

    
343
/**
344
* renders a representation of the given taxon relationship.
345
* According name relatinships are also being rendered.
346
*
347
*
348
* @param unknown_type $taxon
349
* @param unknown_type $reltype_uuid
350
* @param unknown_type $taxonRelationType
351
* @param unknown_type $doLinkTaxon
352
*/
353
function cdm_related_taxon($taxon, $reltype_uuid = null, $relsign = null, $reltype_representation = null, $doLinkTaxon = false, $showSecReference = false){
354

    
355
  static $relsign_homo = '≡';
356
  static $relsign_hetero = '=';
357
  static $relsign_invalid = '&ndash;';
358

    
359
  $footnoteListKey = 'taxonRelationships';
360

    
361
  $name_prefix = '';
362
  $name_postfix = '';
363

    
364
  $skiptags = array();
365

    
366
  if(!$relsign) {
367

    
368
    $relsign = '';
369
    switch ($reltype_uuid){
370
      case UUID_HETEROTYPIC_SYNONYM_OF:
371
      case UUID_SYNONYM_OF:
372
        $relsign = $relsign_hetero;
373
        break;
374
      case UUID_HOMOTYPIC_SYNONYM_OF:
375
        $relsign = $relsign_homo;
376
        break;
377
      case UUID_MISAPPLIED_NAME_FOR:
378
      case UUID_INVALID_DESIGNATION_FOR:
379
        $skiptags[] = 'authors';
380
        $relsign = $relsign_invalid;
381
        $name_prefix = '"';
382
        $name_postfix = '"';
383
        break;
384
      default :
385
        $relsign = $relsign_invalid;
386
    }
387
  }
388
  /*
389
   * names with status invalid or nudum are to be displayed with the $relsign_invalid,
390
  * these names appear at the end of all names in their homotypic group
391
  * (ordered correctly by the java cdm_lib)
392
  */
393
  if ( is_array($taxon->name->status)) {
394
    foreach($taxon->name->status as $status){
395
      if ($status->type->uuid == UUID_NOMENCLATURALSTATUS_TYPE_INVALID || $status->type->uuid == UUID_NOMENCLATURALSTATUS_TYPE_NUDUM){
396
        $relsign = $relsign_invalid;
397
      }
398
    }
399
  }
400

    
401
  // now rendering starts ..
402

    
403
  RenderHints::pushToRenderStack('related_taxon');
404

    
405
  if($taxon->name->nomenclaturalReference){
406
    $referenceUri = url(path_to_reference($taxon->name->nomenclaturalReference->uuid));
407
  }
408
  if($doLinkTaxon){
409
    $taxonUri = url(path_to_taxon($taxon->uuid, "synonymy"));
410
  }
411
  //printing the taxonName and the handling the special case of annotations
412
  $out_taxon_part = theme('cdm_taxonName', $taxon->name, $taxonUri, $referenceUri, true, false, $skiptags);
413
  $out_taxon_part .= theme('cdm_annotations_as_footnotekeys', array($taxon->name, $taxon), $footnoteListKey);
414

    
415
  if($showSecReference) {
416
    $out_taxon_part .= ' sec. ' . theme('cdm_reference',  $taxon->sec);
417
  }
418

    
419

    
420
  //later homonym or trated as later homonym AND bloking names
421
  $from_name_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_FROM_NAMERELATIONS, $taxon->uuid);
422
  $to_name_relations = cdm_ws_get(CDM_WS_PORTAL_TAXON_TO_NAMERELATIONS, $taxon->uuid);
423

    
424
  //first the FROM RELS
425
  //FIXME use UUID below instad of representation_L10n
426
  if ($from_name_relations){
427
    foreach($from_name_relations as $element){
428
      switch ($element->type->representation_L10n){
429
        case 'later homonym for':
430
          if(isset($name_relations_html)){
431
            $name_relations_html .= 'nec ' . l($element->toName->titleCache . ' ' .  substr($element->toName->nomenclaturalReference->datePublished->start, 0, 4),
432
                'cdm_dataportal/name/' . $element->toName->uuid . '/' . $taxon->uuid . '/' . $element->toName->taxonBases[0]->uuid);
433
          }else{
434
            $name_relations_html = 'non ' . l($element->toName->titleCache . ' ' .  substr($element->toName->nomenclaturalReference->datePublished->start, 0, 4),
435
                        'cdm_dataportal/name/' . $element->toName->uuid . '/' . $taxon->uuid . '/' . $element->toName->taxonBases[0]->uuid)
436
            . ' ' . $element->toName->datePublished->start;
437
          }
438
          break;
439
        case 'treated as later homonym for':
440
          if(isset($name_relations_html)){
441
            $name_relations_html = 'nec ' . l($element->toName->titleCache . ' ' .  substr($element->toName->nomenclaturalReference->datePublished->start, 0, 4),
442
                              'cdm_dataportal/name/' . $element->toName->uuid);
443
          }else{
444
            $name_relations_html = 'non ' . l($element->toName->titleCache . ' ' .  substr($element->toName->nomenclaturalReference->datePublished->start, 0, 4),
445
                             'cdm_dataportal/name/' . $element->toName->uuid);
446
          }
447
          break;
448
      }
449
    }
450
    //second the TO RELS
451
    if ($to_name_relations){
452
      foreach($to_name_relations as $element){
453
        switch ($element->type->representation_L10n){
454
          case 'blocking name for':
455
            if(isset($name_relations_html) ){
456
              $name_relations_html .= 'nec ' . l($element->fromName->titleCache . ' ' .  substr($element->fromName->nomenclaturalReference->datePublished->start, 0, 4),
457
                'cdm_dataportal/name/' . $element->fromName->uuid . '/' . $taxon->uuid . '/' . $element->fromName->taxonBases[0]->uuid);
458
            }else{
459
              $name_relations_html = 'non ' . l($element->fromName->titleCache . ' ' .  substr($element->fromName->nomenclaturalReference->datePublished->start, 0, 4),
460
                        'cdm_dataportal/name/' . $element->fromName->uuid . '/' . $taxon->uuid . '/' . $element->fromName->taxonBases[0]->uuid)
461
              . ' ' . $element->fromName->datePublished->start;
462
            }
463
            break;
464
        }
465
      }
466
    }
467
    //rels output
468
    if(isset($name_relations_html)){
469
      $name_relations_html = '['. trim($name_relations_html) .']';
470
    }
471
  }
472
  //geneal output
473
  $out = '<span class="relation_sign" title="' . $reltype_representation . '">'.$relsign.'</span>'.$name_prefix . $out_taxon_part . $name_postfix . ' ' . $name_relations_html;
474
  $out = uuid_anchor($taxon->uuid, $out);
475

    
476
  RenderHints::popFromRenderStack();
477

    
478
  return $out;
479
}
480

    
481
/**
482
 */
483
function theme_cdm_taxon_list_thumbnails($taxon){
484

    
485

    
486
  $gallery_settings = getGallerySettings(CDM_DATAPORTAL_SEARCH_GALLERY_NAME);
487
  $showCaption = $gallery_settings['cdm_dataportal_show_thumbnail_captions'];
488

    
489
  if($showCaption){
490
    $captionElements = array('title', 'rights');
491
  }
492

    
493
  $gallery_name = $taxon->uuid;
494

    
495
   $mediaQueryParameters = array("type"=>"ImageFile");
496
  $galleryLinkUri = path_to_taxon($taxon->uuid, 'images');
497

    
498
  // cdm_dataportal_show_media = ???? TODO
499
  $selectShowMedia = variable_get('cdm_dataportal_show_media', 0);
500
  if ($selectShowMedia == 0){
501
    $mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXON_MEDIA, array($taxon->uuid), queryString( $mediaQueryParameters ));
502
  }else{
503
    $mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXON_SUBTREE_MEDIA, array($taxon->uuid), queryString( $mediaQueryParameters ));
504
  }
505

    
506
  $out .= theme('cdm_media_gallerie', $mediaList, $gallery_name ,
507
      $gallery_settings['cdm_dataportal_media_maxextend'],
508
      $gallery_settings['cdm_dataportal_media_cols'],
509
      $gallery_settings['cdm_dataportal_media_maxRows'],
510
      $captionElements, 'LIGHTBOX', null, $galleryLinkUri);
511

    
512
  return $out;
513
}
514

    
515

    
(8-8/8)