Project

General

Profile

Download (7.95 KB) Statistics
| Branch: | Tag: | Revision:
1 aa7c7290 Andreas Kohlbecker
<?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 f19f47fa Andreas Kohlbecker
  if (isset($iModifieable->modifiers)) {
12
    foreach ($iModifieable->modifiers as $modifier) {
13
      $modifiers_strings[] = cdm_term_representation($modifier);
14
    }
15 aa7c7290 Andreas Kohlbecker
  }
16
  return implode(', ', $modifiers_strings);
17 19e097a3 Andreas Kohlbecker
}
18 bf97c2e8 Andreas Kohlbecker
19 19e097a3 Andreas Kohlbecker
/**
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 aa63dfb4 Andreas Kohlbecker
 * @deprecated this is replaced by the cdmlib DistributionUtil class!!!
30 19e097a3 Andreas Kohlbecker
 */
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 ae0a5060 Andreas Kohlbecker
}
52
53 aa63dfb4 Andreas Kohlbecker
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 ae0a5060 Andreas Kohlbecker
/**
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 bf97c2e8 Andreas Kohlbecker
}
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 f19f47fa Andreas Kohlbecker
    if (isset($node->descriptionElements['#type']) || has_feature_node_description_elements($node)) {
113 bf97c2e8 Andreas Kohlbecker
114 f19f47fa Andreas Kohlbecker
      $feature_name = isset($node->feature->representation_L10n) ? $node->feature->representation_L10n : 'Feature';
115
      $class_attributes = 'feature-toc-item-' . $node->feature->uuid;
116 bf97c2e8 Andreas Kohlbecker
      //TODO HACK to implement images for taxa, should be removed.
117
      if ($node->feature->uuid != UUID_IMAGE) {
118 f19f47fa Andreas Kohlbecker
        $items[] = toc_list_item(
119
          theme(
120
            'cdm_feature_name',
121
            array('feature_name' => $feature_name))
122
          ,
123
          array('class' => $class_attributes)
124 bf97c2e8 Andreas Kohlbecker
        );
125
      }
126
    }
127
  }
128
129 1be93be6 Andreas Kohlbecker
  drupal_alter('cdm_feature_node_toc_items', $items);
130 bf97c2e8 Andreas Kohlbecker
131
  return $items;
132 1f11e206 Andreas Kohlbecker
}
133
134 f19f47fa Andreas Kohlbecker
/**
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 1f11e206 Andreas Kohlbecker
/**
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 5b2170ca Andreas Kohlbecker
 * @param $separator
199 22f5e82d Andreas Kohlbecker
 *     Optional parameter. The separator string to concatenate the footnote ids, default is ','
200 6f5c7f2a Andreas Kohlbecker
 * @param $footnote_list_key_suggestion
201 28c5c87a Andreas Kohlbecker
 * @return String
202 22f5e82d Andreas Kohlbecker
 *    The foot note keys
203 1f11e206 Andreas Kohlbecker
 */
204 28c5c87a Andreas Kohlbecker
function cdm_create_description_element_footnotes($description_element, $separator = ',', $footnote_list_key_suggestion = null){
205 1f11e206 Andreas Kohlbecker
206 f19f47fa Andreas Kohlbecker
207 1f11e206 Andreas Kohlbecker
  // Annotations as footnotes.
208 28c5c87a Andreas Kohlbecker
  $footNoteKeys = cdm_annotations_as_footnotekeys($description_element, $footnote_list_key_suggestion);
209 f19f47fa Andreas Kohlbecker
210 1f11e206 Andreas Kohlbecker
  // Source references as footnotes.
211 5611d467 Andreas Kohlbecker
  $bibliography_settings = get_bibliography_settings();
212
  $original_source_footnote_tag = $bibliography_settings['enabled'] == 1 ? 'div' : null; // otherwise the default
213
214 1f11e206 Andreas Kohlbecker
  foreach ($description_element->sources as $source) {
215
    if (_is_original_source_type($source)) {
216 5611d467 Andreas Kohlbecker
      $fn_key = FootnoteManager::addNewFootnote(
217 28c5c87a Andreas Kohlbecker
        original_source_footnote_list_key($footnote_list_key_suggestion),
218 5611d467 Andreas Kohlbecker
        theme('cdm_OriginalSource', array(
219 1f11e206 Andreas Kohlbecker
          'source' => $source,
220
          'doLink' => FALSE,
221 5611d467 Andreas Kohlbecker
        )),
222
        $original_source_footnote_tag
223
      );
224 1f11e206 Andreas Kohlbecker
      // Ensure uniqueness of the footnote keys.
225
      cdm_add_footnote_to_array($footNoteKeys, $fn_key);
226
    }
227
  }
228
  // Sort and render footnote keys.
229
  $footnoteKeyListStr = '';
230
  asort($footNoteKeys);
231
  foreach ($footNoteKeys as $footNoteKey) {
232 6f5c7f2a Andreas Kohlbecker
    $footnoteKeyListStr .= theme('cdm_footnote_key',
233
      array(
234
        'footnoteKey' => $footNoteKey,
235
        'separator' => ($footnoteKeyListStr ? $separator : '')));
236 1f11e206 Andreas Kohlbecker
  }
237
  return $footnoteKeyListStr;
238 aa63dfb4 Andreas Kohlbecker
}
239
240 f19f47fa Andreas Kohlbecker
/**
241
 *
242
 * @return string the footnote_list_key
243
 */
244
function original_source_footnote_list_key($key_suggestion = null) {
245
  if(!$key_suggestion){
246
    $key_suggestion = RenderHints::getFootnoteListKey();
247
  }
248 5611d467 Andreas Kohlbecker
  $bibliography_settings = get_bibliography_settings();
249
  $footnote_list_key = $bibliography_settings['enabled'] == 1 ? 'BIBLIOGRAPHY' : $key_suggestion;
250 f19f47fa Andreas Kohlbecker
  return $footnote_list_key;
251
}