/**
  * Generate the dashboard links for a group node.
  * Delegates theme implementation to cluster_nav module.
  * @return
  *  Render array of dashboard links.
  */
 public function getDashboardMenu()
 {
     $items = array();
     $items[] = array('label' => t('Dashboard'), 'path' => 'node/' . $this->node->nid, 'options' => array('html' => TRUE));
     if ($this->manager->isEnabled('documents')) {
         $items[] = array('label' => t('Documents'), 'path' => 'node/' . $this->node->nid . '/documents', 'total' => $this->manager->getDocumentCount(), 'options' => array('html' => TRUE, 'query' => array('sort' => 'date', 'sort_direction' => 'DESC')));
     }
     if ($discussions_count = $this->manager->getDiscussionCount() > 0) {
         if ($this->manager->isEnabled('discussions')) {
             $items[] = array('label' => t('Discussions'), 'path' => 'node/' . $this->node->nid . '/discussions', 'total' => $discussions_count, 'options' => array('html' => TRUE));
         }
     }
     if ($events_count = $this->manager->getEventCount() > 0) {
         if ($this->manager->isEnabled('events')) {
             $items[] = array('label' => t('Events'), 'path' => 'node/' . $this->node->nid . '/events', 'total' => $events_count, 'options' => array('html' => TRUE));
         }
     }
     if ($strategic_advisory = $this->manager->getStrategicAdvisory()) {
         $items[] = array('label' => t('Strategic Advisory Group'), 'path' => 'node/' . $strategic_advisory->nid, 'options' => array('html' => TRUE));
     }
     $secondary = array();
     if ($responses = $this->getRelatedResponses()) {
         $secondary['responses'] = partial('navigation_options', array('navigation_type_id' => 'related-operations', 'title' => t('Related operations'), 'nodes' => node_load_multiple($responses)));
     }
     if ($hubs = $this->getRelatedHubs()) {
         $secondary['hubs'] = partial('navigation_options', array('navigation_type_id' => 'hubs', 'title' => t('Hubs'), 'nodes' => node_load_multiple($hubs)));
     }
     if ($working_groups = $this->getRelatedWorkingGroups()) {
         $secondary['working_groups'] = partial('navigation_options', array('navigation_type_id' => 'working-groups', 'title' => t('Working groups'), 'nodes' => node_load_multiple($working_groups)));
     }
     // Combine libraries, pages and other required entities under the same listing.
     $page_ids = array_merge($this->manager->getPages(), $this->manager->getLibraries());
     $pages = shelter_base_sort_nids_by_weight($page_ids);
     if ($pages) {
         $secondary['pages'] = partial('navigation_options', array('navigation_type_id' => 'pages', 'title' => t('Pages'), 'nodes' => node_load_multiple($pages)));
     }
     $useful_links = $this->manager->getUsefulLinks();
     if ($useful_links) {
         $secondary['useful_links'] = partial('navigation_options', array('navigation_type_id' => 'useful-links', 'title' => t('Useful links'), 'links' => $useful_links));
     }
     return array('#theme' => 'cluster_nav_dashboard', '#items' => $items, '#secondary' => $secondary);
 }
 /**
  * Recursively look for children that have any of the argued $nids for parent.
  * @param $parent_nids
  *  Array of node IDs to find descendants on.
  * @param $field
  *  Entity reference field name to use.
  * @param $bundle
  *  Content type to look for.
  * @param $include_self
  *  Whether to include $parent_nids in the result.
  * @param $only_children
  *  Don't do the recursive call.
  * @return Array of node IDs.
  */
 private static function queryDescendants($parent_nids, $field, $bundle, $include_self = FALSE, $only_children = FALSE)
 {
     if (!$parent_nids) {
         return array();
     }
     $query = new EntityFieldQuery();
     $res = $query->entityCondition('entity_type', 'node')->entityCondition('bundle', $bundle)->propertyCondition('status', NODE_PUBLISHED)->fieldCondition($field, 'target_id', $parent_nids, 'IN')->execute();
     if (isset($res['node'])) {
         // We found children nodes.
         if ($only_children) {
             $return_nids = array_keys($res['node']);
         } else {
             // Do a recursive call to get all descendants.
             $return_nids = self::queryDescendants(array_keys($res['node']), $field, $bundle, TRUE);
         }
         if ($include_self) {
             $return_nids = array_merge($return_nids, $parent_nids);
         }
         $return_sorted_nids = shelter_base_sort_nids_by_weight($return_nids);
         return array_unique($return_sorted_nids);
     } elseif ($include_self) {
         // No results from the query but we were asked to include parents in the result.
         return $parent_nids;
     } else {
         // No results and no parents are to be returned, so return empty.
         return array();
     }
 }