<commit_before><?php

namespace Modularity\Module\FilesList;

class FilesList extends \Modularity\Module
{
    public $slug = 'fileslist';
    public $supports = array();

    public function init()
    {
        $this->nameSingular = __("Files", 'modularity');
        $this->namePlural = __("Files", 'modularity');
        $this->description = __("Outputs a file archive.", 'modularity');
    }

    public function data() : array
    {
        $data = array();
        $data['listId'] = 'files_' . uniqid();
        $data['columnData'] = $this->prepareColumnData($files);
        $data['headings'] = $this->prepareHeadings(['File', 'Description']);
        $data['showFilters'] = !empty(get_field('show_filter', $this->ID));
        $data['classes'] = implode(' ', apply_filters('Modularity/Module/Classes', array('box', 'box-panel'), $this->post_type, $this->args));

        return $data;
    }


    private function prepareHeadings($headings) {
        foreach($headings as &$heading) {
            
            $heading = translate($heading, 'modularity');
        }
        return $headings;
    }

    private function prepareColumnData()
    {
        $files = get_field('file_list', $this->ID);
        $columnData = [];

        foreach ($files as $item) {
            $columnData['href'] = $item['file']['url'];

            $columnData[] = [
                'columns' => 
                [
                    $item['file']['title'],
                    $item['file']['description']
                ],
                'href' => $item['file']['url']
            ];
        }

        return $columnData;
    }

    /**
     * Available "magic" methods for modules:
     * init()            What to do on initialization
     * data()            Use to send data to view (return array)
     * style()           Enqueue style only when module is used on page
     * script            Enqueue script only when module is used on page
     * adminEnqueue()    Enqueue scripts for the module edit/add page in admin
     * template()        Return the view template (blade) the module should use when displayed
     */
}
<commit_msg>Added fucntionality for custom columns in file (#97)<commit_after><?php

namespace Modularity\Module\FilesList;

class FilesList extends \Modularity\Module
{
    public $slug = 'fileslist';
    public $supports = array();

    public function init()
    {
        $this->nameSingular = __("Files", 'modularity');
        $this->namePlural = __("Files", 'modularity');
        $this->description = __("Outputs a file archive.", 'modularity');
    }

    public function data() : array
    {
        $data = array();
        // die(var_dump(get_field('columns', $this->ID)));
        $data['listId'] = 'files_' . uniqid();
        $data['columnData'] = $this->prepareColumnData($files);
        $data['headings'] = $this->prepareHeadings(['File', 'Description']);
        $data['showFilters'] = !empty(get_field('show_filter', $this->ID));
        $data['classes'] = implode(' ', apply_filters('Modularity/Module/Classes', array('box', 'box-panel'), $this->post_type, $this->args));

        return $data;
    }


    private function prepareHeadings($headings) {
        $extraColumns = get_field('columns', $this->ID);

        foreach($extraColumns as $col) {
            $headings[$col['key']] = $col['title'];
        }
                
        foreach($headings as &$heading) {
            
            $heading = translate($heading, 'modularity');
        }
        return $headings;
    }

    private function prepareColumnData()
    {
        $files = get_field('file_list', $this->ID);
        $columnData = [];

        foreach ($files as $key => $item) {
            $columnData['href'] = $item['file']['url'];

            $columnData[$key] = [
                'columns' => 
                [
                    'title' => $item['file']['title'],
                    'description' => $item['file']['description']
                ],
                'href' => $item['file']['url']
            ];

            $fields = $this->fieldsArray($item['fields']);

            foreach(get_field('columns', $this->ID) as $col) {
                $columnData[$key]['columns'][$col['key']] = $fields[$col['key']] ? $fields[$col['key']] : "";
            }
        }

        return $columnData;
    }

    private function fieldsArray($arr)
    {
        $newArr = [];
        foreach($arr as $item) {
            $newArr[$item['key']] = $item['value'];
        }

        return $newArr;
    }

    /**
     * Available "magic" methods for modules:
     * init()            What to do on initialization
     * data()            Use to send data to view (return array)
     * style()           Enqueue style only when module is used on page
     * script            Enqueue script only when module is used on page
     * adminEnqueue()    Enqueue scripts for the module edit/add page in admin
     * template()        Return the view template (blade) the module should use when displayed
     */
}

{'fraction_non_alphanumeric': 0.15647339158061954, 'fraction_numerical': 0.0003971405877680699, 'mean_word_length': 2.107341147439852, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, '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': '5438781', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1385, 'n_words': 336}