Project

General

Profile

Download (15.6 KB) Statistics
| Branch: | Tag: | Revision:
1 6657531f Andreas Kohlbecker
<?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 0c432a94 Andreas Kohlbecker
 * Theme function to alter the feature representation.
19
 *
20 4f8e61ad Andreas Kohlbecker
 * It is highly questionable if this function should be completely removed.
21 0c432a94 Andreas Kohlbecker
 * If a feature needs a different representation this should be edited directly
22 4f8e61ad Andreas Kohlbecker
 * in the cdm data but it should not be tweaked like this in the portal.
23 0c432a94 Andreas Kohlbecker
 *
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 6657531f Andreas Kohlbecker
 */
33
function theme_cdm_feature_name($variables) {
34
  $feature_name = $variables['feature_name'];
35 7cc085da Andreas Kohlbecker
  return t('@feature-name', array('@feature-name' => $feature_name));
36 6657531f Andreas Kohlbecker
}
37
38 28c5c87a Andreas Kohlbecker
39 08ced6af Andreas Kohlbecker
/**
40 c3a41ddb Andreas Kohlbecker
 * 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 6657531f Andreas Kohlbecker
 */
45 c3a41ddb Andreas Kohlbecker
function render_feature_tree_hierarchy($feature_tree_uuid, $show_weight = FALSE) {
46 6657531f Andreas Kohlbecker
47 08ced6af Andreas Kohlbecker
  if (!is_uuid($feature_tree_uuid)) {
48
    return NULL;
49 6657531f Andreas Kohlbecker
  }
50
51
  $out = '';
52 9dddc68a Andreas Kohlbecker
  $feature_tree = cdm_ws_get(CDM_WS_TERMTREE,
53 08ced6af Andreas Kohlbecker
    array(
54
      $feature_tree_uuid,
55
    )
56
  );
57 6657531f Andreas Kohlbecker
58 08ced6af Andreas Kohlbecker
  if (isset($feature_tree) && isset($feature_tree->root)) {
59
    $out = '<ul class="' . $feature_tree->class . '">';
60 c3a41ddb Andreas Kohlbecker
    $out .= render_feature_tree_hierarchy_children($feature_tree->root, $show_weight);
61 6657531f Andreas Kohlbecker
    $out .= '</ul>';
62
  }
63
  return $out;
64
}
65
66
/**
67 c3a41ddb Andreas Kohlbecker
 * 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 6657531f Andreas Kohlbecker
 */
73 c3a41ddb Andreas Kohlbecker
function render_feature_tree_hierarchy_children($feature_node, $show_weight = FALSE) {
74 6657531f Andreas Kohlbecker
75
  $out = '';
76 c3a41ddb Andreas Kohlbecker
  $item_index = 0;
77 b011743c Andreas Kohlbecker
  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 c3a41ddb Andreas Kohlbecker
      if($show_weight){
81
        $out .= ' [' .$item_index . ']';
82
      }
83 b011743c Andreas Kohlbecker
      if (isset($child_feature_node->childNodes) && count($child_feature_node->childNodes) > 0) {
84 c3a41ddb Andreas Kohlbecker
        $out .= '<ul>' . render_feature_tree_hierarchy_children($child_feature_node, $show_weight) . '</ul>';
85 6657531f Andreas Kohlbecker
      }
86
      $out .= '</li>';
87 c3a41ddb Andreas Kohlbecker
      $item_index = $item_index + FEATURE_BLOCK_WEIGHT_INCREMENT;
88 6657531f Andreas Kohlbecker
    }
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 c2486c6b Andreas Kohlbecker
    // order and display sources.
115 9e2aa1ff Andreas Kohlbecker
    //TODO can the method handle_annotations_and_sources() be used here?
116 bb93d5d1 Andreas Kohlbecker
    $sources = oder_and_render_original_sources($identificationKey->sources);
117 29809fe3 Andreas Kohlbecker
    $out .= '<div class="sources">';
118 c2486c6b Andreas Kohlbecker
    $out .=  implode('', $sources);
119 6657531f Andreas Kohlbecker
    $out .= '</div>';
120
  }
121
  // Display annotations.
122 e9cc637a Andreas Kohlbecker
  $out .= cdm_annotations(cdm_fetch_visible_annotations($identificationKey),'div');
123 6657531f Andreas Kohlbecker
  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 de017852 Andreas Kohlbecker
      $islinkToManyTaxa = !isset($child->children[0]->statement) && isset($child->children[0]->taxon->uuid);
176 6657531f Andreas Kohlbecker
      $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 32dccd76 Andreas Kohlbecker
      $hasQuestion = !empty($polytomousKeyNode->question->label_l10n);
182 6657531f Andreas Kohlbecker
      $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 1a2294c8 Andreas Kohlbecker
        if (isset($child->modifyingText)) {
220 6657531f Andreas Kohlbecker
          $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 1a2294c8 Andreas Kohlbecker
        if (isset($child->modifyingText)) {
233 6657531f Andreas Kohlbecker
          $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 1a2294c8 Andreas Kohlbecker
          if (isset($taxonChild->modifyingText)) {
258 6657531f Andreas Kohlbecker
            $out .= theme('cdm_poytomousKeyNode_modifyingText', array('modifyingText' => $taxonChild->modifyingText));
259
          }
260 63c3ac73 Andreas Kohlbecker
          $out .= render_taxon_or_name($taxonChild->taxon->name, url(path_to_taxon($taxonChild->taxon->uuid)));
261 6657531f Andreas Kohlbecker
          $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 f95bf1b1 Andreas Kohlbecker
  $out .= cdm_annotation_footnotes(RenderHints::getRenderPath());
334 6657531f Andreas Kohlbecker
  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 7cc085da Andreas Kohlbecker
    $out .= '<h3>' . t('@label', array('@label' => $label)) . "</h3>";
359 6657531f Andreas Kohlbecker
    $out .= $keylist;
360
    $out .= '</div>';
361
  }
362
  RenderHints::popFromRenderStack();
363
  return $out;
364
}
365
366
/**
367 1b756c5f Andreas Kohlbecker
 * Composes block of USE_RECORD and USES feature elements for the given TaxonDescriptions.
368 ae0a5060 Andreas Kohlbecker
 *
369 1b756c5f Andreas Kohlbecker
 * @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 4feafea8 Andreas Kohlbecker
382
383
  RenderHints::pushToRenderStack('block_Uses');
384
385 6657531f Andreas Kohlbecker
  if ($descriptions == NULL) {
386 1b756c5f Andreas Kohlbecker
    return null;
387 6657531f Andreas Kohlbecker
  }
388 bb3188cb Andreas Kohlbecker
389 d192702d Andreas Kohlbecker
  $feature_block_settings = get_feature_block_settings(UUID_USE_RECORD);
390 bb3188cb Andreas Kohlbecker
391 1b756c5f Andreas Kohlbecker
  $on_current_taxon = array();
392
  $on_other_taxa = array();
393
394 6657531f Andreas Kohlbecker
  $currentTaxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $taxonUuid);
395
396
  foreach ($descriptions as $description) {
397 3daa3743 Andreas Kohlbecker
    $useSummary = '';
398 6657531f Andreas Kohlbecker
    foreach ($description->elements as $element) {
399
400 3a5d0703 Andreas Kohlbecker
      if ($element->feature->uuid == UUID_USE && !(strlen($useSummary) > 0) && isset($element->multilanguageText_L10n)) {
401 6657531f Andreas Kohlbecker
        $useSummary = $element->multilanguageText_L10n->text;
402
      }
403
    }
404 3445600f Andreas Kohlbecker
    // uses will be ordered by source
405 1b756c5f Andreas Kohlbecker
    foreach ($description->sources as $description_source) {
406 6657531f Andreas Kohlbecker
      $originalTaxonUsedInSource = NULL;
407
      $originalTaxonPager = NULL;
408 1b756c5f Andreas Kohlbecker
      if ($description_source->originalNameString) {
409 6657531f Andreas Kohlbecker
        $request_params = array();
410 1b756c5f Andreas Kohlbecker
        $request_params['query'] = $description_source->originalNameString;
411 6657531f Andreas Kohlbecker
        $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 1b756c5f Andreas Kohlbecker
      $markup = '<li class="descriptionText DescriptionElement">';
425 2f65af04 Andreas Kohlbecker
      $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 1b756c5f Andreas Kohlbecker
      $markup .= $name_used_in_source_link_to_show_use . ': ';
433
      $markup .= $useSummary;
434
      foreach ($description->sources as $element_source) {
435 bb93d5d1 Andreas Kohlbecker
        $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 6657531f Andreas Kohlbecker
      }
440 1b756c5f Andreas Kohlbecker
      $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 6657531f Andreas Kohlbecker
        }
450 1b756c5f Andreas Kohlbecker
      }
451
      $descriptionUseRecordOut .= '</table></div>';
452
      if ($hasUseRecords) {
453
        $markup .= $descriptionUseRecordOut . '</li>';
454
      }
455 6657531f Andreas Kohlbecker
456 1b756c5f Andreas Kohlbecker
      $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 6657531f Andreas Kohlbecker
      }
462
463
    }
464
  }
465 1b756c5f Andreas Kohlbecker
466 b9e9f59b Andreas Kohlbecker
  $render_array = compose_feature_block_wrap_elements(array_merge($on_current_taxon, $on_other_taxa), $feature, $feature_block_settings['glue']);
467 4feafea8 Andreas Kohlbecker
468
  RenderHints::popFromRenderStack();
469
470 1b756c5f Andreas Kohlbecker
  return $render_array;
471 6657531f Andreas Kohlbecker
}