コード例 #1
0
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
    ));
}
コード例 #2
0
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;
}
コード例 #3
0
 public static function getExportables($datasourceName) {
     return gd_report_findall_by_datasource(LOAD_ENTITY,$datasourceName);
 }
コード例 #4
0
    protected function update(Import\ImportStream $stream, Import\ImportContext $context) {
        $dashboards = $stream->get('dashboards');
        if (empty($dashboards)) {
            return;
        }

        $this->datasourceName = $context->get('datasourceName');

        $this->reports = gd_report_findall_by_datasource(LOAD_ENTITY,$this->datasourceName);

        $metamodel = data_controller_get_metamodel();
        $this->datasets = $metamodel->datasets;

        foreach ( $dashboards as $dashboardKey => $dashboard ) {
            $dashboard = (object) $dashboard;
            $existingDashboard = gd_dashboard_get_by_uuid($dashboard->uuid,$this->datasourceName);
            if ( !$existingDashboard ) {
                // create
                $node = $this->createDashboard($dashboard);
                if ( !empty($node->nid ) ) {
                    $dashboards[$dashboardKey] = $node;
                } else {
                    throw new Exception('Dashboard node creation failed');
                }
            } else {
                $existingDashboard->title = $dashboard->title;
                $existingDashboard->field_dashboard_desc[$existingDashboard->language][0]['value'] = $dashboard->description;
                $existingDashboard->field_dashboard_datasource[$existingDashboard->language][0]['value'] = $this->datasourceName;
                $existingDashboard->field_dashboard_custom_view[$existingDashboard->language][0]['value'] = $dashboard->custom_view;
                $existingDashboard->field_dashboard_public[$existingDashboard->language][0]['value'] = (int) $dashboard->public;

                // update report references
                $existingDashboard->field_dashboard_reports[$existingDashboard->language] = array();
                foreach ( $dashboard->reports as $reportUuid ) {
                    $reportNode = gd_report_get_by_uuid($reportUuid,$this->datasourceName);
                    $existingDashboard->field_dashboard_reports[$existingDashboard->language][] = array('nid'=>$reportNode->nid);
                }

                $this->processConfigReports($dashboard->config);
                $existingDashboard->field_dashboard_config[$existingDashboard->language][0]['value'] = json_encode($dashboard->config);

                gd_dashboard_save($existingDashboard);

                $event = new DefaultEvent();
                $event->type = 101; // see gd_health_monitoring_database_install() for more details
                $event->owner = $existingDashboard->nid;
                EventRecorderFactory::getInstance()->record($event);

                $dashboards[$dashboardKey] = $existingDashboard;
            }
        }

        // update report/dashboard ids in config, for linking
        foreach ( $dashboards as $dashboardKey => $dashboard ) {
            $config = json_decode($dashboard->field_dashboard_config[$dashboard->language][0]['value']);

            $this->processConfigDashboards($config);

            $dashboards[$dashboardKey]->field_dashboard_config[$dashboards[$dashboardKey]->language][0]['value'] = json_encode($config);
            gd_dashboard_save($dashboards[$dashboardKey]);
        }
    }