function gd_datasource_page_admin_retrieve ( $datasourceName ) {

    $EnvironmentMetaModel = data_controller_get_environment_metamodel();

    $DataSource = $EnvironmentMetaModel->getDataSource($datasourceName);

    $output  = '<h2>'.$DataSource->publicName.'</h2>';
    $output .= '<pre>'.print_r($DataSource,true).'</pre>';

    $output .= '<h3>Datasets</h3>';
    $output .= '<ul>';
    foreach ( gd_dataset_findall_by_datasource($datasourceName) as $dataset ) {
        $output .= '<li>'.$dataset->publicName.'</li>';
    }
    $output .= '</ul>';

    $output .= '<h3>Reports</h3>';
    $output .= '<ul>';
    foreach ( gd_report_findall_by_datasource(LOAD_ENTITY,$datasourceName) as $report ) {
        $output .= '<li>'.$report->title.'</li>';
    }
    $output .= '</ul>';

    $output .= '<h3>Dashboards</h3>';
    $output .= '<ul>';
    foreach ( gd_dashboard_findall_by_datasource(LOAD_ENTITY,$datasourceName) as $dashboard ) {
        $output .= '<li>'.$dashboard->title.'</li>';
    }
    $output .= '</ul>';


    return array('datasource_info'=>array(
        '#markup' => $output
    ));
}
function gd_sync_admin_datamart_form ( $form, &$form_state ) {
    // Enable language column if translation module is enabled or if we have any
    // node with language.
    $multilanguage = (module_exists('translation') || db_query_range("SELECT 1 FROM {node} WHERE language <> :language", 0, 1, array(':language' => LANGUAGE_NONE))->fetchField());

    // Build the sortable table header.
    $header = array(
        'title' => array('data' => t('Title'), 'field' => 'n.title'),
        'author' => t('Author'),
        'changed' => array('data' => t('Updated'), 'field' => 'n.changed', 'sort' => 'desc'),
        'datasets' => t('Datasets'),
        'reports' => t('Reports'),
        'dashboards' => t('Dashboards')
    );
    if ($multilanguage) {
        $header['language'] = array('data' => t('Language'), 'field' => 'n.language');
    }
    $header['operations'] = array('data' => t('Operations'));

    $nodes = gd_datamart_get_datamarts(LOAD_ENTITY);

    // Prepare the list of nodes.
    $languages = language_list();
    $destination = drupal_get_destination();
    $options = array();
    foreach ($nodes as $node) {
        $langcode = entity_language('node', $node);
        $l_options = $langcode != LANGUAGE_NONE && isset($languages[$langcode]) ? array('language' => $languages[$langcode]) : array();
        $options[$node->nid] = array(
            'title' => array(
                'data' => array(
                    '#type' => 'link',
                    '#title' => $node->title,
                    '#href' => 'admin/structure/govdashboard/sync/datamart/' . $node->nid,
                    '#options' => $l_options,
                    '#suffix' => ' ' . theme('mark', array('type' => node_mark($node->nid, $node->changed))),
                ),
            ),
            'author' => theme('username', array('account' => $node)),
            'changed' => format_date($node->changed, 'short'),
            'datasets' => count(gd_dataset_findall_by_datasource(!LOAD_ENTITY,get_node_field_value($node,'field_datamart_sysname'))),
            'reports' => count(gd_report_findall_by_datasource(!LOAD_ENTITY,get_node_field_value($node,'field_datamart_sysname'))),
            'dashboards' => count(gd_dashboard_findall_by_datasource(!LOAD_ENTITY,get_node_field_value($node,'field_datamart_sysname')))
        );
        if ($multilanguage) {
            if ($langcode == LANGUAGE_NONE || isset($languages[$langcode])) {
                $options[$node->nid]['language'] = $langcode == LANGUAGE_NONE ? t('Language neutral') : t($languages[$langcode]->name);
            }
            else {
                $options[$node->nid]['language'] = t('Undefined language (@langcode)', array('@langcode' => $langcode));
            }
        }
        // Build a list of all the accessible operations for the current node.
        $operations = array();
        if (node_access('update', $node)) {
            $operations['edit'] = array(
                'title' => t('edit'),
                'href' => 'node/' . $node->nid . '/edit',
                'query' => $destination,
            );
        }
        $options[$node->nid]['operations'] = array();
        if (count($operations) > 1) {
            // Render an unordered list of operations links.
            $options[$node->nid]['operations'] = array(
                'data' => array(
                    '#theme' => 'links__node_operations',
                    '#links' => $operations,
                    '#attributes' => array('class' => array('links', 'inline')),
                ),
            );
        }
        elseif (!empty($operations)) {
            // Render the first and only operation as a link.
            $link = reset($operations);
            $options[$node->nid]['operations'] = array(
                'data' => array(
                    '#type' => 'link',
                    '#title' => $link['title'],
                    '#href' => $link['href'],
                    '#options' => array('query' => $link['query']),
                ),
            );
        }
    }

    $form['nodes'] = array(
        '#type' => 'tableselect',
        '#header' => $header,
        '#options' => $options,
        '#empty' => t('No content available.'),
    );

    return $form;
}