Project

General

Profile

Download (15.7 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 a9a297f6 Andreas Kohlbecker
 * 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 6657531f Andreas Kohlbecker
 */
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 de017852 Andreas Kohlbecker
      $islinkToManyTaxa = !isset($child->children[0]->statement) && isset($child->children[0]->taxon->uuid);
179 6657531f Andreas Kohlbecker
      $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 32dccd76 Andreas Kohlbecker
      $hasQuestion = !empty($polytomousKeyNode->question->label_l10n);
185 6657531f Andreas Kohlbecker
      $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 1a2294c8 Andreas Kohlbecker
        if (isset($child->modifyingText)) {
223 6657531f Andreas Kohlbecker
          $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 1a2294c8 Andreas Kohlbecker
        if (isset($child->modifyingText)) {
236 6657531f Andreas Kohlbecker
          $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 1a2294c8 Andreas Kohlbecker
          if (isset($taxonChild->modifyingText)) {
261 6657531f Andreas Kohlbecker
            $out .= theme('cdm_poytomousKeyNode_modifyingText', array('modifyingText' => $taxonChild->modifyingText));
262
          }
263 63c3ac73 Andreas Kohlbecker
          $out .= render_taxon_or_name($taxonChild->taxon->name, url(path_to_taxon($taxonChild->taxon->uuid)));
264 6657531f Andreas Kohlbecker
          $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 d0d0a092 Andreas Kohlbecker
  $out .= render_footnotes(RenderHints::getRenderPath());
337 6657531f Andreas Kohlbecker
  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 7cc085da Andreas Kohlbecker
    $out .= '<h3>' . t('@label', array('@label' => $label)) . "</h3>";
362 6657531f Andreas Kohlbecker
    $out .= $keylist;
363
    $out .= '</div>';
364
  }
365
  RenderHints::popFromRenderStack();
366
  return $out;
367
}
368
369
/**
370 1b756c5f Andreas Kohlbecker
 * Composes block of USE_RECORD and USES feature elements for the given TaxonDescriptions.
371 ae0a5060 Andreas Kohlbecker
 *
372 1b756c5f Andreas Kohlbecker
 * @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 4feafea8 Andreas Kohlbecker
385
386
  RenderHints::pushToRenderStack('block_Uses');
387
388 6657531f Andreas Kohlbecker
  if ($descriptions == NULL) {
389 1b756c5f Andreas Kohlbecker
    return null;
390 6657531f Andreas Kohlbecker
  }
391 bb3188cb Andreas Kohlbecker
392 d192702d Andreas Kohlbecker
  $feature_block_settings = get_feature_block_settings(UUID_USE_RECORD);
393 bb3188cb Andreas Kohlbecker
394 1b756c5f Andreas Kohlbecker
  $on_current_taxon = array();
395
  $on_other_taxa = array();
396
397 6657531f Andreas Kohlbecker
  $currentTaxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $taxonUuid);
398
399
  foreach ($descriptions as $description) {
400 3daa3743 Andreas Kohlbecker
    $useSummary = '';
401 6657531f Andreas Kohlbecker
    foreach ($description->elements as $element) {
402
403 3a5d0703 Andreas Kohlbecker
      if ($element->feature->uuid == UUID_USE && !(strlen($useSummary) > 0) && isset($element->multilanguageText_L10n)) {
404 6657531f Andreas Kohlbecker
        $useSummary = $element->multilanguageText_L10n->text;
405
      }
406
    }
407 3445600f Andreas Kohlbecker
    // uses will be ordered by source
408 1b756c5f Andreas Kohlbecker
    foreach ($description->sources as $description_source) {
409 6657531f Andreas Kohlbecker
      $originalTaxonUsedInSource = NULL;
410
      $originalTaxonPager = NULL;
411 1b756c5f Andreas Kohlbecker
      if ($description_source->originalNameString) {
412 6657531f Andreas Kohlbecker
        $request_params = array();
413 1b756c5f Andreas Kohlbecker
        $request_params['query'] = $description_source->originalNameString;
414 6657531f Andreas Kohlbecker
        $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 1b756c5f Andreas Kohlbecker
      $markup = '<li class="descriptionText DescriptionElement">';
428 2f65af04 Andreas Kohlbecker
      $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 1b756c5f Andreas Kohlbecker
      $markup .= $name_used_in_source_link_to_show_use . ': ';
436
      $markup .= $useSummary;
437
      foreach ($description->sources as $element_source) {
438 bb93d5d1 Andreas Kohlbecker
        $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 6657531f Andreas Kohlbecker
      }
443 1b756c5f Andreas Kohlbecker
      $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 6657531f Andreas Kohlbecker
        }
453 1b756c5f Andreas Kohlbecker
      }
454
      $descriptionUseRecordOut .= '</table></div>';
455
      if ($hasUseRecords) {
456
        $markup .= $descriptionUseRecordOut . '</li>';
457
      }
458 6657531f Andreas Kohlbecker
459 1b756c5f Andreas Kohlbecker
      $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 6657531f Andreas Kohlbecker
      }
465
466
    }
467
  }
468 1b756c5f Andreas Kohlbecker
469 b9e9f59b Andreas Kohlbecker
  $render_array = compose_feature_block_wrap_elements(array_merge($on_current_taxon, $on_other_taxa), $feature, $feature_block_settings['glue']);
470 4feafea8 Andreas Kohlbecker
471
  RenderHints::popFromRenderStack();
472
473 1b756c5f Andreas Kohlbecker
  return $render_array;
474 6657531f Andreas Kohlbecker
}