Project

General

Profile

Download (7.9 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2

    
3
/**
4
 * Returns the localized representations of the modifiers hold by the supplied cdm instance concatenated into one string.
5
 *
6
 * @param object $iModifieable
7
 *   cdm instance of an class implementing the interface IModifieable: DescriptionElementBase, StateDate, State
8
 */
9
function cdm_modifers_representations($iModifieable, $glue = ', ') {
10
  $modifiers_strings = array();
11
  if (isset($iModifieable->modifiers)) {
12
    foreach ($iModifieable->modifiers as $modifier) {
13
      $modifiers_strings[] = cdm_term_representation($modifier);
14
    }
15
  }
16
  return implode(', ', $modifiers_strings);
17
}
18

    
19
/**
20
 * Filters the given set of description elements and prefers computed elements over
21
 * others. Computed description elements are identified by the MarkerType.COMPUTED()
22
 *
23
 * If the given set contains at least one computed element only the computed elements
24
 * returned.
25
 *
26
 * @param $description_elements
27
 *   An array of CDM DescriptionElementBase instances
28
 * @return only the computed description elements otherwise all others.
29
 * @deprecated this is replaced by the cdmlib DistributionUtil class!!!
30
 */
31
function cdm_description_elements_prefer_computed($description_elements){
32

    
33
  $computed_elements = array();
34
  $other_elements = array();
35

    
36
  if(!empty($description_elements)){
37
    foreach ($description_elements as $element) {
38
      if(cdm_entity_has_marker($element, UUID_MARKERTYPE_COMPUTED)){
39
        $computed_elements[] = $element;
40
      } else {
41
        $other_elements[] = $element;
42
      }
43
    }
44
  }
45

    
46
  if(count($computed_elements) > 0) {
47
    return $computed_elements;
48
  } else {
49
    return $other_elements;
50
  }
51
}
52

    
53
function cdm_distribution_filter_query(){
54
  $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
55
  $query = array();
56

    
57
  if($cdm_distribution_filter['filter_rules']['statusOrderPreference']){
58
    $query['statusOrderPreference'] = 1;
59
  }
60
  if($cdm_distribution_filter['filter_rules']['subAreaPreference']){
61
    $query['subAreaPreference'] = 1;
62
  }
63
  if(is_array($cdm_distribution_filter['hideMarkedAreas']) && count($cdm_distribution_filter['hideMarkedAreas']) > 0){
64
    $query['hideMarkedAreas'] = '';
65
    foreach ($cdm_distribution_filter['hideMarkedAreas'] as $marker_type => $enabled)
66
      if($enabled){
67
        $query['hideMarkedAreas'] .= ($query['hideMarkedAreas'] ? ',' : '') . $marker_type;
68
      }
69
  }
70

    
71
  return $query;
72
}
73

    
74
/**
75
 * Merge the fields 'annotations', 'markers', 'sources', 'media' from the source CDM DescriptionElement into  the target.
76
 *
77
 * @param $target
78
 *     The source CDM DescriptionElement
79
 * @param $source
80
 *     The target CDM DescriptionElement
81
 */
82
function cdm_merge_description_elements(&$target, &$source){
83
  static $fields_to_merge = array('annotations', 'markers', 'sources', 'media');
84

    
85
  foreach ($fields_to_merge as $field){
86
    if(is_array($source->$field)) {
87
      if(!is_array($target->$field)){
88
        $target->$field = $source->$field;
89
      } else {
90
        $target->$field = array_merge($target->$field, $source->$field);
91
      }
92
    }
93
  }
94
}
95

    
96
/**
97
 * Prepares the items for a table of content list.
98
 *
99
 * see also hook_cdm_feature_node_toc_items_alter()
100
 *
101
 * @param $feature_nodes
102
 *   An array of CDM FeatureNode instances
103
 *
104
 * @return array
105
 *   The items array is an array suitable for theme_item_list().
106
 */
107
function cdm_feature_node_toc_items($feature_nodes) {
108
  $items = array();
109

    
110
  foreach ($feature_nodes as $node) {
111

    
112
    if (isset($node->descriptionElements['#type']) || has_feature_node_description_elements($node)) {
113

    
114
      $feature_name = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
115
      $class_attributes = 'feature-toc-item-' . $node->feature->uuid;
116
      //TODO HACK to implement images for taxa, should be removed.
117
      if ($node->feature->uuid != UUID_IMAGE) {
118
        $items[] = toc_list_item(
119
          theme(
120
            'cdm_feature_name',
121
            array('feature_name' => $feature_name))
122
          ,
123
          array('class' => $class_attributes)
124
        );
125
      }
126
    }
127
  }
128

    
129
  drupal_alter('cdm_feature_node_toc_items', $items);
130

    
131
  return $items;
132
}
133

    
134
/**
135
 * Prepares an empty Drupal block for displaying description elements of a specific CDM Feature.
136
 *
137
 * The block can also be used for pseudo Features like a bibliography. Pseudo features are
138
 * derived from other data on the fly and so not exist as such in the cdm data. In case
139
 * of pseudo features the $feature is left empty
140
 *
141
 * @param $feature_name
142
 *    A label describing the feature, usually the localized feature representation.
143
 * @param $feature
144
 *    The CDM Feature for which the block is created. (optional)
145
 * @return object
146
 *    A Drupal block object
147
 */
148
function feature_block($feature_name, $feature = null) {
149
  $block = new stdclass(); // Empty object.
150
  $block->module = 'cdm_dataportal';
151
  $block->delta = generalizeString($feature_name);
152
  $block->region = null;
153
  $block->subject = '<a name="' . $block->delta . '"></a><span class="' . html_class_attribute_ref($feature) . '">'
154
    . theme('cdm_feature_name', array('feature_name' => $feature_name))
155
    . '</span>';
156
  $block->module = "cdm_dataportal-feature";
157
  $block->content = '';
158
  return $block;
159
}
160

    
161
/**
162
 * Creates a list item for a table of content, suitable as data element for a themed list
163
 *
164
 * @see theme_list()
165
 *
166
 * @param $label
167
 * @param $http_request_params
168
 * @param $attributes
169
 * @return array
170
 */
171
function toc_list_item($label, $attributes = array()) {
172

    
173
  // we better cache here since drupal_get_query_parameters has no internal static cache variable
174
  $http_request_params = drupal_static('http_request_params', drupal_get_query_parameters());
175

    
176
  $item =  array(
177
    'data' => l(
178
      $label,
179
      $_GET['q'],
180
      array(
181
        'attributes' => array('class' => array('toc')),
182
        'fragment' => generalizeString($label),
183
        'query' => $http_request_params
184
      )
185
    )
186
  );
187
  $item['attributes'] = $attributes;
188
  return $item;
189
}
190

    
191
/**
192
 * Creates the footnotes for the given CDM DescriptionElement instance.
193
 *
194
 * Footnotes are created for annotatins and original sources.
195
 *
196
 * @param $descriptionElement
197
 *     A CDM DescriptionElement instance
198
 * @param $separator
199
 *     Optional parameter. The separator string to concatenate the footnode ids, default is ','
200
 * @return String
201
 *     the string of foot note keys
202
 */
203
function cdm_create_description_element_footnotes($description_element, $separator = ',', $footnote_list_key_suggestion = null){
204

    
205

    
206
  // Annotations as footnotes.
207
  $footNoteKeys = cdm_annotations_as_footnotekeys($description_element, $footnote_list_key_suggestion);
208

    
209
  // Source references as footnotes.
210
  $bibliography_settings = get_bibliography_settings();
211
  $original_source_footnote_tag = $bibliography_settings['enabled'] == 1 ? 'div' : null; // otherwise the default
212

    
213
  foreach ($description_element->sources as $source) {
214
    if (_is_original_source_type($source)) {
215
      $fn_key = FootnoteManager::addNewFootnote(
216
        original_source_footnote_list_key($footnote_list_key_suggestion),
217
        theme('cdm_OriginalSource', array(
218
          'source' => $source,
219
          'doLink' => FALSE,
220
        )),
221
        $original_source_footnote_tag
222
      );
223
      // Ensure uniqueness of the footnote keys.
224
      cdm_add_footnote_to_array($footNoteKeys, $fn_key);
225
    }
226
  }
227
  // Sort and render footnote keys.
228
  $footnoteKeyListStr = '';
229
  asort($footNoteKeys);
230
  foreach ($footNoteKeys as $footNoteKey) {
231
    $footnoteKeyListStr .= theme('cdm_footnote_key', array('footnoteKey' => $footNoteKey, 'separator' => ($footnoteKeyListStr ? $separator : '')));
232
  }
233
  return $footnoteKeyListStr;
234
}
235

    
236
/**
237
 *
238
 * @return string the footnote_list_key
239
 */
240
function original_source_footnote_list_key($key_suggestion = null) {
241
  if(!$key_suggestion){
242
    $key_suggestion = RenderHints::getFootnoteListKey();
243
  }
244
  $bibliography_settings = get_bibliography_settings();
245
  $footnote_list_key = $bibliography_settings['enabled'] == 1 ? 'BIBLIOGRAPHY' : $key_suggestion;
246
  return $footnote_list_key;
247
}
248

    
(2-2/7)