public function log($level, &$message) { if (is_string($message)) { $datasourceName = gd_datasource_find_active(); if (isset($datasourceName)) { $message = "[$datasourceName] $message"; } } }
<div id="gd-navmain" class="container"> <div class="row"> <div class="col-md-4"> <?php if ($logo): ?> <a tabindex="2" href="<?php print check_url($front_page); ?>" title="<?php print $site_name; ?>"><img class="gd-logo" id="gd-logo" src="<?php print $logo; ?>" alt="<?php print $site_name; ?>" /></a> <?php endif; ?> </div> <div class="col-md-8"> <?php if ($logged_in) : ?> <ul class="secondary-menu menulist pull-right"> <li class="first"><?php print l($user->firstname . ' ' . $user->lastname,'user/profile', array('attributes' => array('tabindex' => '3'))); ?></li> <?php if ( gd_account_user_is_admin() || gd_account_user_is_any_datasource_admin() ) { if ( arg(0) == 'cp' ) { print '<li>'.l("Dashboard Viewer","dashboards", array('query'=>array('ds'=>gd_datasource_find_active()),'attributes' => array('tabindex' => '4'))).'</li>'; } else { print '<li>'.l("Control Panel","cp", array('attributes' => array('tabindex' => '4'))).'</li>'; } } else { print '<li>'.l("Dashboard Viewer","dashboards", array('attributes' => array('tabindex' => '4'))).'</li>'; } ?> <li class="last"><?php print l("Logout","user/logout",array('attributes' => array('tabindex' => '5'))); ?></li> </ul> <?php else : ?> <ul class="menu pull-right"> <li class="last"> <?php if ( !gd_security_is_single_sign_on() ) { print l("Login","user", array('attributes' => array('tabindex' => '3')));
/** * @return array * @throws Exception * @throws IllegalArgumentException */ function gd_dashboard_index_variables () { $dashboards = array(); $active_datasource_name = gd_datasource_find_active(); $current_dashboard = gd_dashboard_get_current(); global $user; if ( gd_account_user_is_admin() ) { // can see all datasources $datasources = gd_datasource_get_all(); if ( $current_dashboard ) { gd_datasource_set_active(get_node_field_value($current_dashboard,'field_dashboard_datasource')); } else if ( !$active_datasource_name ) { if (isset($_GET['ds'])) { gd_datasource_set_active($_GET['ds']); } else { gd_datasource_set_active(key($datasources)); } } // don't pick up any dashboards if there are no published datamarts - causes logic bomb further down if ( !empty($datasources) ) { $dashboards = gd_dashboard_findall_by_datasource(LOAD_ENTITY); } } else if ( $user->uid ) { // get view privileges for all dashboards $results = gd_account_user_get_dashboards(); // pick up the datasources from the dashboards $datasources = gd_account_user_get_datasources(); foreach ( $results as $dashboard ) { if ( !isset($datasources[get_node_field_value($dashboard,'field_dashboard_datasource')]) ) { $datasource = gd_datasource_get(get_node_field_value($dashboard,'field_dashboard_datasource')); $datasources[$datasource->name] = $datasource; } } // set current datasource if ( $current_dashboard ) { gd_datasource_set_active(get_node_field_value($current_dashboard,'field_dashboard_datasource')); } else { if ( !$active_datasource_name ) { if ( isset($_GET['ds']) && isset($datasources[$_GET['ds']]) ) { gd_datasource_set_active($_GET['ds']); } else { reset($results); try { if (!empty($results[key($results)])) { $active_datasource_name = get_node_field_value($results[key($results)],'field_dashboard_datasource'); gd_datasource_set_active($active_datasource_name); } else { return 'You have not been granted permission to view any dashboards.'; } } catch (Exception $e) { drupal_set_message('No default datasource set.', 'error'); LogHelper::log_error($e->getMessage()); } } } } // remove dashboards that do not belong to datasource of current dashboard $active_datasource_name = gd_datasource_get_active(); $dashboards = array(); foreach ( $results as $key => $dashboard ) { if ( $active_datasource_name === get_node_field_value($dashboard,'field_dashboard_datasource') ) { $dashboards[$key] = $dashboard; } } // remove dashboards that were not created by the user if ( gd_datasource_is_property($active_datasource_name, 'personal') ) { global $user; $userCreatedDashboards = array(); foreach ( $dashboards as $key => $dashboard ) { if ( $user->uid == $dashboard->uid ) { $userCreatedDashboards[$key] = $dashboard; } } $dashboards = $userCreatedDashboards; // overwrite dashboard list } } else { // get datasources that belong to the dashboards // weed out dashboards with missing datasource $datasources = array(); $publicDashboards = array(); foreach ( gd_dashboard_get_dashboards_public(LOAD_ENTITY) as $dashboard ) { $datasourceName = get_node_field_value($dashboard,'field_dashboard_datasource'); $datasource = gd_datasource_find($datasourceName); if ( !$datasource ) { continue; } $publicDashboards[$dashboard->nid] = $dashboard; if ( !isset($datasources[$datasourceName]) ) { $datasources[$datasource->name] = $datasource; } } // set current datamart if ( $current_dashboard ) { gd_datasource_set_active(get_node_field_value($current_dashboard,'field_dashboard_datasource')); } else { if ( isset($_GET['ds']) && isset($datasources[$_GET['ds']]) ) { gd_datasource_set_active($_GET['ds']); } else { gd_datasource_set_active(get_node_field_value($publicDashboards[key($publicDashboards)],'field_dashboard_datasource')); } } // remove dashboards that do not belong to datamart of current dashboard $active_datasource_name = gd_datasource_get_active(); $dashboards = array(); foreach ( $publicDashboards as $key => $dashboard ) { if ( $active_datasource_name === get_node_field_value($dashboard,'field_dashboard_datasource') ) { $dashboards[$key] = $dashboard; } } } reset($datasources); reset($dashboards); // sort the dashboard list by name usort($dashboards, function($a, $b) { if (strtolower($a->title) === strtolower($b->title)){ return strnatcmp($a->title,$b->title); } return strnatcasecmp($a->title,$b->title); }); // which dashboard to display if ( $current_dashboard ) { $dashboard = $current_dashboard; } else if (!empty($dashboards) ) { $dashboard = $dashboards[0]; } else { $dashboard = null; } $display_dashboards = array(); if ( !empty($dashboards) ) { $dashboard_ids = array(); // index of any parents from $dashboards $drilldown_dashboard_ids = array(); foreach ( $dashboards as $d ) { $config = new GD_DashboardConfig($d); $dashboard_ids[] = (int)$d->nid; foreach( $config->drilldowns as $drilldown) { if ( is_object($drilldown->dashboard) ) { $drilldown_dashboard_ids[] = (int)$drilldown->dashboard->id; // for backwards compatibility } else { $drilldown_dashboard_ids[] = (int)$drilldown->dashboard; } } } $drilldown_dashboard_ids = array_unique($drilldown_dashboard_ids); $display_dashboard_ids = array_diff($dashboard_ids, $drilldown_dashboard_ids); $display_dashboards = array(); foreach ( $dashboards as $d ) { if ( in_array($d->nid,$display_dashboard_ids) ) { $display_dashboards[] = $d; } } // if initial dashboard is a drilldown dashboard, load first non-drilldown dashboard instead if ( in_array($dashboard->nid, $drilldown_dashboard_ids) && empty($_GET['id']) ) { $dashboardKeys = array_keys($display_dashboard_ids); $dashboard = $dashboards[array_shift($dashboardKeys)]; } } // force a dashboard id into the url for javascript libs // TODO doing a redirect is wasteful, find some other way if ( empty($_GET['id']) && isset($dashboard) ) { drupal_goto('dashboards',array('query'=>array('id'=>$dashboard->nid))); } foreach ( $datasources as $k => $ds ) { if ( $ds->name == gd_datasource_get_active() ) { $datasources[$k]->active = true; } } return array($datasources, $dashboard, $display_dashboards); }
<div id="header-inside-left"> <?php if ($logo): ?> <a tabindex="5" href="javascript:void(0)" title="<?php print $site_name; ?>"> <img class="gd-logo" src="<?php print $logo; ?>" alt="<?php print $site_name; ?>"/> </a> <?php endif; ?> </div> <div id="header-inside-right"> <div id="search-area"> <?php if ($user->uid) : ?> <ul class="secondary-menu links clearfix"> <li class="first"><?php print l($user->firstname . ' ' . $user->lastname, 'user/profile', array('attributes' => array('tabindex' => '5'))); ?></li> <?php if (gd_account_user_is_admin() || gd_account_user_is_any_datasource_admin()) { print '<li>' . l("Control Panel", "cp", array('query'=>array('ds'=>gd_datasource_find_active()),'attributes' => array('tabindex' => '5'))) . '</li>'; } ?> <li class="last"><?php print l("Logout", "user/logout", array('attributes' => array('tabindex' => '5'),'query' => array('destination' => $_SERVER['REQUEST_URI']))); ?></li> </ul> <?php else : ?> <ul class="secondary-menu links clearfix"> <li class="last"> <?php if (!gd_security_is_single_sign_on()) { print l("Login", "user", array('attributes' => array('tabindex' => '5'))); } ?> </li> </ul> <?php endif; ?>
protected function prepareLookupDataTypes() { $lookupDataTypes = NULL; $metamodel = data_controller_get_metamodel(); $datasourceName = gd_datasource_find_active(); // selecting datasets which can be used as lookup foreach ($metamodel->datasets as $dataset) { $accessible = FALSE; if ($dataset->isPublic()) { // we need to include public datasets $accessible = TRUE; } elseif ($dataset->isProtected() && isset($datasourceName) && ($dataset->datasourceName == $datasourceName)) { // including protected datasets if they belong to active data source $accessible = TRUE; } if (!$accessible) { continue; } $primaryKeyColumnIndex = NULL; foreach ($dataset->getColumns() as $column) { if (!$column->isVisible()) { continue; } if ($column->isKey()) { // Composite key is not supported for lookup. There is no need to check rest of the columns if (isset($primaryKeyColumnIndex)) { continue 2; } else { $primaryKeyColumnIndex = $column->columnIndex; } } } // the dataset has to have single column primary key if (!isset($primaryKeyColumnIndex)) { continue; } // checking if the dataset is used as source for a cube. If yes, ignore it if ($metamodel->findCubeByDatasetName($dataset->name) != NULL) { continue; } $lookupDataTypes[] = $dataset->name; } return $lookupDataTypes; }