<commit_before><?php

namespace Backend\Modules\MediaLibrary\Actions;

use Backend\Core\Engine\Base\ActionIndex as BackendBaseActionIndex;
use Backend\Core\Engine\DataGridDB;
use Backend\Core\Language\Language;
use Backend\Modules\MediaLibrary\Engine\Model as BackendMediaLibraryModel;
use Backend\Modules\MediaLibrary\Domain\MediaFolder\MediaFolder;
use Backend\Modules\MediaLibrary\Domain\MediaItem\Type;
use Backend\Modules\MediaLibrary\Domain\MediaItem\MediaItemDataGrid;

/**
 * This is the index-action, it will display the overview of MediaItem items.
 */
class Index extends BackendBaseActionIndex
{
    /**
     * Execute the action
     *
     * @return void
     */
    public function execute()
    {
        // call parent, this will probably add some general CSS/JS or other required files
        parent::execute();

        // Parse JS files
        $this->parseFiles();

        /** @var MediaFolder|null $mediaFolder */
        $mediaFolder = $this->getMediaFolder();

        /** @var array $possibleTypes */
        $possibleTypes = Type::getPossibleValues();

        /** @var array $dataGrids */
        $dataGrids = $this->getDataGrids(
            $mediaFolder,
            $possibleTypes
        );

        // Assign variables
        $this->tpl->assign('tree', BackendMediaLibraryModel::getTreeHTML());
        $this->tpl->assign('mediaFolder', $mediaFolder);
        $this->tpl->assign('mediaFolders', $this->getMediaFoldersForDropdown($mediaFolder));
        $this->tpl->assign('dataGrids', $dataGrids);
        $this->tpl->assign('hasResults', ($this->getTotalFolderCount($dataGrids)) > 0);
        $this->header->addJsData('MediaLibrary', 'openedFolderId', ($mediaFolder !== null) ? $mediaFolder->getId() : null);

        $this->display();
    }

    /**
     * @param MediaFolder|null $mediaFolder
     * @param $possibleTypes
     * @return array
     */
    private function getDataGrids(MediaFolder $mediaFolder = null, $possibleTypes)
    {
        $dataGrids = array();

        /** @var string $type */
        foreach ($possibleTypes as $type) {
            /** @var DataGridDB $dataGrid */
            $dataGrid = MediaItemDataGrid::getDataGrid(
                $type,
                ($mediaFolder !== null) ? $mediaFolder->getId() : null
            );

            // create datagrid
            $dataGrids[$type] = [
                'label' => Language::lbl('MediaMultiple' . ucfirst($type)),
                'tabName' => 'tab' . ucfirst($type),
                'type' => $type,
                'dataGrid' => $dataGrid->getContent(),<commit_msg>multi-lining<commit_after><?php

namespace Backend\Modules\MediaLibrary\Actions;

use Backend\Core\Engine\Base\ActionIndex as BackendBaseActionIndex;
use Backend\Core\Engine\DataGridDB;
use Backend\Core\Language\Language;
use Backend\Modules\MediaLibrary\Engine\Model as BackendMediaLibraryModel;
use Backend\Modules\MediaLibrary\Domain\MediaFolder\MediaFolder;
use Backend\Modules\MediaLibrary\Domain\MediaItem\Type;
use Backend\Modules\MediaLibrary\Domain\MediaItem\MediaItemDataGrid;

/**
 * This is the index-action, it will display the overview of MediaItem items.
 */
class Index extends BackendBaseActionIndex
{
    /**
     * Execute the action
     *
     * @return void
     */
    public function execute()
    {
        // call parent, this will probably add some general CSS/JS or other required files
        parent::execute();

        // Parse JS files
        $this->parseFiles();

        /** @var MediaFolder|null $mediaFolder */
        $mediaFolder = $this->getMediaFolder();

        /** @var array $possibleTypes */
        $possibleTypes = Type::getPossibleValues();

        /** @var array $dataGrids */
        $dataGrids = $this->getDataGrids(
            $mediaFolder,
            $possibleTypes
        );

        // Assign variables
        $this->tpl->assign('tree', BackendMediaLibraryModel::getTreeHTML());
        $this->tpl->assign('mediaFolder', $mediaFolder);
        $this->tpl->assign('mediaFolders', $this->getMediaFoldersForDropdown($mediaFolder));
        $this->tpl->assign('dataGrids', $dataGrids);
        $this->tpl->assign('hasResults', ($this->getTotalFolderCount($dataGrids)) > 0);
        $this->header->addJsData('MediaLibrary', 'openedFolderId',
            ($mediaFolder !== null) ? $mediaFolder->getId() : null);

        $this->display();
    }

    /**
     * @param MediaFolder|null $mediaFolder
     * @param $possibleTypes
     * @return array
     */
    private function getDataGrids(MediaFolder $mediaFolder = null, $possibleTypes)
    {
        $dataGrids = array();

        /** @var string $type */
        foreach ($possibleTypes as $type) {
            /** @var DataGridDB $dataGrid */
            $dataGrid = MediaItemDataGrid::getDataGrid(
                $type,
                ($mediaFolder !== null) ? $mediaFolder->getId() : null
            );

            // create datagrid
            $dataGrids[$type] = [
                'label' => Language::lbl('MediaMultiple' . ucfirst($type)),
                'tabName' => 'tab' . ucfirst($type),
                'type' => $type,
                'dataGrid' => $dataGrid->getContent(),
{'fraction_non_alphanumeric': 0.13927952225004817, 'fraction_numerical': 0.00038528221922558276, 'mean_word_length': 2.5757575757575757, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5778987', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1454, 'n_words': 289}