Project

General

Profile

« Previous | Next » 

Revision 9438ad3a

Added by Andreas Kohlbecker about 11 years ago

dataportal side implementation for #3305 (Collect images via taxon relations)

View differences:

7.x/modules/cdm_dataportal/cdm_dataportal.install
32 32
 * - 1 digit for Drupal core compatibility.
33 33
 * - 1 digit for your module's major release version (e.g., is this the 7.x-1.* (1) or 7.x-2.* (2) series of your module?). This digit should be 0 for initial porting of your module to a new Drupal core API.
34 34
 * - 2 digits for sequential counting, starting with 00.
35
 *
36
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_update_N/7
35 37
 */
36 38

  
37 39
/**
......
40 42
 */
41 43
function cdm_dataportal_update_7301() {
42 44
  // reset edit_map_server variable to default
43
  variable_del('edit_map_server');

44
  return t('Resetting setting for EDIT map server (edit_map_server) to default');
45
   return
46
  _remove_variable('edit_map_server');
45 47
}
46 48

  
47 49
/**
......
49 51
 *  - reset edit_map_server variable to default
50 52
 */
51 53
function cdm_dataportal_update_7302() {
52
  // once again reset edit_map_server variable to default
53
  variable_del('edit_map_server');
54
  return t('Resetting setting for EDIT map server (edit_map_server) to default');
54

  
55
  return
56
  _remove_variable('edit_map_server') . // once again reset edit_map_server variable to default
57
  _rename_variable('cdm_dataportal_show_media', 'cdm_images_include_children');
55 58
}
56 59

  
57 60
/**
58
 * @todo Please document this function.
59
 * @see http://drupal.org/node/1354
61
 * Renames a persistent variable.
62
 *
63
 * @return
64
 *   A message string of the performed operation.
60 65
 */
61 66
function _rename_variable($old_name, $new_name) {
62 67
  $success = FALSE;
......
70 75
    $success = TRUE;
71 76
  }
72 77

  
73
  return array('success' => $success, 'query' => "Renaming variable $old_name to $new_name");
78
  return "Variable \'$old_name\' to \'$new_name\' renamed. ";
74 79
}
75 80

  
76 81
/**
77
 * @todo Please document this function.
78
 * @see http://drupal.org/node/1354
82
 * Unsets a persistent variable.
83
 *
84
 * Calls variable_del() and returns a message string.
85
 *
86
 * @return
87
 *   A message string of the performed operation.
79 88
 */
80 89
function _remove_variable($name) {
81 90
  variable_del($name);
82
  return array('success' => TRUE, 'query' => "Removing variable $name");
91
  return "Variable \'$name\' removed. ";
83 92
}
84 93

  
85 94
/**
86
 * @todo Please document this function.
87
 * @see http://drupal.org/node/1354
95
 * Sets a persistent variable.
96
 *
97
 * Calls variable_set() and returns a message string.
98
 *
99
 * @return
100
 *   A message string of the performed operation.
88 101
 */
89 102
function _create_variable($name, $value) {
90 103
  variable_set($name, $value);
91
  return array('success' => TRUE, 'query' => "Creating variable $name new value: $value");
104
  return "Variable \'$name\' created with value: \'$value\'. ";
92 105
}
93 106

  
94 107
/**
95
 * @todo Please document this function.
96
 * @see http://drupal.org/node/1354
108
 * Overwrites a persistent variable.
109
 *
110
 * Calls _create_variable() and returns a message string.
111
 *
112
 * @return
113
 *   A message string of the performed operation.
97 114
 */
98 115
function _modify_variable($name, $value_override) {
99 116
  /*
7.x/modules/cdm_dataportal/cdm_dataportal.module
899 899
  }
900 900
}
901 901

  
902
/**
903
 * Loads the media associated to the given taxon from the cdm server.
904
 * The aggregation settings regarding taxon relathionships and
905
 * taxonnomic childen are taken into account.
906
 *
907
 * The media lists are cached in a static variable.
908
 *
909
 * @param Taxon $taxon
910
 *   A CDM Taxon entitiy
911
 *
912
 * @return array
913
 *   An array of CDM Media entities
914
 *
915
 */
916
function _load_media_for_taxon($taxon) {
917

  
918
  static $media = NULL;
919

  
920
  if(!isset($media)) {
921
    $media = array();
922
  }
923
  if (!isset($media[$taxon->uuid])) {
924

  
925
    // --- GET Images --- //
926
    $mediaQueryParameters = array(
927
        "type" => "ImageFile",
928
    );
929

  
930
    $relationship_choice = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
931
    $mediaQueryParameters['relationships'] = implode(',', get_selection($relationship_choice['direct']));
932
    $mediaQueryParameters['relationshipsInvers'] = implode(',', get_selection($relationship_choice['invers']));
933

  
934
    $ws_endpoint = NULL;
935
    if ( variable_get('cdm_images_include_children', 0) == 0) {
936
      $ws_endpoint = CDM_WS_PORTAL_TAXON_MEDIA;
937
    } else {
938
      $ws_endpoint = CDM_WS_PORTAL_TAXON_SUBTREE_MEDIA;
939
    }
940

  
941
    $media[$taxon->uuid] = cdm_ws_get($ws_endpoint,
942
        array(
943
            $taxon->uuid,
944
        ),
945
        queryString($mediaQueryParameters)
946
       );
947
  }
948

  
949
  return $media[$taxon->uuid];
950
}
951

  
952
/**
953
 *
954
 * @param Taxon $taxon
955
 *   A CDM Taxon entitiy
956
 *
957
 * @return array
958
 *   An array of CDM SpecimenOrObservation entities
959
 *
960
function _load_occurences_for_taxon($taxon){
961

  
962
  static $occurences = NULL;
963

  
964
  if(!isset($occurences)) {
965
    $occurences = array();
966
  }
967

  
968
  if (!isset($occurences[$taxon->uuid])){
969

  
970
    $relationship_choice = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
971
    $relationship_choice['direct'] = get_selection($relationship_choice['direct']);
972
    $relationship_choice['invers'] = get_selection($relationship_choice['invers']);
973

  
974
    $by_associatedtaxon_query = http_build_query(array(
975
        'relationshipsInvers' => implode(',', $relationship_choice['invers']),
976
        'relationships' => implode(',', $relationship_choice['direct']),
977
        'pageSize' => null // all hits in one page
978
    )
979
    );
980

  
981
    $pager = cdm_ws_get(CDM_WS_OCCURRENCE_BY_ASSOCIATEDTAXON,
982
        null,
983
        $by_associatedtaxon_query . '&taxonUuid=' . $taxon->uuid
984
    );
985

  
986

  
987
    if(isset($pager->records[0])){
988
      $occurences[$taxon->uuid] =  $pager->records;
989
    }
990
  }
991
  return $occurences[$taxon->uuid];
992
}
993
 */
994

  
902 995
/**
903 996
 * Gets a Drupal variable, string or array and returns it.
904 997
 *
7.x/modules/cdm_dataportal/includes/pages.inc
234 234
/**
235 235
 * Implements the hook_preprocess_HOOK() for theme_menu_local_tasks()
236 236
 *
237
 * Removes the tabs to be hidden, @see taxon_page_tabs_hidden()
237
 *  - Removes the tabs to be hidden, @see taxon_page_tabs_hidden()
238
 *  - Renames tabs according to the settings // TODO (this will replace the theme_cdm_taxonpage_tab() function !!!)
238 239
 *
239 240
 * @param array $variables
240 241
 *   The variables array
......
243 244

  
244 245
  $hidden_tabs = taxon_page_tabs_hidden();
245 246

  
246
  foreach ($variables['primary'] as $key => &$element) {
247
    foreach ($hidden_tabs as $tab) {
248
      if ($element['#link']['path'] == 'cdm_dataportal/taxon/%/' . $tab) {
249
        // remove the tab
250
        unset($variables['primary'][$key]);
247
  if (is_array($variables['primary'])) {
248
    foreach ($variables['primary'] as $key => &$element) {
249
      foreach ($hidden_tabs as $tab) {
250
        if ($element['#link']['path'] == 'cdm_dataportal/taxon/%/' . $tab) {
251
          // remove the tab
252
          unset($variables['primary'][$key]);
253
        }
251 254
      }
252 255
    }
253 256
  }
7.x/modules/cdm_dataportal/settings.php
406 406
    '#title' => t('CDM Server'),
407 407
    '#collapsible' => FALSE,
408 408
    '#collapsed' => FALSE,
409
    '#description' => t('<em>CDM Server</em> makes the dialogue possible with
410
      <em>CDM Data Portal</em> thanks to its web services.'),
409
    '#description' => t('The <em>CDM Server</em> exposes data stored in a
410
        CDM data base to the web via RESTful web services and thus is the source of the data
411
        to be displayed by a CDM DataPotal.'),
411 412
  );
412 413

  
413 414
  $form['cdm_webservice']['cdm_webservice_url'] = array(
......
501 502

  
502 503
  // TODO: settings are still incomplete, compare with
503 504
  // trunk/dataportal/inc/config_default.php.inc.
504
  $form['cdm_dataportal'] = array(
505
  $form['taxon_tree'] = array(
505 506
    '#type' => 'fieldset',
506 507
    '#title' => t('Taxon Tree'),
507 508
    '#collapsible' => FALSE,
......
515 516
      </a></p>'),
516 517
  );
517 518

  
518
  $form['cdm_dataportal'][CDM_TAXONOMICTREE_UUID] = array(
519
  $form['taxon_tree'][CDM_TAXONOMICTREE_UUID] = array(
519 520
    '#type' => 'select',
520 521
    '#title' => t('Available classifications') . ':',
521 522
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
......
525 526
      with a manual user change.'),
526 527
  );
527 528

  
528
  $form['cdm_dataportal']['taxontree_ranklimit'] = array(
529
  $form['taxon_tree']['taxontree_ranklimit'] = array(
529 530
    '#type' => 'select',
530 531
    '#title' => t('Rank of highest displayed taxon') . ':',
531 532
     // Before DEFAULT_TAXONTREE_RANKLIMIT_UUID.
......
536 537
      level of the tree structure.'),
537 538
  );
538 539

  
539
  $form['cdm_dataportal'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
540
  $form['aggregation'] = array(
541
      '#type' => 'fieldset',
542
      '#title' => t('Aggregation of data'),
543
      '#collapsible' => FALSE,
544
      '#description' => t("This section covers the different aspects of aggregating information.
545
          <p>
546
          <strong>NOTICE:</strong> Aggregation may slow down your data portal, so you may want to sensibly apply these setting and you may also
547
          whant to make use of the caching capabilities of the dataportal.</p>"),
548

  
549
  );
550

  
551
  $form['aggregation']['media_aggregation'] = array(
552
      '#type' => 'fieldset',
553
      '#title' => t('Media aggregation'),
554
      '#collapsible' => FALSE,
555
      '#collapsed' => TRUE,
556
      '#description' => t("The media aggregation is also affected by the settigs in \"<strong>Aggregation via taxon relationsships</strong>\" below."),
557

  
558
  );
559
  $form['aggregation']['media_aggregation']['cdm_images_include_children'] = array(
560
      '#type' => 'select',
561
      '#title' => t('Aggregation of taxon pictures') . ':',
562
      '#default_value' => variable_get('cdm_images_include_children', FALSE),
563
      '#options' => array(
564
          0 => "Show only pictures of the current taxon",
565
          1 => "Include pictures of taxonomic children",
566
      ),
567
      '#description' => t("Choose whether to include the images of the taxonomic children. This will affect the <em>Images</em> tab and image tumbnails like in the search results."),
568
  );
569

  
570
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS] = array(
540 571
      '#type' => 'fieldset',
541 572
      '#attributes' => array('class'=>array('clearfix')),
542
      '#title' => t('Information aggregation via taxon relationsships'),
573
      '#title' => t('Aggregation via taxon relationsships'),
543 574
      '#collapsible' => TRUE,
544 575
      '#collapsed' => TRUE,
545 576
      '#tree' => TRUE,
......
553 584
  $taxonRelationshipTypeOptions = cdm_Vocabulary_as_option(UUID_TAXON_RELATIONSHIP_TYPE, '_cdm_relationship_type_term_label_callback');
554 585
  $aggregate_by_taxon_relationships = variable_get(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS, unserialize(CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS_DEFAULT));
555 586

  
556
  $form['cdm_dataportal'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
587
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['direct'] = array(
557 588
      '#type' => 'checkboxes',
558 589
      '#title' => t('Direct'),
559 590
      '#options' => $taxonRelationshipTypeOptions,
560 591
      '#default_value' => $aggregate_by_taxon_relationships['direct'],
561 592
  );
562
  $form['cdm_dataportal'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
593
  $form['aggregation']['aggregate_by_taxon_relationships'][CDM_AGGREGATE_BY_TAXON_RELATIONSHIPS]['invers'] = array(
563 594
      '#type' => 'checkboxes',
564 595
      '#title' => t('Invers'),
565 596
      '#options' => $taxonRelationshipTypeOptions,
......
967 998
  $form['taxon_profile'] = array(
968 999
    '#type' => 'fieldset',
969 1000
    '#title' => t('Taxon profile (tab)'),
970
    '#description' => t('<p>This section covers the setting related to the taxon
1001
    '#description' => t('<p>This section covers the settings related to the taxon
971 1002
      profile tab, also known as the <strong>"General"</strong> tab.</p>'),
972 1003
    '#collapsible' => TRUE,
973 1004
    '#collapsed' => TRUE,
......
976 1007
  // ---- PROFILE PICTURE ----//
977 1008
  $form['taxon_profile']['picture'] = array(
978 1009
    '#type' => 'fieldset',
979
    '#title' => t('Profile Picture'),
1010
    '#title' => t('Taxon profile picture'),
980 1011
    '#collapsible' => TRUE,
981 1012
    '#collapsed' => FALSE,
982
    '#description' => t('Select a profile picture for taxa. Like a facebook of plants.'),
1013
    '#description' => t('This sections allows configuring the display of the so called taxon profile image which is displayed in the taxon profile tab.'),
983 1014
  );
984 1015

  
985 1016
  $form['taxon_profile']['picture']['cdm_dataportal_show_default_image'] = array(
......
993 1024
  array_unshift($options, '-- DISABLED --');
994 1025
  $form['taxon_profile']['picture']['image_hide_rank'] = array(
995 1026
    '#type' => 'select',
996
    '#title' => t('Hide picture for taxa above') . ':',
1027
    '#title' => t('Hide profile picture for higher ranks') . ':',
997 1028
    '#default_value' => variable_get('image_hide_rank', '0'),
998 1029
    '#options' => $options,
999
    '#description' => t('Select which rank of pictures should not have
1000
      a profile picture.'),
1001
  );
1002
  // Show picture.
1003
  $selectShowMedia = array(
1004
    0 => "Show only taxon pictures",
1005
    1 => "Show taxon and child taxa pictures",
1006
  );
1007

  
1008
  $form['taxon_profile']['picture']['cdm_dataportal_show_media'] = array(
1009
    '#type' => 'select',
1010
    '#title' => t('Available picture files') . ':',
1011
    '#default_value' => variable_get('cdm_dataportal_show_media', FALSE),
1012
    '#options' => $selectShowMedia,
1013
    '#description' => t("Show the profile pictures current taxon's children."),
1030
    '#description' => t('The taxon profile picture will not be shown for taxa with rank higher that the selected.'),
1014 1031
  );
1015 1032

  
1016 1033
  // -- MEDIA THUMBNAILS -- //
7.x/modules/cdm_dataportal/theme/cdm_dataportal.page.theme
105 105

  
106 106
  $page_part = variable_get('cdm_dataportal_taxonpage_tabs', 1) ? $page_part : 'all';
107 107

  
108
  // --- GET Images --- //
109
  $mediaQueryParameters = array(
110
    "type" => "ImageFile",
111
  );
108
  $media = _load_media_for_taxon($taxon);
109

  
112 110

  
113
  $selectShowMedia = variable_get('cdm_dataportal_show_media', 0);
114
  if ($selectShowMedia == 0) {
115
    $media = cdm_ws_get(CDM_WS_PORTAL_TAXON_MEDIA, array(
116
      $taxon->uuid,
117
    ), queryString($mediaQueryParameters));
118
  }
119
  else {
120
    $media = cdm_ws_get(CDM_WS_PORTAL_TAXON_SUBTREE_MEDIA, array(
121
      $taxon->uuid,
122
    ), queryString($mediaQueryParameters));
123
  }
124 111
  if (!isset($media[0]) || ($tabsToDisplay["Images"] == '0')) {
125 112
    taxon_page_tabs_hidden('images');
126 113
  }
114

  
127 115
  // HideImage flag depending on administative preset.
128 116
  $hideImages = FALSE;
129 117
  if (variable_get('image_hide_rank', '0') != '0' && isset($taxon->name->rank->uuid)) {
7.x/modules/cdm_dataportal/theme/cdm_dataportal.taxon.theme
617 617

  
618 618
  $gallery_name = $taxon->uuid;
619 619

  
620
  $mediaQueryParameters = array(
621
    "type" => "ImageFile",
622
  );
623
  $galleryLinkUri = path_to_taxon($taxon->uuid, 'images');
620
  $mediaList = _load_media_for_taxon($taxon);
624 621

  
625
  // TODO cdm_dataportal_show_media = ????
626
  $selectShowMedia = variable_get('cdm_dataportal_show_media', 0);
627
  if ($selectShowMedia == 0) {
628
    $mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXON_MEDIA, array(
629
      $taxon->uuid,
630
    ), queryString($mediaQueryParameters));
631
  }
632
  else {
633
    $mediaList = cdm_ws_get(CDM_WS_PORTAL_TAXON_SUBTREE_MEDIA, array(
634
      $taxon->uuid,
635
    ), queryString($mediaQueryParameters));
636
  }
622
  $galleryLinkUri = path_to_taxon($taxon->uuid, 'images');
637 623

  
638 624
  $out .= theme('cdm_media_gallerie', array(
639 625
    'mediaList' => $mediaList,
7.x/themes/garland_cichorieae/template.php
471 471

  
472 472
  $gallery_name = $taxon->uuid;
473 473

  
474
  $mediaQueryParameters = array("type" => "ImageFile");
475 474
  $galleryLinkUri = path_to_taxon($taxon->uuid, 'images');
476 475

  
477
  // TODO cdm_dataportal_show_media = ????
478
  $selectShowMedia = variable_get('cdm_dataportal_show_media', 0);
479
  if ($selectShowMedia == 0) {
480
    $mediaList = cdm_ws_get(
481
      CDM_WS_PORTAL_TAXON_MEDIA,
482
      array($taxon->uuid),
483
      queryString($mediaQueryParameters
484
    ));
485
  }
486
  else {
487
    $mediaList = cdm_ws_get(
488
      CDM_WS_PORTAL_TAXON_SUBTREE_MEDIA,
489
      array($taxon->uuid),
490
      queryString($mediaQueryParameters
491
    ));
492
  }
476
  $mediaList = $mediaList = _load_media_for_taxon($taxon);
477

  
493 478
  $out .= theme('cdm_media_gallerie', array(
494 479
    'mediaList' => $mediaList,
495 480
    'galleryName' => $gallery_name,

Also available in: Unified diff