Project

General

Profile

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

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

    
25
  /**
26
   * Filters the given set of description elements and prefers
27
   * computed elements over others. Computed description elements
28
   * are identified by the MarkerType.COMPUTED()
29
   *
30
   * If the given set contains at least one computed element only
31
   * the computed elements are returned.
32
   *
33
   * @param $description_elements
34
   *   An array of CDM DescriptionElementBase instances
35
   *
36
   * @return
37
   *  only the computed description elements otherwise all others.
38
   *
39
   * @deprecated this is replaced by the cdmlib DistributionUtil class!!!
40
   */
41
  function cdm_description_elements_prefer_computed($description_elements){
42

    
43
    $computed_elements = array();
44
    $other_elements = array();
45

    
46
    if(!empty($description_elements)){
47
      foreach ($description_elements as $element) {
48
        if(cdm_entity_has_marker($element, UUID_MARKERTYPE_COMPUTED)){
49
          $computed_elements[] = $element;
50
        } else {
51
          $other_elements[] = $element;
52
        }
53
      }
54
    }
55

    
56
    if(count($computed_elements) > 0) {
57
      return $computed_elements;
58
    } else {
59
      return $other_elements;
60
    }
61
  }
62

    
63
  /**
64
   * @return array
65
   */
66
  function cdm_distribution_filter_query(){
67
    $cdm_distribution_filter = get_array_variable_merged(CDM_DISTRIBUTION_FILTER, CDM_DISTRIBUTION_FILTER_DEFAULT);
68
    $query = array();
69

    
70
    if($cdm_distribution_filter['filter_rules']['statusOrderPreference']){
71
      $query['statusOrderPreference'] = 1;
72
    }
73
    if($cdm_distribution_filter['filter_rules']['subAreaPreference']){
74
      $query['subAreaPreference'] = 1;
75
    }
76
    if(is_array($cdm_distribution_filter['hideMarkedAreas']) && count($cdm_distribution_filter['hideMarkedAreas']) > 0){
77
      $query['hideMarkedAreas'] = '';
78
      foreach ($cdm_distribution_filter['hideMarkedAreas'] as $marker_type => $enabled)
79
        if($enabled){
80
          $query['hideMarkedAreas'] .= ($query['hideMarkedAreas'] ? ',' : '') . $marker_type;
81
        }
82
    }
83

    
84
    return $query;
85
  }
86

    
87
  /**
88
   * Merge the fields 'annotations', 'markers', 'sources', 'media' from the source CDM DescriptionElement into  the target.
89
   *
90
   * @param $target
91
   *     The source CDM DescriptionElement
92
   * @param $source
93
   *     The target CDM DescriptionElement
94
   */
95
  function cdm_merge_description_elements(&$target, &$source){
96
    static $fields_to_merge = array('annotations', 'markers', 'sources', 'media');
97

    
98
    foreach ($fields_to_merge as $field){
99
      if(is_array($source->$field)) {
100
        if(!is_array($target->$field)){
101
          $target->$field = $source->$field;
102
        } else {
103
          $target->$field = array_merge($target->$field, $source->$field);
104
        }
105
      }
106
    }
107
  }
108

    
109
  /**
110
   * Creates a  entry for the table of content items list
111
   *
112
   * The  table of content items are crated internally by calling
113
   * toc_list_item() the resulting item is added to the statically cached
114
   * list of toc elements
115
   *
116
   * @param $label
117
   *  The label of toc entry
118
   * @param $class_attribute_suffix
119
   *  The suffix to be appended to the class attribute prefix: "feature-toc-item-"
120
   * @param $fragment
121
   *  Optional parameter to define a url fragment different from the $label,
122
   *  if the $fragment is not defined the $label will be used
123
   */
124
  function cdm_toc_list_add_item($label, $class_attribute_suffix, $fragment = NULL){
125
    $toc_list_items = &cdm_toc_list();
126

    
127
    // TODO normalize $fragment if necesarry, check uri()
128
    if(!$fragment){
129
      $fragment = $label;
130
    }
131

    
132
    $class_attributes = 'feature-toc-item-' . $class_attribute_suffix;
133

    
134
    $toc_list_items[] = toc_list_item(
135
      theme(
136
        'cdm_feature_name',
137
        array('feature_name' => $label))
138
      ,
139
      array('class' => $class_attributes),
140
      $fragment
141
    );
142

    
143
  }
144

    
145
  /**
146
   * Returns the statically cached table of content items as render array
147
   *
148
   * @see see also cdm_toc_list_add_item()
149
   *
150
   * @return array
151
   *   a render array of table of content items suitable for theme_item_list()
152
   */
153
  function &cdm_toc_list(){
154
    $toc_list_items = &drupal_static('toc_list_items', array());
155

    
156
    return $toc_list_items;
157
  }
158

    
159
/**
160
 * Prepares an empty Drupal block for displaying description elements of a specific CDM Feature.
161
 *
162
 * The block can also be used for pseudo Features like a bibliography. Pseudo features are
163
 * derived from other data on the fly and so not exist as such in the cdm data. In case
164
 * of pseudo features the $feature is left empty
165
 *
166
 * @param $feature_name
167
 *    A label describing the feature, usually the localized feature representation.
168
 * @param $feature
169
 *    The CDM Feature for which the block is created. (optional)
170
 * @return object
171
 *    A Drupal block object
172
 */
173
function feature_block($feature_name, $feature = null) {
174
  $block = new stdclass(); // Empty object.
175
  $block->module = 'cdm_dataportal';
176
  $block->delta = generalizeString($feature_name);
177
  $block->region = null;
178
  $block->subject = '<a name="' . $block->delta . '"></a><span class="' . html_class_attribute_ref($feature) . '">'
179
    . theme('cdm_feature_name', array('feature_name' => $feature_name))
180
    . '</span>';
181
  $block->module = "cdm_dataportal-feature";
182
  $block->content = '';
183
  return $block;
184
}
185

    
186
  /**
187
   * Creates a list item for a table of content, suitable as data element for a themed list
188
   *
189
   * @see theme_list()
190
   *
191
   * @param $label
192
   * @param $http_request_params
193
   * @param $attributes
194
   * @return array
195
   */
196
  function toc_list_item($label, $attributes = array(), $fragment = null) {
197

    
198
    // we better cache here since drupal_get_query_parameters has no internal static cache variable
199
    $http_request_params = drupal_static('http_request_params', drupal_get_query_parameters());
200

    
201
    $item =  array(
202
      'data' => l(
203
        $label,
204
        $_GET['q'],
205
        array(
206
          'attributes' => array('class' => array('toc')),
207
          'fragment' => generalizeString($label),
208
          'query' => $http_request_params
209
        )
210
      )
211
    );
212
    $item['attributes'] = $attributes;
213
    return $item;
214
  }
215

    
216
  /**
217
   * Creates the footnotes for the given CDM DescriptionElement instance.
218
   *
219
   * Footnotes are created for annotatins and original sources.
220
   *
221
   * @param $descriptionElement
222
   *     A CDM DescriptionElement instance
223
   * @param $separator
224
   *     Optional parameter. The separator string to concatenate the footnote ids, default is ','
225
   * @param $footnote_list_key_suggestion
226
   * @return String
227
   *    The foot note keys
228
   */
229
  function cdm_create_description_element_footnotes($description_element, $separator = ',', $footnote_list_key_suggestion = null){
230

    
231

    
232
    // Annotations as footnotes.
233
    $footNoteKeys = cdm_annotations_as_footnotekeys($description_element, $footnote_list_key_suggestion);
234

    
235
    // Source references as footnotes.
236
    $bibliography_settings = get_bibliography_settings();
237
    $original_source_footnote_tag = $bibliography_settings['enabled'] == 1 ? 'div' : null; // otherwise the default
238

    
239
    foreach ($description_element->sources as $source) {
240
      if (_is_original_source_type($source)) {
241
        $fn_key = FootnoteManager::addNewFootnote(
242
          original_source_footnote_list_key($footnote_list_key_suggestion),
243
          theme('cdm_OriginalSource', array(
244
            'source' => $source,
245
            'doLink' => FALSE,
246
          )),
247
          $original_source_footnote_tag
248
        );
249
        // Ensure uniqueness of the footnote keys.
250
        cdm_add_footnote_to_array($footNoteKeys, $fn_key);
251
      }
252
    }
253
    // Sort and render footnote keys.
254
    $footnoteKeyListStr = '';
255
    asort($footNoteKeys);
256
    foreach ($footNoteKeys as $footNoteKey) {
257
      $footnoteKeyListStr .= theme('cdm_footnote_key',
258
        array(
259
          'footnoteKey' => $footNoteKey,
260
          'separator' => ($footnoteKeyListStr ? $separator : '')));
261
    }
262
    return $footnoteKeyListStr;
263
  }
264

    
265
  /**
266
   *
267
   * @return string the footnote_list_key
268
   */
269
  function original_source_footnote_list_key($key_suggestion = null) {
270
    if(!$key_suggestion){
271
      $key_suggestion = RenderHints::getFootnoteListKey();
272
    }
273
    $bibliography_settings = get_bibliography_settings();
274
    $footnote_list_key = $bibliography_settings['enabled'] == 1 ? 'BIBLIOGRAPHY' : $key_suggestion;
275
    return $footnote_list_key;
276
  }
277

    
(2-2/7)