Project

General

Profile

« Previous | Next » 

Revision a6d7907d

Added by Andreas Kohlbecker over 3 years ago

fixing typos and cleaning code

View differences:

modules/cdm_dataportal/includes/descriptions.inc
7 7
 * Returns the localized representations of the modifiers hold by the
8 8
 * supplied cdm instance concatenated into one string.
9 9
 *
10
 * @param object $iModifieable
10
 * @param object $is_modifieable
11 11
 *   cdm instance of an class implementing the interface IModifieable:
12 12
 *   DescriptionElementBase, StateDate, State
13 13
 *
......
15 15
 *   localized representations of the modifiers hold by the
16 16
 *   supplied cdm instance concatenated into one string
17 17
 */
18
function cdm_modifers_representations($iModifieable, $glue = ', ') {
18
function cdm_modifiers_representations($is_modifieable, $glue = ', ') {
19 19
  $modifiers_strings = array();
20
  if (isset($iModifieable->modifiers)) {
21
    foreach ($iModifieable->modifiers as $modifier) {
20
  if (isset($is_modifieable->modifiers)) {
21
    foreach ($is_modifieable->modifiers as $modifier) {
22 22
      $modifiers_strings[] = cdm_term_representation($modifier);
23 23
    }
24 24
  }
......
111 111
 * @param object $source
112 112
 *   The target CDM DescriptionElement
113 113
 */
114
function cdm_merge_description_elements(&$target, &$source) {
114
function cdm_merge_description_elements($target, $source) {
115 115
  static $fields_to_merge = array('annotations', 'markers', 'sources', 'media');
116 116

  
117 117
  foreach ($fields_to_merge as $field) {
......
136 136
 * @param string $label
137 137
 *   The label of toc entry
138 138
 * @param $class_attribute_suffix
139
 *   The suffix to be appended to the class attribute prefix: "feature-toc-item-"
139
 *   The suffix to be appended to the class attribute prefix:
140
 *   "feature-toc-item-"
140 141
 * @param string $fragment
141 142
 *   Optional parameter to define a url fragment different from the $label,
142 143
 *   if the $fragment is not defined the $label will be used
143 144
 * @param boolean $as_first_element
144
 *   Place the new item as fist one. This parameter is ignored when $weight is being set
145
 *   Place the new item as fist one. This parameter is ignored when $weight is
146
 *   being set
145 147
 * @param integer $weight
146 148
 *   Defines the weight for the ordering the item in the toc list.
147 149
 *   The item will be placed at the end if weigth is NULL.
150
 *
151
 * @throws \Exception re-throws exception from theme()
148 152
 */
149 153
function cdm_toc_list_add_item($label, $class_attribute_suffix, $fragment = NULL, $as_first_element = FALSE, $weight = null) {
150 154

  
......
189 193
 *   a render array of table of content items suitable for theme_item_list()
190 194
 */
191 195
function &cdm_toc_list(){
196

  
192 197
  $toc_list_items = &drupal_static('toc_list_items', array());
193 198

  
194 199
  return $toc_list_items;
195 200
}
196 201

  
197 202
/**
198
 * Prepares an empty Drupal block for displaying description elements of a specific CDM Feature.
203
 * Prepares an empty Drupal block for displaying description elements of a
204
 * specific CDM Feature.
199 205
 *
200
 * The block can also be used for pseudo Features like a bibliography. Pseudo features are
201
 * derived from other data on the fly and so not exist as such in the cdm data. For pseudo
202
 * features the $feature can be created using make_pseudo_feature().
206
 * The block can also be used for pseudo Features like a bibliography. Pseudo
207
 * features are derived from other data on the fly and so not exist as such in
208
 * the cdm data. For pseudo features the $feature can be created using
209
 * make_pseudo_feature().
203 210
 *
204 211
 * @param $feature_name
205
 *   A label describing the feature, usually the localized feature representation.
212
 *   A label describing the feature, usually the localized feature
213
 *   representation.
206 214
 * @param object $feature
207 215
 *   The CDM Feature for which the block is created.
216
 *
208 217
 * @return object
209 218
 *   A Drupal block object
219
 *
220
 * @throws \Exception re-throws exception from theme()
210 221
 */
211 222
function feature_block($feature_name, $feature) {
212 223
  $block = new stdclass();
......
245 256
    drupal_set_message(t('Type parameter is missing'), 'error');
246 257
    return;
247 258
  }
248
  $cdm_ws_pasepath = NULL;
259
  $cdm_ws_base_path = NULL;
249 260
  switch ($type) {
250 261
    case "PolytomousKey":
251
      $cdm_ws_pasepath = CDM_WS_POLYTOMOUSKEY;
262
      $cdm_ws_base_path = CDM_WS_POLYTOMOUSKEY;
252 263
      break;
253 264

  
254 265
    case "MediaKey":
255
      $cdm_ws_pasepath = CDM_WS_MEDIAKEY;
266
      $cdm_ws_base_path = CDM_WS_MEDIAKEY;
256 267
      break;
257 268

  
258 269
    case "MultiAccessKey":
259
      $cdm_ws_pasepath = CDM_WS_MULTIACCESSKEY;
270
      $cdm_ws_base_path = CDM_WS_MULTIACCESSKEY;
260 271
      break;
261 272

  
262 273
  }
263 274

  
264
  if (!$cdm_ws_pasepath) {
275
  if (!$cdm_ws_base_path) {
265 276
    drupal_set_message(t('Type parameter is not valid: ') . $type, 'error');
266 277
  }
267 278

  
......
283 294
  if ($taxonUuid) {
284 295
    $queryParameters = "findByTaxonomicScope=$taxonUuid";
285 296
  }
286
  $pager = cdm_ws_get($cdm_ws_pasepath, NULL, $queryParameters);
297
  $pager = cdm_ws_get($cdm_ws_base_path, NULL, $queryParameters);
287 298

  
288 299
  if (!$pager || $pager->count == 0) {
289 300
    return array();
......
338 349
 *       - "BIBLIOGRAPHY-$footnote_list_key_suggestion" (when !$is_bibliography_aware && bibliography_settings['enabled'] == 0 )
339 350
 *       - $footnote_list_key_suggestion (when $is_bibliography_aware)
340 351
 *
341
 * @param $descriptionElement
352
 * @param $description_element
342 353
 *   A CDM DescriptionElement instance
343
 * @param $separator
354
 * @param string $separator
344 355
 *   Optional parameter. The separator string to concatenate the footnote ids, default is ','
345 356
 * @param $footnote_list_key_suggestion string
346 357
 *    Optional parameter. If this parameter is left empty (null, 0, "") the footnote key will be determined by the nested
347 358
 *    method calls by calling RenderHints::getFootnoteListKey(). NOTE: the footnote key for annotations will be set to
348 359
 *    RenderHints::getFootnoteListKey().'-annotations'.
360
 * @param bool $do_link_to_reference
361
 *    Create a link to the reference pages for sources when TRUE.
362
 * @param bool $do_link_to_name_used_in_source
363
 *    Create a link to the name pages for name in source when TRUE.
364
 * @param bool $is_bibliography_aware
365
 *    Put source references into the bibliography when this param is TRUE.
349 366
 *
350 367
 * @return String
351 368
 *   The foot note keys
352 369
 *
370
 * @throws \Exception re-throw exception from theme()
353 371
 * @see cdm_entities_annotations_as_footnotekeys()
354 372
 *    For original sources the $footnote_list_key_suggestion will be overwritten by bibliography_footnote_list_key() when
355 373
 *    $is_bibliography_aware is set TRUE.
356 374
 * @$original_source_footnote_tag
357 375
 *    null will cause bibliography_footnote_list_key to use the default
358
 *
359 376
 */
360 377
function cdm_create_footnotes(
361 378
    $description_element,
......
401 418
  }
402 419
  // Sort and render footnote keys.
403 420
  asort($footnote_keys);
404
  $footnotes_markup = footnote_keys_to_markup($footnote_keys, $separator);
405
  return $footnotes_markup;
421
  return footnote_keys_to_markup($footnote_keys, $separator);
406 422
}
407 423

  
408 424
/**
......
413 429
 *
414 430
 * @return string
415 431
 */
416
function footnote_keys_to_markup(array $footnote_keys, string $separator): string {
432
function footnote_keys_to_markup(array $footnote_keys, $separator) {
417 433

  
418 434
  $footnotes_markup = '';
419 435
  foreach ($footnote_keys as $foot_note_key) {
......
432 448

  
433 449

  
434 450
/**
435
 * Compare callback to be used in usort() to sort render arrays produced by compose_description_element().
451
 * Compare callback to be used in usort() to sort render arrays produced by
452
 * compose_description_element().
436 453
 *
437 454
 * @param $a
438 455
 * @param $b
456
 *
457
 * @return int Returns < 0 if $a['#value'].$a['#value-suffix'] from is less than
458
 * $b['#value'].$b['#value-suffix'], > 0 if it is greater than $b['#value'].$b['#value-suffix'],
459
 * and 0 if they are equal.
439 460
 */
440 461
function compare_description_element_render_arrays($a, $b){
441 462
  if ($a['#value'].$a['#value-suffix'] == $b['#value'].$b['#value-suffix']) {
......
447 468

  
448 469

  
449 470
/**
450
 * @param $render_array
451 471
 * @param $element
452 472
 * @param $feature_block_settings
453 473
 * @param $element_markup
454 474
 * @param $footnote_list_key_suggestion
475
 * @param bool $prepend_feature_label
476
 *
477
 * @return array|null
455 478
 */
456 479
function compose_description_element($element, $feature_block_settings, $element_markup, $footnote_list_key_suggestion, $prepend_feature_label = FALSE)
457 480
{
......
544 567
  return $config;
545 568
}
546 569

  
547
  /**
548
   * @param $entity
549
   * @param $config array
550
   *   An associative array to configure the display of the annotations and sources.
551
   *   The array has the following keys
552
   *   - sources_as_content
553
   *   - link_to_name_used_in_source
554
   *   - link_to_reference
555
   *   - add_footnote_keys
556
   *   - bibliography_aware
557
   *   Valid values are 1 or 0.
558
   * @param $inline_text_prefix
559
   *   Only used to decide if the source references should be enclosed in brackets or not when displayed inline.
560
   *   This text will not be included into the response.
561
   * @param $footnote_list_key_suggestion string
562
   *    optional parameter. If this paramter is left empty (null, 0, "") the footnote key will be determined by the nested
563
   *    method calls by calling RenderHints::getFootnoteListKey(). NOTE: the footnore key for annotations will be set to
564
   *    RenderHints::getFootnoteListKey().'-annotations'. @return array
565
   *   an associative array with the following elements:
566
   *   - foot_note_keys: all footnote keys as markup
567
   *   - source_references: an array of the source references citations
568
   *   - names used in source: an associative array of the names in source,
569
   *        the name in source strings are de-duplicated
570
   *        !!!NOTE!!!!: this field will most probably be removed soon (TODO)
571
   *
572
   *@see cdm_entities_annotations_as_footnotekeys()
573
   *
574
   */
570
/**
571
 * @param $entity
572
 * @param $config array
573
 *   An associative array to configure the display of the annotations and
574
 *   sources. The array has the following keys
575
 *   - sources_as_content
576
 *   - link_to_name_used_in_source
577
 *   - link_to_reference
578
 *   - add_footnote_keys
579
 *   - bibliography_aware
580
 *   Valid values are 1 or 0.
581
 * @param $inline_text_prefix
582
 *   Only used to decide if the source references should be enclosed in
583
 *   brackets or not when displayed inline. This text will not be included into
584
 *   the response.
585
 * @param $footnote_list_key_suggestion string
586
 *    optional parameter. If this paramter is left empty (null, 0, "") the
587
 *   footnote key will be determined by the nested method calls by calling
588
 *   RenderHints::getFootnoteListKey(). NOTE: the footnore key for annotations
589
 *   will be set to RenderHints::getFootnoteListKey().'-annotations'. @return
590
 *   array an associative array with the following elements:
591
 *   - foot_note_keys: all footnote keys as markup
592
 *   - source_references: an array of the source references citations
593
 *   - names used in source: an associative array of the names in source,
594
 *        the name in source strings are de-duplicated
595
 *        !!!NOTE!!!!: this field will most probably be removed soon (TODO)
596
 *
597
 * @throws \Exception
598
 *
599
 * @see cdm_entities_annotations_as_footnotekeys()
600
 */
575 601
  function handle_annotations_and_sources($entity, $config, $inline_text_prefix, $footnote_list_key_suggestion) {
576 602

  
577 603
    $annotations_and_sources = array(
......
682 708
    return $footnote_list_key;
683 709
  }
684 710

  
685
  /**
686
   * Provides the according tag name for the description element markup which fits the  $feature_block_settings['as_list'] value
687
   *
688
   * @param $feature_block_settings
689
   *   A feature_block_settings array, for details, please see get_feature_block_settings($feature_uuid = 'DEFAULT')
690
   */
711
/**
712
 * Provides the according tag name for the description element markup which
713
 * fits the  $feature_block_settings['as_list'] value
714
 *
715
 * @param $feature_block_settings
716
 *   A feature_block_settings array, for details, please see
717
 *   get_feature_block_settings($feature_uuid = 'DEFAULT')
718
 *
719
 * @return mixed|string
720
 */
691 721
  function cdm_feature_block_element_tag_name($feature_block_settings){
692 722
    switch ($feature_block_settings['as_list']){
693 723
      case 'ul':
......
1273 1303
            $state .= ' ' . $state_data->modifyingText_L10n;
1274 1304
          }
1275 1305
    
1276
          $modifiers_strings = cdm_modifers_representations($state_data);
1306
          $modifiers_strings = cdm_modifiers_representations($state_data);
1277 1307
          $state_data_markup = $state . ($modifiers_strings ? ' ' . $modifiers_strings : '');
1278 1308
          // we could use strip_tags() to reduce the markup to text for the key but this is expensive
1279 1309
          $sort_key = str_pad($sample_count, 6, '0', STR_PAD_LEFT) . '_' . $state_data_markup;
......
1360 1390
      if (isset($statistical_val->value)) {
1361 1391
        $statistical_val->_value = $statistical_val->value;
1362 1392
      }
1363
      $val_modifiers_strings = cdm_modifers_representations($statistical_val);
1393
      $val_modifiers_strings = cdm_modifiers_representations($statistical_val);
1364 1394
      if ($val_modifiers_strings) {
1365 1395
        $statistical_val->_value = ' ' . $val_modifiers_strings . ' ' . $statistical_val->_value;
1366 1396
      }
......
1393 1423
  }
1394 1424

  
1395 1425
  // modifiers of the description element itself
1396
  $modifier_string = cdm_modifers_representations($element);
1426
  $modifier_string = cdm_modifiers_representations($element);
1397 1427
  $out .= ($modifier_string ? ' ' . $modifier_string : '');
1398 1428
  if (isset($element->modifyingText_L10n)) {
1399 1429
    $out = $element->modifyingText_L10n . ' ' . $out;

Also available in: Unified diff