Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / modules / cdm_dataportal / theme / cdm_dataportal.descriptions.theme @ a9a297f6

History | View | Annotate | Download (15.7 KB)

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 .= cdm_annotations(cdm_fetch_visible_annotations($identificationKey),'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
 * Theme function for creating a linked style representation for a polytomous key.
150
 * <p>
151
 * The linked style is the only kind of representations implemented so far.
152
 *
153
 * @ingroup theme
154
 */
155
function theme_cdm_polytomousKey_linkedStyle_subgraph($variables) {
156
  $polytomousKeyNode = $variables['polytomousKeyNode'];
157
  static $statementCountCharacter = '\'';
158
  $out = "";
159

    
160
  if (is_array($polytomousKeyNode->children)) {
161
    $childIndex = 0;
162

    
163
    // Render edges of the current node.
164
    foreach ($polytomousKeyNode->children as &$child) {
165

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

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

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

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

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

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

    
208
      // Feature.
209
      if ($hasFeature) {
210
        $out .= $polytomousKeyNode->feature->representation_L10n . ": ";
211
      }
212

    
213
      // Statement.
214
      $out .= $child->statement->label_l10n;
215

    
216
      // --- Links to nodes taxa and subkeys.
217
      $out .= '<div class="nodeLink">';
218

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

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

    
245
      // Link to one or many taxa.
246
      if ($islinkToTaxon || $islinkToManyTaxa) {
247

    
248
        if ($islinkToManyTaxa) {
249
          $taxonChildren = $child->children;
250
        }
251
        else {
252
          $taxonChildren = array(
253
            $child,
254
          );
255
        }
256

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

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

    
273
      $out .= '</div>'; // End node link.
274
      $out .= '</td>'; // End edge.
275
      $out .= '</tr>';
276

    
277
      $childIndex++;
278
    }
279

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

    
286
  return $out;
287
}
288

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

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

    
328
  RenderHints::pushToRenderStack('list_IdentificationKeys');
329
  $out = '<ul>';
330
  foreach ($keyList as $key) {
331
    $out .= '<li>';
332
    $out .= theme('cdm_IdentificationKey', array('identificationKey' => $key));
333
    $out .= '</li>';
334
  }
335
  $out .= '</ul>';
336
  $out .= render_footnotes(RenderHints::getRenderPath());
337
  RenderHints::popFromRenderStack();
338

    
339
  return $out;
340
}
341

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

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

    
385

    
386
  RenderHints::pushToRenderStack('block_Uses');
387

    
388
  if ($descriptions == NULL) {
389
    return null;
390
  }
391

    
392
  $feature_block_settings = get_feature_block_settings(UUID_USE_RECORD);
393

    
394
  $on_current_taxon = array();
395
  $on_other_taxa = array();
396

    
397
  $currentTaxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $taxonUuid);
398

    
399
  foreach ($descriptions as $description) {
400
    $useSummary = '';
401
    foreach ($description->elements as $element) {
402

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

    
427
      $markup = '<li class="descriptionText DescriptionElement">';
428
      $name_used_in_source_link_to_show_use = l(
429
        $description_source->originalNameString,
430
        path_to_name($originalTaxonUsedInSource->uuid, null, null, true),
431
        array(
432
          'absolute' => TRUE,
433
          'html' => TRUE,
434
        ));
435
      $markup .= $name_used_in_source_link_to_show_use . ': ';
436
      $markup .= $useSummary;
437
      foreach ($description->sources as $element_source) {
438
        $markup .= " (" . render_original_source(
439
            $element_source,
440
            $feature_block_settings['link_to_reference'] == 1,
441
            $feature_block_settings['link_to_name_used_in_source'] == 1) . ")";
442
      }
443
      $hasUseRecords = FALSE;
444
      $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>';
445
      foreach ($description->elements as $descriptionElement) {
446
        if ($descriptionElement->feature->uuid == UUID_USE_RECORD) {
447
          $hasUseRecords = TRUE;
448
          $useRecordTags = explode(';', $descriptionElement->modifyingText_l10n);
449
          $descriptionUseRecordOut .= '<tr>';
450
          $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>';
451
          $descriptionUseRecordOut .= '</tr>';
452
        }
453
      }
454
      $descriptionUseRecordOut .= '</table></div>';
455
      if ($hasUseRecords) {
456
        $markup .= $descriptionUseRecordOut . '</li>';
457
      }
458

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

    
466
    }
467
  }
468

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

    
471
  RenderHints::popFromRenderStack();
472

    
473
  return $render_array;
474
}
Add picture from clipboard (Maximum size: 40 MB)