<commit_before><?php

namespace Backend\Core\Engine;

use Backend\Core\Engine\Model as BackendModel;
use Backend\Core\Language\Language as BackendLanguage;
use SpoonDatagridSource;
use SpoonFormDropdown;

/**
 * This is our extended version of \SpoonDataGrid
 * This class will handle a lot of stuff for you, for example:
 *    - it will set debug mode
 *    - it will set the compile-directory
 *    - ...
 */
class DataGrid extends \SpoonDataGrid
{
    /**
     * Map of icons by given action name
     *
     * @todo this map is not full
     *
     * @var array
     */
    private static $mapIcons = [
        'add' => 'fa-plus',
        'copy' => 'fa-copy',
        'edit' => 'fa-pencil',
        'import' => 'fa-download',
        'export' => 'fa-upload',
        'delete' => 'fa-trash-o',
        'detail' => 'fa-eye',
        'details' => 'fa-eye',
        'approve' => 'fa-thumbs-o-up',
        'mark_as_spam' => 'fa-ban',
        'install' => 'fa-download',
        'use_revision' => 'fa-file-o',
        'use_draft' => 'fa-file-o',
        'custom_fields' => 'fa-tasks',
    ];

    public function __construct(SpoonDatagridSource $source)
    {
        parent::__construct($source);

        // set debugmode, this will force the recompile for the used templates
        $this->setDebug(BackendModel::getContainer()->getParameter('kernel.debug'));

        // set the compile-directory, so compiled templates will be in a folder that is writable
        $this->setCompileDirectory(BACKEND_CACHE_PATH . '/CompiledTemplates');

        // set attributes for the datagrid
        $this->setAttributes(['class' => 'table table-hover table-striped fork-data-grid jsDataGrid']);

        // id gets special treatment
        if (in_array('id', $this->getColumns(), true)) {
            // hide the id by defaults
            $this->setColumnsHidden(['id']);

            // our JS needs to know an id, so we can highlight it
            $this->setRowAttributes(['id' => 'row-[id]']);
        }

        // set default sorting options
        $this->setSortingOptions();

        // add classes on headers
        foreach ($this->getColumns() as $column) {
            // set class
            $this->setColumnHeaderAttributes($column, ['class' => $column]);

            // set default label
            $this->setHeaderLabels(
                [$column => \SpoonFilter::ucfirst(BackendLanguage::lbl(\SpoonFilter::toCamelCase($column)))]
            );
        }

        // set paging class
        $this->setPagingClass(DataGridPaging::class);

        // set default template
        $this->setTemplate(BACKEND_CORE_PATH . '/Layout/Templates/Datagrid.tpl');
    }

    /**
     * Adds a new column
     *
     * @param string $name The name for the new column.
     * @param string $label The label for the column.
     * @param string $value The value for the column.
     * @param string $url The URL for the link inside the column.
     * @param string $title A title for the image inside the column.
     * @param string $image An URL to the image inside the column.
     * @param int $sequence The sequence for the column.
     */
    public function addColumn(
        $name,
        $label = null,
        $value = null,
        $url = null,
        $title = null,
        $image = null,
        $sequence = null
    ) {
        // make sure we use a lowercased column in all checks
        $lowercasedName = mb_strtolower($name);

        $icon = $this->decideIcon($name);

        // known actions that should have a button
        if (in_array(
            $lowercasedName,
            ['add', 'edit', 'delete', 'detail', 'details', 'approve', 'mark_as_spam', 'install'],
            true
        )) {
            // rebuild value, it should have special markup
            $value =
                '<a href="' . $url . '" class="btn btn-default btn-xs pull-right">' .
                ($icon ? '<span class="fa ' . $icon . '"></span>&nbsp;' : '') .
                $value .
                '</a>';

            // reset URL
            $url = null;
        }

        if (in_array($lowercasedName, ['use_revision', 'use_draft'], true)) {
            // rebuild value, it should have special markup
            $value =
                '<a href="' . $url . '" class="btn btn-default btn-xs">' .
                ($icon ? '<span class="fa ' . $icon . '"></span>&nbsp;' : '') .
                $value .
                '</a>';

            // reset URL
            $url = null;
        }<commit_msg>Fix datagrid icons not accessible<commit_after><?php

namespace Backend\Core\Engine;

use Backend\Core\Engine\Model as BackendModel;
use Backend\Core\Language\Language as BackendLanguage;
use SpoonDatagridSource;
use SpoonFormDropdown;

/**
 * This is our extended version of \SpoonDataGrid
 * This class will handle a lot of stuff for you, for example:
 *    - it will set debug mode
 *    - it will set the compile-directory
 *    - ...
 */
class DataGrid extends \SpoonDataGrid
{
    /**
     * Map of icons by given action name
     *
     * @todo this map is not full
     *
     * @var array
     */
    private static $mapIcons = [
        'add' => 'fa-plus',
        'copy' => 'fa-copy',
        'edit' => 'fa-pencil',
        'import' => 'fa-download',
        'export' => 'fa-upload',
        'delete' => 'fa-trash-o',
        'detail' => 'fa-eye',
        'details' => 'fa-eye',
        'approve' => 'fa-thumbs-o-up',
        'mark_as_spam' => 'fa-ban',
        'install' => 'fa-download',
        'use_revision' => 'fa-file-o',
        'use_draft' => 'fa-file-o',
        'custom_fields' => 'fa-tasks',
    ];

    public function __construct(SpoonDatagridSource $source)
    {
        parent::__construct($source);

        // set debugmode, this will force the recompile for the used templates
        $this->setDebug(BackendModel::getContainer()->getParameter('kernel.debug'));

        // set the compile-directory, so compiled templates will be in a folder that is writable
        $this->setCompileDirectory(BACKEND_CACHE_PATH . '/CompiledTemplates');

        // set attributes for the datagrid
        $this->setAttributes(['class' => 'table table-hover table-striped fork-data-grid jsDataGrid']);

        // id gets special treatment
        if (in_array('id', $this->getColumns(), true)) {
            // hide the id by defaults
            $this->setColumnsHidden(['id']);

            // our JS needs to know an id, so we can highlight it
            $this->setRowAttributes(['id' => 'row-[id]']);
        }

        // set default sorting options
        $this->setSortingOptions();

        // add classes on headers
        foreach ($this->getColumns() as $column) {
            // set class
            $this->setColumnHeaderAttributes($column, ['class' => $column]);

            // set default label
            $this->setHeaderLabels(
                [$column => \SpoonFilter::ucfirst(BackendLanguage::lbl(\SpoonFilter::toCamelCase($column)))]
            );
        }

        // set paging class
        $this->setPagingClass(DataGridPaging::class);

        // set default template
        $this->setTemplate(BACKEND_CORE_PATH . '/Layout/Templates/Datagrid.tpl');
    }

    /**
     * Adds a new column
     *
     * @param string $name The name for the new column.
     * @param string $label The label for the column.
     * @param string $value The value for the column.
     * @param string $url The URL for the link inside the column.
     * @param string $title A title for the image inside the column.
     * @param string $image An URL to the image inside the column.
     * @param int $sequence The sequence for the column.
     */
    public function addColumn(
        $name,
        $label = null,
        $value = null,
        $url = null,
        $title = null,
        $image = null,
        $sequence = null
    ) {
        // make sure we use a lowercased column in all checks
        $lowercasedName = mb_strtolower($name);

        $icon = $this->decideIcon($name);

        // known actions that should have a button
        if (in_array(
            $lowercasedName,
            ['add', 'edit', 'delete', 'detail', 'details', 'approve', 'mark_as_spam', 'install'],
            true
        )) {
            // rebuild value, it should have special markup
            $value =
                '<a href="' . $url . '" class="btn btn-default btn-xs pull-right">' .
                ($icon ? '<span class="fa ' . $icon . '" aria-hidden="true"></span>&nbsp;' : '') .
                $value .
                '</a>';

            // reset URL
            $url = null;
        }

        if (in_array($lowercasedName, ['use_revision', 'use_draft'], true)) {
            // rebuild value, it should have special markup
            $value =
                '<a href="' . $url . '" class="btn btn-default btn-xs">' .
                ($icon ? '<span class="fa ' . $icon . '"></span>&nbsp;' : '') .
                $value .
                '</a>';

            // reset URL
            $url = null;
        }
{'fraction_non_alphanumeric': 0.13874489908459248, 'fraction_numerical': 0.0, 'mean_word_length': 1.90176, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 83, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3294858', 'n_tokens_mistral': 2637, 'n_tokens_neox': 2580, 'n_words': 752}