Project

General

Profile

« Previous | Next » 

Revision 1b756c5f

Added by Andreas Kohlbecker about 7 years ago

fix #6392 test for uses and use records and refactoring of the uses feature block

  • fixing wrong assumptions for cyprus
  • bibliography as pseudo feature block better testable

View differences:

modules/cdm_dataportal/theme/cdm_dataportal.descriptions.theme
357 357
}
358 358

  
359 359
/**
360
 * This theming function formats the use description and use record list for
361
 * these descriptions.
360
 * Composes block of USE_RECORD and USES feature elements for the given TaxonDescriptions.
362 361
 *
363
 * @see http://drupal.org/node/1354
364
 */
365
function theme_cdm_UseDescription($variables) {
362
 * @param $descriptions
363
 *   The set of TaxonDescriptions
364
 * @param $taxonUuid
365
 *   UUID of the taxon to which the descriptions belong
366
* @return array
367
 *    A Drupal render array
368
 *
369
 * @see cdm_block_use_description_content()
370
 *
371
 * @ingroup compose
372
*/
373
  function compose_feature_block_items_use_records($descriptions, $taxonUuid, $feature) {
366 374

  
367 375

  
368 376
  RenderHints::pushToRenderStack('block_Uses');
369 377

  
370
  $descriptions = $variables['description'];
371
  $taxonUuid = $variables['taxonUuid'];
372
  $out = '<ul id="Description" class ="description">';
373 378
  if ($descriptions == NULL) {
374
    return '';
379
    return null;
375 380
  }
376 381

  
377 382
  $feature_block_settings = get_feature_block_settings(UUID_USE_RECORD);
378 383

  
379
  $descriptionSynonyms = '';
380
  $descriptionOut = '';
381
  $synonymOut = '';
384
  $on_current_taxon = array();
385
  $on_other_taxa = array();
386

  
382 387
  $currentTaxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $taxonUuid);
383 388

  
384 389
  foreach ($descriptions as $description) {
......
390 395
      }
391 396
    }
392 397
    // uses will be ordered by source
393
    foreach ($description->sources as $source) {
398
    foreach ($description->sources as $description_source) {
394 399
      $originalTaxonUsedInSource = NULL;
395 400
      $originalTaxonPager = NULL;
396
      if ($source->originalNameString) {
401
      if ($description_source->originalNameString) {
397 402
        $request_params = array();
398
        $request_params['query'] = $source->originalNameString;
403
        $request_params['query'] = $description_source->originalNameString;
399 404
        $request_params['matchMode'] = "EXACT";
400 405
        $originalTaxonPager = cdm_ws_get(CDM_WS_PORTAL_NAME_FINDBYNAME, NULL, queryString($request_params));
401 406
        if ($originalTaxonPager->count > 0) {
......
409 414
        $originalTaxonUsedInSource = $currentTaxon->name;
410 415
      }
411 416

  
412
      $is_about_current_taxon = $currentTaxon->name->uuid == $originalTaxonUsedInSource->uuid;
413

  
414
      if (!$is_about_current_taxon) {
415
        $descriptionOut .= '<li class="descriptionText DescriptionElement">';
416
        $name_used_in_source_link_to_show_use = l($source->originalNameString, path_to_name($originalTaxonUsedInSource->uuid), array(
417
          'absolute' => TRUE,
418
          'html' => TRUE,
419
        ));
420
        $descriptionOut .= $name_used_in_source_link_to_show_use . ': ';
421
        $descriptionOut .= $useSummary;
422
        foreach ($description->sources as $source) {
423
          $descriptionOut .= " (" . theme('cdm_OriginalSource', array(
424
              'source' => $source,
425
              'doLink' => $feature_block_settings['link_to_reference'] == 1,
426
              'do_link_to_name_used_in_source' => $feature_block_settings['link_to_name_used_in_source'] == 1)) . ")";
427
        }
428
        $hasUseRecords = FALSE;
429
        $descriptionUseRecordOut = '<div id=useRecords><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>';
430
        foreach ($description->elements as $descriptionElement) {
431
          if ($descriptionElement->feature->uuid == UUID_USE_RECORD) {
432
            $hasUseRecords = TRUE;
433
            // FIXME localization hardcoded to English
434
            $useRecordTags = explode(';', $descriptionElement->modifyingText_l10n);
435
            $descriptionUseRecordOut .= '<tr>';
436
            $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>';
437
            $descriptionUseRecordOut .= '</tr>';
438
          }
439
        }
440
        $descriptionUseRecordOut .= '</table></div>';
441
        if ($hasUseRecords) {
442
          $descriptionOut .= $descriptionUseRecordOut . '</li>';
443
        }
417
      $markup = '<li class="descriptionText DescriptionElement">';
418
      $name_used_in_source_link_to_show_use = l($description_source->originalNameString, path_to_name($originalTaxonUsedInSource->uuid), array(
419
        'absolute' => TRUE,
420
        'html' => TRUE,
421
      ));
422
      $markup .= $name_used_in_source_link_to_show_use . ': ';
423
      $markup .= $useSummary;
424
      foreach ($description->sources as $element_source) {
425
        $markup .= " (" . theme('cdm_OriginalSource', array(
426
            'source' => $element_source,
427
            'doLink' => $feature_block_settings['link_to_reference'] == 1,
428
            'do_link_to_name_used_in_source' => $feature_block_settings['link_to_name_used_in_source'] == 1)) . ")";
444 429
      }
445
      else {
446
        // TODO +/- duplicate of above, unify this code
447
        $synonymOut .= '<li class="descriptionText DescriptionElement">';
448
        $name_used_in_source_link_to_show_use = l($source->originalNameString, path_to_name($originalTaxonUsedInSource->uuid), array(
449
          'absolute' => TRUE,
450
          'html' => TRUE,
451
        ));
452

  
453
        $synonymOut .= $name_used_in_source_link_to_show_use . ': ';
454
        $synonymOut .= $useSummary;
455
        foreach ($description->sources as $source) {
456
          $synonymOut .= " (" . theme('cdm_OriginalSource', array(
457
              'source' => $source,
458
              'doLink' => $feature_block_settings['link_to_reference'] == 1,
459
              'do_link_to_name_used_in_source' => $feature_block_settings['link_to_name_used_in_source'] == 1
460
            )) . ")";
430
      $hasUseRecords = FALSE;
431
      $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>';
432
      foreach ($description->elements as $descriptionElement) {
433
        if ($descriptionElement->feature->uuid == UUID_USE_RECORD) {
434
          $hasUseRecords = TRUE;
435
          $useRecordTags = explode(';', $descriptionElement->modifyingText_l10n);
436
          $descriptionUseRecordOut .= '<tr>';
437
          $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>';
438
          $descriptionUseRecordOut .= '</tr>';
461 439
        }
440
      }
441
      $descriptionUseRecordOut .= '</table></div>';
442
      if ($hasUseRecords) {
443
        $markup .= $descriptionUseRecordOut . '</li>';
444
      }
462 445

  
463
        $hasUseRecords = FALSE;
464
        $useRecordTableOut = '<div id=useRecords><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>';
465
        foreach ($description->elements as $descriptionElement) {
466
          if ($descriptionElement->feature->uuid == UUID_USE_RECORD) {
467
            $hasUseRecords = TRUE;
468
            $useRecordTags = explode(';', $descriptionElement->modifyingText_l10n);
469
            $useRecordTableOut .= '<tr>';
470
            $useRecordTableOut .= '<td>' . $useRecordTags[0] . '</td>' . '<td>' . $useRecordTags[1] . '</td>' . '<td>' . $useRecordTags[3] . '</td>' . '<td>' . $useRecordTags[4] . '</td>' . '<td>' . $useRecordTags[5] . '</td>' . '<td>' . $useRecordTags[2] . '</td>';
471
            $useRecordTableOut .= '</tr>';
472
          }
473
        }
474
        $useRecordTableOut .= '</table></div>';
475
        if ($hasUseRecords) {
476
          $synonymOut .= $useRecordTableOut . '</li>';
477
        }
446
      $is_about_current_taxon_name = $currentTaxon->name->uuid == $originalTaxonUsedInSource->uuid;
447
      if ($is_about_current_taxon_name) {
448
        $on_current_taxon[] = markup_to_render_array($markup);
449
      } else {
450
        $on_other_taxa[] = markup_to_render_array($markup);
478 451
      }
479 452

  
480
      // }
481 453
    }
482 454
  }
483
  $out .= $descriptionOut . $synonymOut;
484
  $out .= "</ul></div>";
455

  
456
  $render_array = compose_feature_block_wrap_elements(array_merge($on_current_taxon, $on_other_taxa), $feature);
485 457

  
486 458
  RenderHints::popFromRenderStack();
487 459

  
488
  return $out;
460
  return $render_array;
489 461
}

Also available in: Unified diff