commit 38da4e54929476f0af87bc94e92e7db9fdd16066
Author: Andreas Kohlbecker <a.kohlbecker@bgbm.org>
Date:   Mon Jun 13 15:40:06 2016 +0200

    #5887 root nodes available in classification breadcrumbs

diff --git a/modules/cdm_dataportal/cdm_api/webservice_uris.php b/modules/cdm_dataportal/cdm_api/webservice_uris.php
index 1f60c040..a154c794 100644
--- a/modules/cdm_dataportal/cdm_api/webservice_uris.php
+++ b/modules/cdm_dataportal/cdm_api/webservice_uris.php
@@ -82,6 +82,8 @@ define('CDM_WS_PORTAL_TAXONOMY_PATH_FROM', 'portal/classification/$0/pathFrom/$1
 define('CDM_WS_PORTAL_TAXONOMY_PATH_FROM_TO_RANK', 'portal/classification/$0/pathFrom/$1/toRank/$2');
 define('CDM_WS_PORTAL_TAXONOMY_MEDIA', 'portal/classification/$0/$1');
 
+define('CDM_WS_TAXONNODE_PARENT', 'taxonNode/$0/parent');
+
 define('CDM_WS_TERMVOCABULARY', 'termVocabulary/$0');
 
 define('CDM_WS_TERM_COMPARE', 'term/$0/compareTo/$1');
diff --git a/modules/cdm_dataportal/cdm_dataportal.module b/modules/cdm_dataportal/cdm_dataportal.module
index 83d92ed3..77f602a4 100644
--- a/modules/cdm_dataportal/cdm_dataportal.module
+++ b/modules/cdm_dataportal/cdm_dataportal.module
@@ -296,7 +296,7 @@ function _add_js_taxonomic_children($jquery_selector) {
           hoverClass: "fa-rotate-90",
           activeClass: "fa-rotate-90",
           classificationUuid: "' . get_current_classification_uuid() . '",
-          cdmwebappBaseUri: "' . variable_get('cdm_webservice_url', '') . '",
+          cdmWebappBaseUri: "' . variable_get('cdm_webservice_url', '') . '",
           proxyBaseUri: "' . $base_url . '",
           
         });
@@ -828,12 +828,14 @@ function cdm_dataportal_block_view($delta) {
       ));
       return $block;
     case 'classification_breadcrumbs':
+      $taxon_uuid = null;
       if (arg(1) == 'taxon' && is_uuid(arg(2))) {
-        $block['subject'] = '<none>';
-        $block['content'] = compose_classification_breadcrumbs(arg(2));
-        return $block;
+        $taxon_uuid = arg(2);
       }
-      break;
+      $block['subject'] = '<none>';
+      $block['content'] = compose_classification_breadcrumbs($taxon_uuid);
+      return $block;
+    
   }
 }
 
diff --git a/modules/cdm_dataportal/cdm_taxontree/cdm_taxontree.module b/modules/cdm_dataportal/cdm_taxontree/cdm_taxontree.module
index 3ae4f4ad..588b5e59 100644
--- a/modules/cdm_dataportal/cdm_taxontree/cdm_taxontree.module
+++ b/modules/cdm_dataportal/cdm_taxontree/cdm_taxontree.module
@@ -934,13 +934,12 @@ function theme_cdm_taxontree($variables) {
   $tree_node_callback = $variables['tree_node_callback'];
   $element_name = $variables['element_name'];
 
+  if(isset($tree->records)){
+    // unwrap from pager object
+    $tree = $tree->records;
+  }
+
   if (!is_array($tree)) {
-    /*
-    $out = '<ul class="taxon-nodes">';
-    $out .= '<li>----------------------------NO TREE---------------------------------------</li>';
-    $out .= '</ul>';
-    return $out;
-    */
     return FALSE;
   }
 
@@ -952,6 +951,9 @@ function theme_cdm_taxontree($variables) {
   // Append element name to get multiple taxontrees on one page working.
   $out = '<ul class="taxon-nodes ' . (($element_name) ? ' ' . $element_name : '') . '">';
   foreach ($tree as $node) {
+    if($node == null){
+      continue;
+    }
     $out .= theme('cdm_taxontree_node', array(
       'node' => $node,
       'filterIncludes' => $filterIncludes,
diff --git a/modules/cdm_dataportal/includes/pages.inc b/modules/cdm_dataportal/includes/pages.inc
index b5f38ad4..c2a519b6 100644
--- a/modules/cdm_dataportal/includes/pages.inc
+++ b/modules/cdm_dataportal/includes/pages.inc
@@ -959,9 +959,6 @@ function compose_classification_breadcrumbs($taxon_uuid) {
   _add_js_taxonomic_children('#classification-breadcrumbs .taxonomic-children-button');
 
   $render_array = array();
-  if(!is_uuid($taxon_uuid)){
-    return $render_array;
-  }
 
   $render_array['#theme'] = 'item_list';
   $render_array['#type'] = 'ul';
@@ -971,27 +968,67 @@ function compose_classification_breadcrumbs($taxon_uuid) {
   );
 
   $items = array();
-  $parent_taxon_nodes = cdm_ws_taxonomy_pathFromRoot($taxon_uuid);
-
-  foreach ($parent_taxon_nodes as $node){
 
-    $is_first_item = count($items) == 0;
-    $node_name = cdm_dataportal_shortname_of($node);
-    $path = path_to_taxon($node->taxonUuid);
+  $parent_taxon_nodes = null;
+  if($taxon_uuid){
+    $parent_taxon_nodes = cdm_ws_taxonomy_pathFromRoot($taxon_uuid);
+  }
 
-    $children_indicator = '';
-    if($node->taxonomicChildrenCount){
-      $children_indicator =  '<span class="taxonomic-children-button" data-cdm-taxon-uuid="'. $node->taxonUuid. '" > '
-        . font_awesome_icon_markup('fa-chevron-right')
-        . ' </span>';
+  $classifications = cdm_ws_fetch_all(CDM_WS_PORTAL_TAXONOMY);
+  // find current classification in list
+  $classification = null;
+  $current_classification_uuid = get_current_classification_uuid();
+  foreach ($classifications as $classification){
+    if($classification->uuid == $current_classification_uuid){
+      break;
     }
+  }
 
-    $items[] =
-      ($is_first_item ? '':  ' ')
-      . l($node_name, $path)
-      . $children_indicator;
+  $node_name = '';
+  if(count($classifications) > 1 ){
+    // need to add the current classification as first label
+    $node_name = '<span '. html_class_attribute_ref($classification) .'>'
+      . $classification->titleCache . '</span>';
   }
 
+  $rank_limit_uuid = variable_get(TAXONTREE_RANKLIMIT, TAXONTREE_RANKLIMIT_DEFAULT);
+
+  /*
+  if($parent_taxon_nodes) {
+    // the path to root never contains the classification->root, by asking for
+    // the parent node we either get this or the predecessor of the virtual root node.
+    $root_parent_taxon_node_dto = cdm_ws_get(CDM_WS_TAXONNODE_PARENT, array($parent_taxon_nodes[0]->uuid));
+  } else {
+
+
+  }*/
+
+  $children_indicator =  '<span class="taxonomic-children-button" data-classification-uuid="'. $current_classification_uuid
+    . '" data-rank-limit-uuid="'. $rank_limit_uuid . '" > '
+    . font_awesome_icon_markup('fa-chevron-right')
+    . ' </span>';
+
+  $items[] = $node_name . $children_indicator;
+
+    foreach ($parent_taxon_nodes as $node){
+
+      $is_first_item = count($items) == 0;
+      $node_name = cdm_dataportal_shortname_of($node);
+      $path = path_to_taxon($node->taxonUuid);
+
+      $children_indicator = '';
+      if($node->taxonomicChildrenCount){
+        $children_indicator =  '<span class="taxonomic-children-button" data-cdm-taxon-uuid="'. $node->taxonUuid. '" > '
+          . font_awesome_icon_markup('fa-chevron-right')
+          . ' </span>';
+      }
+
+      $items[] =
+        ($is_first_item ? '':  ' ')
+        . l($node_name, $path)
+        . $children_indicator;
+    }
+
 
   $render_array['#items'] = $items;
 
diff --git a/modules/cdm_dataportal/js/jquery.cdm.taxonomic_children.js b/modules/cdm_dataportal/js/jquery.cdm.taxonomic_children.js
index f62047b8..008e2837 100644
--- a/modules/cdm_dataportal/js/jquery.cdm.taxonomic_children.js
+++ b/modules/cdm_dataportal/js/jquery.cdm.taxonomic_children.js
@@ -133,6 +133,8 @@
       this.$element = $(this.element);
 
       this.taxonUuid = this.$element.attr('data-cdm-taxon-uuid');
+      this.rankLimitUuid = this.$element.attr('data-rank-limit-uuid');
+
 
       var nextLiElement = this.$element.parent('li').next();
       if(nextLiElement != undefined){
@@ -286,11 +288,31 @@
     requestURI: function(pageIndex, pageSize){
 
       // pageIndex, pageSize are not yet used, prepared for future though
-      var contentRequest =
-        this.options.cdmwebappBaseUri
-        + this.options.cdmwebappRequest
-          .replace('{classificationUuid}', this.options.classificationUuid)
-          .replace('{taxonUuid}', this.taxonUuid);
+      var contentRequest;
+
+      if(!pageIndex){
+        pageIndex = 0;
+      }
+      if(!pageSize) {
+        pageSize = 100;
+      }
+
+      if(this.taxonUuid){
+        contentRequest =
+          this.options.cdmWebappBaseUri
+          + this.options.cdmWebappTaxonChildrenRequest
+            .replace('{classificationUuid}', this.options.classificationUuid)
+            .replace('{taxonUuid}', this.taxonUuid);
+
+      } else if(this.rankLimitUuid){
+        contentRequest =
+          this.options.cdmWebappBaseUri
+          + this.options.cdmWebappClassificationChildnodesAtRequest
+            .replace('{classificationUuid}', this.options.classificationUuid)
+            .replace('{rankUuid}', this.rankLimitUuid);
+      } else {
+
+      }
 
       this.log("contentRequest: " + contentRequest);
 
@@ -350,9 +372,11 @@
     hoverClass: undefined,
     activeClass: undefined,
     classificationUuid: undefined,
-    cdmwebappBaseUri: undefined,
+    cdmWebappBaseUri: undefined,
     proxyBaseUri: undefined,
-    cdmwebappRequest: "portal/classification/{classificationUuid}/childNodesOf/{taxonUuid}",
+    cdmWebappTaxonChildrenRequest: "portal/classification/{classificationUuid}/childNodesOf/{taxonUuid}",
+    cdmWebappClassificationChildnodesAtRequest: "portal/classification/{classificationUuid}/childNodesAt/{rankUuid}.json",
+    cdmWebappClassificationRootRequest: "portal/classification/{classificationUuid}/childNodes.json",
     proxyRequest: "cdm_api/proxy/{contentRequest}/{renderFunction}",
     renderFunction: "cdm_taxontree",
     viewPortRows: {min: 5, max: 5}
