Project

General

Profile

Download (3.32 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/**
3
 * @file
4
 * Extensions to the cdm dataportal module specific for the Palmweb project
5
 *
6
 * @copyright
7
 *   (C) 2016 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
 * @author
16
 *   - Andreas Kohlbecker <a.kohlbecker@BGBM.org>
17
 */
18

    
19

    
20
/**
21
 * Implements hook_block_info().
22
 */
23
function phycobank_block_info() {
24

    
25
  // $block[0]["info"] = t("CDM DataPortal DevLinks");
26
  // $block[1]["info"] = t("CDM DataPortal Credits");
27
  $block['registration_data'] = array(
28
    'info' => t('Phycobank - Registration data'),
29
    'cache' => DRUPAL_NO_CACHE,
30
    'visibility' => BLOCK_VISIBILITY_LISTED,
31
    'pages' => "cdm_dataportal/taxon/*"
32
  );
33

    
34
  return $block;
35
}
36

    
37
/**
38
 * Implements hook_block_view().
39
 */
40
function phycobank_block_view($delta)
41
{
42
  switch ($delta) {
43
    // case 'delta-1':
44
    // $block['subject'] = t('Credits');
45
    // $block['content'] = theme('cdm_credits');
46
    // return $block;
47
    case 'registration_data':
48
      $block['subject'] = t('Registration data');
49
      $block['content'] = phycobank_registration_data();
50
      return $block;
51
      break;
52
  }
53
}
54

    
55
function phycobank_registration_data(){
56

    
57
  if(! (arg(0) == 'cdm_dataportal' && arg(1) == 'taxon' &&  is_uuid(arg(2))) ) {
58
    return markup_to_render_array("<span class='error'>This block can only be used on cdm_dataportal/taxon/* pages. Please check the block settings.</span>");
59
  }
60
  $rows = array();
61
  $taxon_uuid = arg(2);
62
  $taxon = cdm_ws_get(CDM_WS_PORTAL_TAXON, $taxon_uuid);
63

    
64
  // read registrations
65
  $registrations = cdm_ws_get(CDM_WS_NAME . '/' . $taxon->name->uuid . '/registrations');
66
  if($registrations && count($registrations) > 0){
67
    foreach($registrations as $reg){
68
      if($reg->status == "PUBLISHED" && strpos($reg->identifier, "http://phycobank.org") == 0) {
69
        $rows[] = array(
70
          'data' => array('ID:', $reg->identifier),
71
          'no_striping' => true
72
        );
73
        $rows[] = array(
74
          'data' => array('Date:', preg_replace('/^([^T]*)(.*)$/', '${1}', $reg->registrationDate)),
75
          'no_striping' => true
76
        );
77
        if(isset($reg->institution->titleCache)){
78
          $rows[] = array(
79
            'data' => array('Office:', $reg->institution->titleCache),
80

    
81
            'no_striping' => true
82
          );
83
        }
84
        break;
85
      }
86
    }
87

    
88
  } else {
89
    // read extensions
90
    $extensions = cdm_ws_get(CDM_WS_NAME . '/' . $taxon->name->uuid . '/extensions');
91

    
92
    if(isset($extensions->records[0])){
93
      $data = json_decode($extensions->records[0]->value);
94

    
95
      $rows[] = array(
96
        'data' => array('ID:', $data->regId),
97
        'no_striping' => true
98
      );
99
      $rows[] = array(
100
        'data' => array('Date:', preg_replace('/^(.*?\.)(97|98|99)$/', '${1}19$2', $data->date)),
101
          'no_striping' => true
102
        );
103
      $rows[] = array(
104
        'data' => array('Office:', $data->office),
105
        'no_striping' => true
106
      );
107
      if(isset($data->formNumber)) {
108
        $rows[] = array(
109
          'data' => array('Form number', $data->formNumber),
110
          'no_striping' => true
111
        );
112
      }
113
    }
114

    
115
  }
116
  if(count($rows) > 0){
117
    $data_elements = array(
118
      '#theme' => 'table',
119
      '#rows' => $rows,
120
    );
121
    return $data_elements;
122
  }
123
}
(2-2/2)