Project

General

Profile

« Previous | Next » 

Revision 7ef52eac

Added by Andreas Kohlbecker almost 4 years ago

ref #9034 simple agent search page with filter function by query parameter

View differences:

modules/cdm_dataportal/classes/AgentComposeHandler.php
1
<?php
2

  
3
class AgentComposeHandler extends ItemComposeHandler {
4

  
5
  private $enclosing_tag = 'div';
6

  
7
  public function getClassAttributes($item) {
8
    return $this->classAttributes($item);
9
  }
10

  
11
  public function composeItem($item) {
12
    return compose_agent($item, $this->enclosing_tag);
13
  }
14
}
modules/cdm_dataportal/classes/ItemComposeHandler.php
1
<?php
2

  
3

  
4
abstract class ItemComposeHandler {
5

  
6
  abstract public function getClassAttributes($item);
7

  
8
  abstract public function composeItem($item);
9

  
10
  /**
11
   * @param $cdm_entity
12
   * A CDM native entity. In case of DTOs the cdm entity can be substituted by
13
   * TypedEntityReference
14
   *
15
   * @return string
16
   */
17
  protected function classAttributes($cdm_entity) {
18
    return html_class_attribute_ref($cdm_entity);
19
  }
20
}
modules/cdm_dataportal/classes/RegistrationDtoComposeHandler.php
1
<?php
2

  
3
class RegistrationDTOComposeHandler extends ItemComposeHandler {
4

  
5
  public function getClassAttributes($item) {
6
    return $this->classAttributes(new TypedEntityReference("Registration", $item->uuid));
7
  }
8

  
9
  public function composeItem($item) {
10
    return compose_registration_dto_compact($item, 'item-style', 'div');
11
  }
12
}
modules/cdm_dataportal/includes/agent.inc
1
<?php
2

  
3
/**
4
 * Compose a description as a table of Feature<->State
5
 *
6
 * @param $description_uuid
7
 *
8
 * @return array
9
 *    The drupal render array for the page
10
 *
11
 * @ingroup compose
12
 */
13
function compose_agent($agent, $enclosing_tag) {
14

  
15
  $name_details = [];
16
  if($agent->familyName){
17
    $name_details[] = '<span class="label">' . t('Family name') . ': </span>'. $agent->familyName;
18
  }
19
  if($agent->givenName){
20
    $name_details[] = '<span class="label">' . t('Given name') . ': </span>'. $agent->givenName;
21
  }
22
  $details[] = join(', ', $name_details);
23
  if($details[0]) {
24
    $details[0] = ' (' . $details[0] . ')';
25
  }
26
  if($agent->lifespan){
27
    // as first element after the titleCache
28
    $lifespan_text = timePeriodToString($agent->lifespan);
29
    if($lifespan_text){
30
      array_unshift($details, ", " . $lifespan_text);
31
    }
32
  }
33
  // FIXME:-------------------------------
34
  // 7d1a269b-9bdd-44eb-beba-2f8acee941af is the phycobank specific ext type for "Life span" which will become obsolte!!!!
35
  if(isset($visible_extensions_sorted['7d1a269b-9bdd-44eb-beba-2f8acee941af'])){
36
    // as first element after the titleCache
37
    array_unshift($details, ", " . $visible_extensions_sorted['7d1a269b-9bdd-44eb-beba-2f8acee941af'][0]->value);
38
    unset($visible_extensions_sorted['7d1a269b-9bdd-44eb-beba-2f8acee941af']);
39
  }
40
  // ------------------------------------
41
  // extensions
42
  $visible_extensions_sorted = visible_extensions_sorted($agent);
43
  $extensions = [];
44
  foreach ($visible_extensions_sorted as $type_uuid => $exts){
45
    foreach ($exts as $ext){
46
      if($ext->value){
47
        $extensions[] = '<span class="label">' . $ext->type->representation_L10n . ': </span>'. $ext->value;
48
      }
49
    }
50
  }
51
  $extensions_markup = join(', ', $extensions);
52
  if($extensions_markup){
53
    $details[] = $extensions_markup;
54
  }
55

  
56
  // IDs as last
57
  if(isset($agent->orcid)){
58
    $corcid_id = number_format($agent->orcid->digitsOnly, 0, '.', '-');
59
    $details[] = l('https://orcid.org/' . $corcid_id, 'https://orcid.org/' . $corcid_id);
60
  }
61
  if($agent->identifiers){
62
    $identifiers_render_array = compose_identifiers($agent->identifiers);
63
    $details[] = drupal_render($identifiers_render_array);
64
  }
65

  
66
  $details_markup = join(' ', $details);
67

  
68
  $render_array = markup_to_render_array($agent->titleCache . $details_markup, null, '<' . $enclosing_tag . ' class="' . html_class_attribute_ref($agent) . '">', '</' . $enclosing_tag . '>');
69

  
70
  return $render_array;
71
}

Also available in: Unified diff