Generate the report DOM document to pass to the report renderer.

@param array $tables
@param Config $config

@return Document
430681
private function generateDocument(array $tables, Config $config)
    {
        $document = new Document();
        $reportsEl = $document->createRoot('reports');
        $reportsEl->setAttribute('name', 'table');
        $reportEl = $reportsEl->appendElement('report');
        $classMap = array_merge(
            $this->classMap,
            $config['class_map']
        );

        if (isset($config['title'])) {
            $reportEl->setAttribute('title', $config['title']);
        }

        if (isset($config['description'])) {
            $reportEl->appendElement('description', $config['description']);
        }

        foreach ($tables as $breakHash => $table) {
            $tableEl = $reportEl->appendElement('table');

            // Build the col(umn) definitions.
            foreach ($table as $row) {
                $colsEl = $tableEl->appendElement('cols');

                foreach ($row->getNames() as $colName) {
                    $colEl = $colsEl->appendElement('col');
                    $colEl->setAttribute('name', $colName);

                    // column labels are the column names by default.
                    // the user may override by column name or column index.
                    $colLabel = $colName;

                    if (isset($config['labels'][$colName])) {
                        $colLabel = $config['labels'][$colName];
                    }

                    $colEl->setAttribute('label', $colLabel);
                }

                break;
            }

            if ($breakHash) {
                $tableEl->setAttribute('title', $breakHash);
            }

            $groupEl = $tableEl->appendElement('group');
            $groupEl->setAttribute('name', 'body');

            foreach ($table as $row) {
                $rowEl = $groupEl->appendElement('row');

                // apply formatter options
                foreach ($row->getFormatParams() as $paramName => $paramValue) {
                    $paramEl = $rowEl->appendElement('formatter-param', $paramValue);
                    $paramEl->setAttribute('name', $paramName);
                }

                foreach ($row as $key => $value) {
                    $cellEl = $rowEl->appendElement('cell', $value);
                    $cellEl->setAttribute('name', $key);

                    if (isset($classMap[$key])) {
                        $cellEl->setAttribute('class', implode(' ', $classMap[$key]));
                    }
                }
            }
        }

        return $document;
    }
1241296
private function processCompare(array $tables, Config $config)
    {
        if (!isset($config['compare'])) {
            return $tables;
        }

        $conditions = array_diff($config['cols'], $this->statKeys, [$config['compare']]);
        $compare = $config['compare'];
        $compareFields = $config['compare_fields'];

        return F\map($tables, function ($table) use ($conditions, $compare, $compareFields) {
            $groups = F\group($table, function ($row) use ($conditions) {
                $values = array_intersect_key($row->getArrayCopy(), array_flip($conditions));

                return F\reduce_left($values, function ($value, $i, $c, $reduction) {
                    return $reduction . $value;
                });
            });

            $table = [];
            $colNames = null;

            foreach ($groups as $group) {
                $firstRow = null;

                foreach ($group as $row) {
                    if (null === $firstRow) {
                        $firstRow = $row->newInstance(array_diff_key($row->getArrayCopy(), array_flip($this->statKeys)));

                        if (isset($firstRow[$compare])) {
                            unset($firstRow[$compare]);
                        }

                        foreach ($compareFields as $compareField) {
                            if (isset($firstRow[$compareField])) {
                                unset($firstRow[$compareField]);
                            }
                        }
                    }

                    if (null === $colNames) {
                        $colNames = array_combine($firstRow->getNames(), $firstRow->getNames());
                    }

                    $compared = $row[$compare];

                    foreach ($compareFields as $compareField) {
                        $name = $compare . ':' . $compared . ':' . $compareField;

                        $name = $this->resolveCompareColumnName($firstRow, $name);

                        $firstRow[$name] = $row[$compareField];
                        $colNames[$name] = $name;

                        // TODO: This probably means the field is non-comparable, could handle this earlier..
                        if (isset($this->classMap[$compareField])) {
                            // we invent a new col name here, use the compare field's class.
                            $this->classMap[$name] = $this->classMap[$compareField];
                        }
                    }
                }

                $table[] = $firstRow;
            }

            $table = F\map($table, function ($row) use ($colNames) {
                $newRow = $row->newInstance([]);

                foreach ($colNames as $colName) {
                    $newRow[$colName] = isset($row[$colName]) ? $row[$colName] : null;
                }

                return $newRow;
            });

            return $table;
        });

        return $tables;
    }
1343504
public function render(Document $reportDom, Config $config)
    {
        foreach ($reportDom->firstChild->query('./report') as $reportEl) {
            $title = $reportEl->getAttribute('title');

            if ($title) {
                $this->output->writeln(sprintf('<title>%s</title>', $title));
                $this->output->writeln(sprintf('<title>%s</title>', str_repeat('=', strlen($title))));
                $this->output->write(PHP_EOL);
            }

            foreach ($reportEl->query('./description') as $descriptionEl) {
                $this->output->writeln(sprintf('<description>%s</description>', $descriptionEl->nodeValue));
                $this->output->writeln('');
            }

            foreach ($reportEl->query('.//table') as $tableEl) {
                $this->output->writeln(sprintf('<subtitle>%s</subtitle>', $tableEl->getAttribute('title')));
                $this->renderTableElement($tableEl, $config);
            }
        }
    }
1192454
public function renderer($config = null)
    {
        if ($config !== null) {
            $this->_renderer = new CakePdf($config);
        }

        return $this->_renderer;
    }
125677
public function renderWidget( $config = [] ) {

		$containerHtml	= $this->container ? $this->renderContainer( $config ) : null;

		$draggerHtml	= $this->dragger ? $this->renderDragger( $config ) : null;

		$chooserHtml	= $this->chooser ? $this->renderChooser( $config ) : null;

		$preloaderHtml	= $this->preloader ? $this->renderPreloader( $config ) : null;

		$infoHtml		= $this->info ? $this->renderInfo( $config ) : null;

		$fieldsHtml		= $this->fields ? $this->renderFields( $config ) : null;

		$formHtml		= $this->form ? $this->renderForm( $config, [ 'infoHtml' => $infoHtml, 'fieldsHtml' => $fieldsHtml ] ) : null;

		$uploaderView	= CodeGenUtil::isAbsolutePath( $this->uploaderView ) ? $this->uploaderView : "$this->template/$this->uploaderView";

		$widgetHtml = $this->render( $uploaderView, [
			'widget' => $this,
			'containerHtml' => $containerHtml,
			'draggerHtml' => $draggerHtml,
			'chooserHtml' => $chooserHtml,
			'preloaderHtml' => $preloaderHtml,
			'infoHtml' => $infoHtml,
			'fieldsHtml' => $fieldsHtml,
			'formHtml' => $formHtml
		] );

		if( $this->wrap ) {

			return Html::tag( $this->wrapper, $widgetHtml, $this->options );
		}

		return $widgetHtml;
	}
334052
public function getParser(array $config = null)
	{
		$this->configOptimizer->reset();

		// Get the stylesheet used for rendering
		$xslt      = new XSLT;
		$xslt->optimizer->normalizer->remove('RemoveLivePreviewAttributes');
		$this->xsl = $xslt->getXSL($this->configurator->rendering);

		// Prepare the parser's config
		$this->config = (isset($config)) ? $config : $this->configurator->asConfig();
		$this->config = ConfigHelper::filterConfig($this->config, 'JS');
		$this->config = $this->callbackGenerator->replaceCallbacks($this->config);

		// Get the parser's source and inject its config
		$src = $this->getHints() . $this->injectConfig($this->getSource());

		// Export the public API
		$src .= "if (!window['s9e']) window['s9e'] = {};\n" . $this->getExports();

		// Minify the source
		$src = $this->getMinifier()->get($src);

		// Wrap the source in a function to protect the global scope
		$src = '(function(){' . $src . '})()';

		return $src;
	}
915820
public function renderWidget( $config = [] ) {

		$gallery		= $this->gallery;
		$items 			= [];
		$galleryHtml	= '';

		// Paths
		$wrapperPath	= $this->template . '/wrapper';
		$itemPath		= $this->template . '/item';

		// Generate Items Html

		$gitems = $gallery->files;

	    foreach( $gitems as $item ) {

	        $items[] = $this->render( $itemPath, [ 'item' => $item ] );
	    }

		$itemsHtml		= implode( "\n", $items );

		$galleryHtml	= $this->render( $wrapperPath, [ 'gallery' => $gallery, 'itemsHtml' => $itemsHtml ] );

		return $galleryHtml;
	}
1049319
protected function generateTablesAndIndices( array $tables )
	{
		$this->method = 'create';

		foreach ( $tables as $table ) {
			$this->table = $table;
			$this->migrationName = 'create_'. $this->table .'_table';
			$this->fields = $this->schemaGenerator->getFields( $this->table );

			$this->generate();
		}
	}
959069
public function renderFields( $config = [] ) {

		$fieldsView = CodeGenUtil::isAbsolutePath( $this->fieldsView, true ) ? $this->fieldsView : "$this->template/$this->fieldsView";

		return $this->render( $fieldsView, [ 'widget' => $this ] );
	}
2120
protected function convertToExcel(array $data, array $config): Collection
    {
        $uses = $config['uses'] ?? 'data';
        $content = $data[$uses] ?? [];

        if ($content instanceof Arrayable) {
            $content = $content->toArray();
        }

        return Collection::make(\array_map([$this, 'transformToArray'], $content));
    }
1182993
public function asHtml($config)
    {
        $class = $config['class'];
        $dates = $config['dates'];

        $daysOfTheWeek = [
            'Monday',
            'Tuesday',
            'Wednesday',
            'Thursday',
            'Friday',
            'Saturday',
            'Sunday',
        ];

        $output = '<table class="'.$class.'">';
        $output .= '<thead>';
        foreach ($daysOfTheWeek as $day) {
            $output .= '<th>'.$day.'</th>';
        }
        $output .= '</thead>';

        foreach ($this->weeks as $week) {
            $output .= '<tr>';
            foreach (range(1, 7) as $dayAsNumber) {
                if (isset($week[$dayAsNumber])) {
                    $content = '';
                    if (isset($dates[$week[$dayAsNumber]->toDateString()])) {
                        $content = $dates[$week[$dayAsNumber]->toDateString()];
                    }

                    if (is_array($content)) {
                        $itemString = '';
                        foreach ($content as $item) {
                            if (config('app.locale') !== config('cms.default-language')) {
                                if ($item->translationData(config('app.locale'))) {
                                    $itemString .= '<a href="'.url('events/event/'.$item->id).'">'.$item->translationData(config('app.locale'))->title.'</a><br>';
                                }
                            } else {
                                $itemString .= '<a href="'.url('events/event/'.$item->id).'">'.$item->title.'</a><br>';
                            }
                        }
                        $content = $itemString;
                    }

                    $output .= '<td><span class="date"><a href="'.url('events/date/'.$week[$dayAsNumber]->format('Y-m-d')).'">'.$week[$dayAsNumber]->toFormattedDateString().'</a></span><span class="content">'.$content.'</span></td>';
                } else {
                    $output .= '<td>&nbsp;</td>';
                }
            }
            $output .= '</tr>';
        }
        $output .= '</table>';

        return $output;
    }
228576
public function getTemplate(array $config)
	{
		foreach ($this->templateGenerators as $type => $generator)
		{
			if (isset($config[$type]))
			{
				return $generator->getTemplate($config[$type]);
			}
		}

		return '';
	}
569513
public function createCRUD($config, $section, $table, $splitTable)
    {
        $bar = $this->output->createProgressBar(7);

        try {
            $this->crudService->generateCore($config, $bar);
            $this->crudService->generateAppBased($config, $bar);

            $this->crudGenerator->createTests(
                $config,
                $this->option('serviceOnly'),
                $this->option('apiOnly'),
                $this->option('api')
            );
            $bar->advance();

            $this->crudGenerator->createFactory($config);
            $bar->advance();

            $this->crudService->generateAPI($config, $bar);
            $bar->advance();

            $this->crudService->generateDB($config, $bar, $section, $table, $splitTable, $this);
            $bar->finish();

            $this->crudReport($table);
        } catch (Exception $e) {
            throw new Exception('Unable to generate your CRUD: ('.$e->getFile().':'.$e->getLine().') '.$e->getMessage(), 1);
        }
    }
896487
protected function generateConfigContent(array $config)
    {
        /* This code is taken from ZF2s' classmap_generator.php script. */

        // Create a file with the class/file map.
        // Stupid syntax highlighters make separating < from PHP declaration necessary
        $content = '<' . "?php\n"
                   . "\n"
                   . 'return ' . var_export($config, true) . ';';

        // Fix \' strings from injected DIRECTORY_SEPARATOR usage in iterator_apply op
        $content = str_replace("\\'", "'", $content);


        // Remove unnecessary double-backslashes
        $content = str_replace('\\\\', '\\', $content);

        // Exchange "array (" width "array("
        $content = str_replace('array (', 'array(', $content);

        // Make the file end by EOL
        $content = rtrim($content, "\n") . "\n";

        var_export($config, true);

        return $content;
    }
787219
public function plainText(MailConfig $config, array $data)
    {
        $plainTemplate = $config->template().$this->plainSuffix;

        if ($this->views->exists($plainTemplate)) {
            return $this->views->make($plainTemplate, $data)->render();
        }

        if (!$this->htmlPlainConverter) {
            return '';
        }

        return call_user_func($this->htmlPlainConverter, $this->html($config, $data),  $data);
    }
1306270
public function getPublisherHTML($config = array())
    {
    // Initialize.
        $session_secret = "";
        $fields = array('config' => $config);
        $webservice_url = '/ws/setruntimeoptions/' . $this->publisherKey;

        // If necessary, process the config data.
        if ( ! empty($config))
        {
            // Add the gameid to the options url.
            if (array_key_exists("gameid", $config))
            {
                $webservice_url .= '/' . $config['gameid'];
            }
        }

        // Call the webservice and get the response.
        $resp = $this->doHttpsPostReturnJSONArray($this->webService, $webservice_url, $fields);
        if ($resp)
        {
            // Get the session secret from the response.
            $session_secret = $resp->session_secret;

            // Build the url to the AYAH webservice.
            $url = 'https://';                      // The AYAH webservice API requires https.
            $url.= $this->webService;               // Add the host.
            $url.= "/ws/script/";                       // Add the path to the API script.
            $url.= urlencode($this->publisherKey);          // Add the encoded publisher key.
            $url.= (empty($session_secret))? "" : "/".$session_secret;  // If set, add the session_secret.

            // Build and return the needed HTML code.
            return "<div id='AYAH'></div><script src='". $url ."' type='text/javascript' language='JavaScript'></script>";
        }
        else
        {
            // Build and log a detailed message.
            $url = "https://".$this->webService.$webservice_url;
            $message = "Unable to connect to the AYAH webservice server.  url='$url'";

            // Build and display a helpful message to the site user.
            $style = "padding: 10px; border: 1px solid #EED3D7; background: #F2DEDE; color: #B94A48;";
            $message = "Unable to load the <i>Are You a Human</i> PlayThru&trade;.  Please contact the site owner to report the problem.";
            echo "<p style=\"$style\">$message</p>\n";
        }
    }
60876
public static function insert($table, $data = array(), $config = array()) {
        DB::connect();
        return DB::$connection->insert($table, $data, $config);
    }