commit afc363dfe7f1c165c5c716b3fde063a2b8f67ec6
Author: Andreas Kohlbecker <a.kohlbecker@bgbm.org>
Date:   Wed Aug 10 10:04:20 2011 +0000

    fixing #2519 (Make DescriptionElement Media visible in Data Portal)

diff --git a/modules/cdm_dataportal/cdm_api/cdm_api.module b/modules/cdm_dataportal/cdm_api/cdm_api.module
index 1ae185b2..c481322e 100644
--- a/modules/cdm_dataportal/cdm_api/cdm_api.module
+++ b/modules/cdm_dataportal/cdm_api/cdm_api.module
@@ -1020,10 +1020,13 @@ function cdm_get_featureTrees_as_options($addDefaultFeatureTree = false){
             $treeRepresentation = $featureTree->titleCache;
 
             if(is_array($featureTree->root->children) && count($featureTree->root->children) > 0){
+
+              // render the hierarchic tree structure
               $treeDetails = '<div class="featuretree_structure">'
                 //._featureTree_elements_toString($featureTree->root)
                 .theme('featureTree_hierarchy', $featureTree->uuid)
                 .'</div>';
+
               $form = array();
               $form['featureTree-'.$featureTree->uuid] = array(
                   '#type' => 'fieldset',
diff --git a/modules/cdm_dataportal/cdm_dataportal.module b/modules/cdm_dataportal/cdm_dataportal.module
index d158631b..4d34473f 100644
--- a/modules/cdm_dataportal/cdm_dataportal.module
+++ b/modules/cdm_dataportal/cdm_dataportal.module
@@ -1435,7 +1435,7 @@ function cdm_dataportal_media_from_descriptionElements($descriptionElements){
 		foreach($descriptionElements as $descriptionElement){
 			if(is_array($descriptionElement->media)){
 				foreach($descriptionElement->media as $media){
-					if(isset($media)){
+					if(is_object($media)){
 						$outArrayOfMedia[] = $media;
 					}
 				}
diff --git a/modules/cdm_dataportal/theme/cdm_dataportal.descriptions.theme b/modules/cdm_dataportal/theme/cdm_dataportal.descriptions.theme
index f76db4fd..e22e15d9 100644
--- a/modules/cdm_dataportal/theme/cdm_dataportal.descriptions.theme
+++ b/modules/cdm_dataportal/theme/cdm_dataportal.descriptions.theme
@@ -93,9 +93,9 @@ function theme_cdm_feature_nodes($mergedFeatureNodes, $taxon){
   RenderHints::pushToRenderStack('feature_nodes');
   $gallery_settings = getGallerySettings(CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME);
 
-  foreach($mergedFeatureNodes as $node){
+  $media_list = array();
 
-      var_dump($node->feature->representation_L10n);
+  foreach($mergedFeatureNodes as $node){
 
     // process $descriptionElements with content only
     if(is_array($node->descriptionElements) && count($node->descriptionElements) > 0 || count($node->children) > 0){
@@ -103,11 +103,15 @@ function theme_cdm_feature_nodes($mergedFeatureNodes, $taxon){
       $block->module = 'cdm_dataportal';
 
       if($node->feature->uuid != UUID_IMAGE){
+
         $block->delta = generalizeString($featureRepresentation);
         $block->subject = theme('cdm_feature_name', $featureRepresentation);
         $block->module = "cdm_dataportal-feature";
         $block->content = '';
 
+        /*
+         * Content/DISTRIBUTION
+         */
         if($node->feature->uuid == UUID_DISTRIBUTION){
 
           if(variable_get(DISTRIBUTION_TEXTDATA_DISPLAY_ON_TOP, 0)){
@@ -130,19 +134,62 @@ function theme_cdm_feature_nodes($mergedFeatureNodes, $taxon){
           $block->content .= theme('cdm_distribution_map', $taxon);
         }
 
-        //get the text for the feature block
-        if ($node->feature->uuid == UUID_COMMON_NAME){
+        /*
+         * Content/COMMON_NAME
+         */
+        else if ($node->feature->uuid == UUID_COMMON_NAME){
           $block->content .= theme('cdm_common_names', $node->descriptionElements);
         /*
         }else if($node->feature->uuid == UUID_IMAGE_SOURCES) {
           $block->content .= theme('cdm_image_sources', $node->descriptionElements);
         */
-        } else {
+        }
+
+        /*
+         * Content/ALL OTHER FEATURES
+         */
+        else {
           $block->content .= theme('cdm_descriptionElements', $node->descriptionElements, $node->feature->uuid, $taxon->uuid);
+
+          /*
+           *  Content/ALL OTHER FEATURES/Subordinate Features
+           *
+           *  subordinate features are printed inline in one floating text,
+           *  it is expected that supordinate features only "contain" TextData elements
+           */
+          // TODO move into own theme
+          if(count($node->children) > 0){
+
+            //TODO support more than one level of childen http://dev.e-taxonomy.eu/trac/ticket/2393
+            $text = '';
+            foreach ($node->children as $child){
+
+             if (is_array($child->descriptionElements)){
+               foreach ($child->descriptionElements as $element) {
+
+                 if(is_array($element->media)){
+                   // append media of supordinate emelents to list of main feature
+                   $media_list = array_merge($media_list, $element->media);
+                 }
+
+                 $description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
+                //TODO use localized version of feature name, the locale must match the locale of the multilanguage text (http://dev.e-taxonomy.eu/trac/ticket/2394)
+                 $description = str_replace($element->feature->titleCache, '<em>' . $element->feature->titleCache . '</em>', $description);
+               }
+               $text .= " " . $description;
+               $description = '';
+             }
+
+            }
+            $block->content .= $text;
+          }
+
         }
 
-        // get media for the feature block
-        $media_list = cdm_dataportal_media_from_descriptionElements($node->descriptionElements);
+        /*
+         * Media/ALL FEATURES
+         */
+        $media_list = array_merge($media_list, cdm_dataportal_media_from_descriptionElements($node->descriptionElements));
         $captionElements = array('title', 'rights');
 
         $gallery = theme('cdm_media_gallerie', $media_list, CDM_DATAPORTAL_DESCRIPTION_GALLERY_NAME.'_'.$node->feature->uuid,
@@ -162,24 +209,6 @@ function theme_cdm_feature_nodes($mergedFeatureNodes, $taxon){
 
       }
     }
-    // theme
-    if(count($node->children) > 0){
-      //TODO support more than one level of childen http://dev.e-taxonomy.eu/trac/ticket/2393
-      $text = '';
-      foreach ($node->children as $child){
-       //$out .= theme('cdm_descriptionElementTextData', $child->descriptionElements[0], false);
-       if (is_array($child->descriptionElements)){//if condition added to avoid warnings
-         foreach ($child->descriptionElements as $element) {
-           $description = str_replace("\n", "<br/>", $element->multilanguageText_L10n->text);
-          //TODO use localized version of feature name, the locale must match the locale of the multilanguage text (http://dev.e-taxonomy.eu/trac/ticket/2394)
-           $description = str_replace($element->feature->titleCache, '<em>' . $element->feature->titleCache . '</em>', $description);
-         }
-         $text .= " " . $description;
-         $description = '';
-       }
-      }
-      $out .= $text;
-    }
 
   }
   RenderHints::popFromRenderStack();
diff --git a/modules/cdm_dataportal/theme/cdm_dataportal.media.theme b/modules/cdm_dataportal/theme/cdm_dataportal.media.theme
index 6c21cdb6..995722f4 100644
--- a/modules/cdm_dataportal/theme/cdm_dataportal.media.theme
+++ b/modules/cdm_dataportal/theme/cdm_dataportal.media.theme
@@ -224,12 +224,12 @@ function theme_cdm_media_caption($media, $elements = array('title', 'description
 function theme_cdm_media_gallerie(
 	$mediaList,
     $galleryName,
-	$maxExtend = 150, 
-	$cols = 4, 
-	$maxRows = false, 
+	$maxExtend = 150,
+	$cols = 4,
+	$maxRows = false,
 	$captionElements = array('title'),
-	$mediaLinkType = 'LIGHTBOX', 
-	$alternativeMediaUri = null, 
+	$mediaLinkType = 'LIGHTBOX',
+	$alternativeMediaUri = null,
 	$galleryLinkUri = null,
 	$showCaption = true){
 
@@ -303,7 +303,7 @@ function theme_cdm_media_gallerie(
 
 				_add_js_ahah();
 				$content_url = cdm_compose_url(CDM_WS_PORTAL_MEDIA, $media->uuid);
-				
+
 				$cdm_proxy_url = url('cdm_api/proxy/'.urlencode($content_url)."/cdm_media_caption/".serialize($captionElements));
 				$captionPartHtml = '<div class="ahah-content" rel="'.$cdm_proxy_url.'"><span class="loading" style="display: none;">Loading ....</span></div>';
 
diff --git a/modules/cdm_dataportal/theme/cdm_dataportal.page.theme b/modules/cdm_dataportal/theme/cdm_dataportal.page.theme
index 4d74a350..e3531cf8 100644
--- a/modules/cdm_dataportal/theme/cdm_dataportal.page.theme
+++ b/modules/cdm_dataportal/theme/cdm_dataportal.page.theme
@@ -283,12 +283,12 @@ function theme_cdm_taxon_page_specimens($taxon){
           $captionElements = array('#uri'=>t('open media'));
           $gallery_html = theme(
               'cdm_media_gallerie',
-          $mediaList,
-          $gallery_name ,
-          $gallery_settings['cdm_dataportal_media_maxextend'],
-          $gallery_settings['cdm_dataportal_media_cols'],
-          $gallery_settings['cdm_dataportal_media_maxRows'],
-          $captionElements, 'LIGHTBOX', null, null);
+              $mediaList,
+              $gallery_name ,
+              $gallery_settings['cdm_dataportal_media_maxextend'],
+              $gallery_settings['cdm_dataportal_media_cols'],
+              $gallery_settings['cdm_dataportal_media_maxRows'],
+              $captionElements, 'LIGHTBOX', null, null);
         } else {
           $gallery_html = '';
         }
