Project

General

Profile

Download (15.7 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * Description theming functions.
5
 *
6
 * @copyright
7
 *   (C) 2007-2012 EDIT
8
 *   European Distributed Institute of Taxonomy
9
 *   http://www.e-taxonomy.eu
10
 *
11
 *   The contents of this module are subject to the Mozilla
12
 *   Public License Version 1.1.
13
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
14
 */
15

    
16

    
17
/**
18
 * Theme function to alter the feature representation.
19
 *
20
 * It is highly questionable if this function should be completely removed.
21
 * If a feature needs a different representation this should be edited directly
22
 * in the cdm data but it should not be tweaked like this in the portal.
23
 *
24
 * Used in:
25
 *  - theme_cdm_feature_nodesTOC()
26
 *  - theme_cdm_feature_nodes()
27
 *  - theme_cdm_media_mime_application()
28
 *  - theme_cdm_media_mime_text()
29
 *
30
 * TODO delete this function? (a.kohlbecker feb 2013)
31
 *
32
 */
33
function theme_cdm_feature_name($variables) {
34
  $feature_name = $variables['feature_name'];
35
  return t('@feature-name', array('@feature-name' => $feature_name));
36
}
37

    
38

    
39
/**
40
 * Renders a hierarchical representation of the CDM FeatureTree identified by its uuid
41
 *
42
 * @param string $feature_tree_uuid
43
 *    The CDM FeatureTree uuid
44
 */
45
function render_feature_tree_hierarchy($feature_tree_uuid, $show_weight = FALSE) {
46

    
47
  if (!is_uuid($feature_tree_uuid)) {
48
    return NULL;
49
  }
50

    
51
  $out = '';
52
  $feature_tree = cdm_ws_get(CDM_WS_TERMTREE,
53
    array(
54
      $feature_tree_uuid,
55
    )
56
  );
57

    
58
  if (isset($feature_tree) && isset($feature_tree->root)) {
59
    $out = '<ul class="' . $feature_tree->class . '">';
60
    $out .= render_feature_tree_hierarchy_children($feature_tree->root, $show_weight);
61
    $out .= '</ul>';
62
  }
63
  return $out;
64
}
65

    
66
/**
67
 * Renders a hierarchical representation of the children of the CDM FeatureNode
68
 * passed as object.
69
 *
70
 * @param object $feature_node
71
 *    The CDM FeatureNode
72
 */
73
function render_feature_tree_hierarchy_children($feature_node, $show_weight = FALSE) {
74

    
75
  $out = '';
76
  $item_index = 0;
77
  if (isset($feature_node->childNodes)) {
78
    foreach ($feature_node->childNodes as $child_feature_node) {
79
      $out .= '<li>' . check_plain($child_feature_node->term->representation_L10n);
80
      if($show_weight){
81
        $out .= ' [' .$item_index . ']';
82
      }
83
      if (isset($child_feature_node->childNodes) && count($child_feature_node->childNodes) > 0) {
84
        $out .= '<ul>' . render_feature_tree_hierarchy_children($child_feature_node, $show_weight) . '</ul>';
85
      }
86
      $out .= '</li>';
87
      $item_index = $item_index + FEATURE_BLOCK_WEIGHT_INCREMENT;
88
    }
89
  }
90
  return $out;
91
}
92

    
93
/**
94
 * @todo Please document this function.
95
 * @see http://drupal.org/node/1354
96
 */
97
function theme_cdm_IdentificationKey($variables) {
98
  $out = '';
99
  $identificationKey = $variables['identificationKey'];
100
  $doLinkToKeyPage = $variables['doLinkToKeyPage'];
101
  $showIdentificationKeyTitle = $variables['showIdentificationKeyTitle'];
102
  $parentRenderPath = RenderHints::getRenderPath();
103
  RenderHints::pushToRenderStack("IdentificationKey");
104

    
105
  if ($showIdentificationKeyTitle) {
106
    if ($doLinkToKeyPage) {
107
      $out = l($identificationKey->titleCache, path_to_key($identificationKey->class, $identificationKey->uuid));
108
    }
109
    else {
110
      $out = $identificationKey->titleCache;
111
    }
112
  }
113
  if (isset($identificationKey->sources) && is_array($identificationKey->sources)) {
114
    // order and display sources.
115
    //TODO can the method handle_annotations_and_sources() be used here?
116
    $sources = oder_and_render_original_sources($identificationKey->sources);
117
    $out .= '<div class="sources">';
118
    $out .=  implode('', $sources);
119
    $out .= '</div>';
120
  }
121
  // Display annotations.
122
  $out .= theme('cdm_annotations', array('annotations' => cdm_fetch_visible_annotations($identificationKey), 'enclosingTag' => 'div'));
123
  RenderHints::popFromRenderStack();
124
  return $out;
125
}
126

    
127
/**
128
 * @todo Please document this function.
129
 * @see http://drupal.org/node/1354
130
 */
131
function theme_cdm_polytomousKey($variables) {
132
  $polytomousKey = $variables['polytomousKey'];
133

    
134
  // TODO settings needed.
135
  // @see http://en.wikipedia.org/wiki/Single_access_key#Presentation_styles
136
  // @see http://dev.e-taxonomy.eu/trac/ticket/2152
137
  $keyStyle = "linkedStyle";
138

    
139
  RenderHints::pushToRenderStack("polytomousKey");
140
  // Key nodes in linked style.
141
  $out = '<table class="polytomousKey polytomousKey_' . $keyStyle . '">';
142
  $out .= theme('cdm_polytomousKey_' . $keyStyle . '_subgraph', array('polytomousKeyNode' => $polytomousKey->root));
143
  $out .= '</table>';
144
  RenderHints::popFromRenderStack();
145
  return $out;
146
}
147

    
148
/**
149
 * @todo Please document this function.
150
 * @see http://drupal.org/node/1354
151
 */
152
function theme_cdm_polytomousKey_linkedStyle_subgraph($variables) {
153
  $polytomousKeyNode = $variables['polytomousKeyNode'];
154
  static $statementCountCharacter = '\'';
155
  $out = "";
156

    
157
  if (is_array($polytomousKeyNode->children)) {
158
    $childIndex = 0;
159

    
160
    // Render edges of the current node.
161
    foreach ($polytomousKeyNode->children as &$child) {
162

    
163
      if (!isset($child->statement) && isset($child->taxon->uuid)) {
164
        // Skip node with empty statements (see below for explanation: "Special
165
        // case").
166
        // this skipping here happens always in the next deeper level of iteration
167
        // the check below is node on the level above
168
        continue;
169
      }
170

    
171
      /*
172
       * Special case: Child nodes with empty statements but taxa as leaf are to
173
       * treated as if all those taxa where direct children of the source node.
174
       */
175
      $islinkToManyTaxa = !isset($child->children[0]->statement) && isset($child->children[0]->taxon->uuid);
176
      $islinkToTaxon = isset($child->taxon->uuid);
177
      $islinkToSubKey = isset($child->subkey->uuid);
178
      $islinkToOtherNode = isset($child->otherNode);
179
      // Either NULL or 0.
180
      $islinkToNode = $child->nodeNumber && !$islinkToManyTaxa && !$islinkToOtherNode;
181
      $hasQuestion = !empty($polytomousKeyNode->question->label_l10n);
182
      $hasFeature = isset($polytomousKeyNode->feature);
183

    
184
      // $indentEdge = $hasQuestion && $childIndex > 0;
185
      // Question.
186
      if ($hasQuestion && $childIndex == 0) {
187
        // Place question, as extra table row.
188
        $out .= '<tr class="question new_section">';
189
        $out .= '<td class="nodeNumber">' . uuid_anchor($polytomousKeyNode->uuid, $polytomousKeyNode->nodeNumber) . "</td>";
190
        $out .= '<td class="question">' . $polytomousKeyNode->question->label_l10n . '</td>';
191
        $out .= '</tr>';
192
      }
193

    
194
      $out .= '<tr class="childCount_' . $childIndex . (!$hasQuestion && $childIndex == 0 ? ' new_section' : '') . '">';
195

    
196
      if ($hasQuestion) {
197
        $out .= '<td class="nodeNumber"></td>';
198
      }
199
      else {
200
        $out .= '<td class="nodeNumber">' . uuid_anchor($polytomousKeyNode->uuid, $polytomousKeyNode->nodeNumber . str_pad("", $childIndex, $statementCountCharacter)) . "</td>";
201
      }
202

    
203
      $out .= '<td ' . RenderHints::getHtmlElementID($child) . '  class="edge' . ($hasQuestion ? ' edge-indent' : '') . '">';
204

    
205
      // Feature.
206
      if ($hasFeature) {
207
        $out .= $polytomousKeyNode->feature->representation_L10n . ": ";
208
      }
209

    
210
      // Statement.
211
      $out .= $child->statement->label_l10n;
212

    
213
      // --- Links to nodes taxa and subkeys.
214
      $out .= '<div class="nodeLink">';
215

    
216
      // Link to a PolytomousKeyNode.
217
      if ($islinkToNode) {
218
        $out .= '<div class="nodeLinkToNode">';
219
        if (isset($child->modifyingText)) {
220
          $out .= theme('cdm_poytomousKeyNode_modifyingText', array('modifyingText' => $child->modifyingText));
221
        }
222
        $out .= l($child->nodeNumber, request_path(), array(
223
          'attributes' => NULL,
224
          'query' => NULL,
225
          'fragment' => $child->uuid,
226
        )) . '</div>';
227
      }
228

    
229
      // Link to a PolytomousKeyNode.
230
      if ($islinkToOtherNode) {
231
        $out .= '<div class="nodeLinkToOtherNode">';
232
        if (isset($child->modifyingText)) {
233
          $out .= theme('cdm_poytomousKeyNode_modifyingText', array('modifyingText' => $child->modifyingText));
234
        }
235
        $out .= l($child->otherNode->nodeNumber, $_REQUEST["q"], array(
236
          'attributes' => NULL,
237
          'query' => NULL,
238
          'fragment' => $child->otherNode->uuid,
239
        )) . '</div>';
240
      }
241

    
242
      // Link to one or many taxa.
243
      if ($islinkToTaxon || $islinkToManyTaxa) {
244

    
245
        if ($islinkToManyTaxa) {
246
          $taxonChildren = $child->children;
247
        }
248
        else {
249
          $taxonChildren = array(
250
            $child,
251
          );
252
        }
253

    
254
        foreach ($taxonChildren as $taxonChild) {
255
          // TODO many taxa $child->children->taxon.
256
          $out .= '<div class="nodeLinkToTaxon">';
257
          if (isset($taxonChild->modifyingText)) {
258
            $out .= theme('cdm_poytomousKeyNode_modifyingText', array('modifyingText' => $taxonChild->modifyingText));
259
          }
260
          $out .= render_taxon_or_name($taxonChild->taxon->name, url(path_to_taxon($taxonChild->taxon->uuid)));
261
          $out .= '</div>';
262
        }
263

    
264
        // Link to a subkey.
265
        if ($islinkToSubKey) {
266
          $out .= '<div class="nodeLinkToSubkey">' . theme('cdm_IdentificationKey', array('identificationKey' => $child->subkey)) . '</div>';
267
        }
268
      }
269

    
270
      $out .= '</div>'; // End node link.
271
      $out .= '</td>'; // End edge.
272
      $out .= '</tr>';
273

    
274
      $childIndex++;
275
    }
276

    
277
    // Recurse into child nodes.
278
    foreach ($polytomousKeyNode->children as &$child) {
279
      $out .= theme('cdm_polytomousKey_linkedStyle_subgraph', array('polytomousKeyNode' => $child));
280
    }
281
  }
282

    
283
  return $out;
284
}
285

    
286
/**
287
 * @todo Please document this function.
288
 * @see http://drupal.org/node/1354
289
 */
290
function theme_cdm_poytomousKeyNode_modifyingText($variables) {
291
  $out = '';
292
  $modifyingText = $variables['modifyingText'];
293
  if (is_object($modifyingText)) {
294
    $i = 0;
295
    foreach (get_object_vars($modifyingText) as $lang => $languageString) {
296
      $out .= ($i++ > 0 ? ', ' : '') . '<span class="modifyingText">' . $languageString->text . '</span> ';
297
    }
298
  }
299
  return $out;
300
}
301

    
302
/**
303
 * Returns HTML for a list of a specific type of IdentificationKeys.
304
 *
305
 * The list can be restricteded by a taxon.
306
 *
307
 * @param array $variables
308
 *   An associative array containing:
309
 *   - type: The simple name of the cdm class implementing the interface
310
 *     IdentificationKey, valid values are:
311
 *     PolytomousKey, MediaKey, MultiAccessKey
312
 *   - taxonUuid: If given, this parameter restrict the listed keys to those
313
 *     which have the taxon identified be this uuid in scope.
314
 *
315
 * @ingroup themeable
316
 */
317
function theme_cdm_list_IdentificationKeys($variables) {
318
  $type = $variables['type'];
319
  $taxonUuid = $variables['taxonUuid'];
320
  $keyList = _list_IdentificationKeys($type, $taxonUuid);
321
  if (!$keyList || count($keyList) == 0) {
322
    return;
323
  }
324

    
325
  RenderHints::pushToRenderStack('list_IdentificationKeys');
326
  $out = '<ul>';
327
  foreach ($keyList as $key) {
328
    $out .= '<li>';
329
    $out .= theme('cdm_IdentificationKey', array('identificationKey' => $key));
330
    $out .= '</li>';
331
  }
332
  $out .= '</ul>';
333
  $out .= theme("cdm_annotation_footnotes", array('footnoteListKey' => RenderHints::getRenderPath()));
334
  RenderHints::popFromRenderStack();
335

    
336
  return $out;
337
}
338

    
339
/**
340
 * @todo Please document this function.
341
 * @see http://drupal.org/node/1354
342
 */
343
function theme_cdm_block_IdentificationKeys($variables) {
344
  $taxonUuid = $variables['taxonUuid'];
345
  static $types = array(
346
    "PolytomousKey" => "Polytomous",
347
    "MediaKey" => "Media",
348
    "MultiAccessKey" => "Multiaccess",
349
  );
350
  RenderHints::pushToRenderStack('block_IdentificationKeys');
351
  $out = '';
352
  foreach ($types as $type => $label) {
353
    $keylist = theme('cdm_list_IdentificationKeys', array('type' => $type, 'taxonUuid' => $taxonUuid));
354
    if (!$keylist) {
355
      continue;
356
    }
357
    $out .= '<div class="' . $type . '">';
358
    $out .= '<h3>' . t('@label', array('@label' => $label)) . "</h3>";
359
    $out .= $keylist;
360
    $out .= '</div>';
361
  }
362
  RenderHints::popFromRenderStack();
363
  return $out;
364
}
365

    
366
/**
367
 * Composes block of USE_RECORD and USES feature elements for the given TaxonDescriptions.
368
 *
369
 * @param $descriptions
370
 *   The set of TaxonDescriptions
371
 * @param $taxonUuid
372
 *   UUID of the taxon to which the descriptions belong
373
* @return array
374
 *    A Drupal render array
375
 *
376
 * @see cdm_block_use_description_content()
377
 *
378
 * @ingroup compose
379
*/
380
  function compose_feature_block_items_use_records($descriptions, $taxonUuid, $feature) {
381

    
382

    
383
  RenderHints::pushToRenderStack('block_Uses');
384

    
385
  if ($descriptions == NULL) {
386
    return null;
387
  }
388

    
389
  $feature_block_settings = get_feature_block_settings(UUID_USE_RECORD);
390

    
391
  $on_current_taxon = array();
392
  $on_other_taxa = array();
393

    
394
  $currentTaxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $taxonUuid);
395

    
396
  foreach ($descriptions as $description) {
397
    $useSummary = '';
398
    foreach ($description->elements as $element) {
399

    
400
      if ($element->feature->uuid == UUID_USE && !(strlen($useSummary) > 0) && isset($element->multilanguageText_L10n)) {
401
        $useSummary = $element->multilanguageText_L10n->text;
402
      }
403
    }
404
    // uses will be ordered by source
405
    foreach ($description->sources as $description_source) {
406
      $originalTaxonUsedInSource = NULL;
407
      $originalTaxonPager = NULL;
408
      if ($description_source->originalNameString) {
409
        $request_params = array();
410
        $request_params['query'] = $description_source->originalNameString;
411
        $request_params['matchMode'] = "EXACT";
412
        $originalTaxonPager = cdm_ws_get(CDM_WS_PORTAL_NAME_FINDBYNAME, NULL, queryString($request_params));
413
        if ($originalTaxonPager->count > 0) {
414
          $originalTaxonUsedInSource = $originalTaxonPager->records[0];
415
        }
416
        else {
417
          $originalTaxonUsedInSource = $currentTaxon->name;
418
        }
419
      }
420
      else {
421
        $originalTaxonUsedInSource = $currentTaxon->name;
422
      }
423

    
424
      $markup = '<li class="descriptionText DescriptionElement">';
425
      $name_used_in_source_link_to_show_use = l(
426
        $description_source->originalNameString,
427
        path_to_name($originalTaxonUsedInSource->uuid, null, null, true),
428
        array(
429
          'absolute' => TRUE,
430
          'html' => TRUE,
431
        ));
432
      $markup .= $name_used_in_source_link_to_show_use . ': ';
433
      $markup .= $useSummary;
434
      foreach ($description->sources as $element_source) {
435
        $markup .= " (" . render_original_source(
436
            $element_source,
437
            $feature_block_settings['link_to_reference'] == 1,
438
            $feature_block_settings['link_to_name_used_in_source'] == 1) . ")";
439
      }
440
      $hasUseRecords = FALSE;
441
      $descriptionUseRecordOut = '<div class="use-records"><table><th>Use Category</th><th>Use Sub Category</th><th>Plant Part</th><th>Human Group</th><th>Ethnic Group</th><th>Country</th>';
442
      foreach ($description->elements as $descriptionElement) {
443
        if ($descriptionElement->feature->uuid == UUID_USE_RECORD) {
444
          $hasUseRecords = TRUE;
445
          $useRecordTags = explode(';', $descriptionElement->modifyingText_l10n);
446
          $descriptionUseRecordOut .= '<tr>';
447
          $descriptionUseRecordOut .= '<td>' . $useRecordTags[0] . '</td>' . '<td>' . $useRecordTags[1] . '</td>' . '<td>' . $useRecordTags[3] . '</td>' . '<td>' . $useRecordTags[4] . '</td>' . '<td>' . $useRecordTags[5] . '</td>' . '<td>' . $useRecordTags[2] . '</td>';
448
          $descriptionUseRecordOut .= '</tr>';
449
        }
450
      }
451
      $descriptionUseRecordOut .= '</table></div>';
452
      if ($hasUseRecords) {
453
        $markup .= $descriptionUseRecordOut . '</li>';
454
      }
455

    
456
      $is_about_current_taxon_name = $currentTaxon->name->uuid == $originalTaxonUsedInSource->uuid;
457
      if ($is_about_current_taxon_name) {
458
        $on_current_taxon[] = markup_to_render_array($markup);
459
      } else {
460
        $on_other_taxa[] = markup_to_render_array($markup);
461
      }
462

    
463
    }
464
  }
465

    
466
  $render_array = compose_feature_block_wrap_elements(array_merge($on_current_taxon, $on_other_taxa), $feature, $feature_block_settings['glue']);
467

    
468
  RenderHints::popFromRenderStack();
469

    
470
  return $render_array;
471
}
(2-2/9)