<commit_before><?php

namespace Modules\Content\Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Modules\Content\Models\Channel;
use Modules\Content\Models\Entry;
use Modules\Content\Models\HtmlBlock;
use Modules\Content\Models\Section;
use Netcore\Translator\Models\Language;
use Netcore\Translator\Helpers\TransHelper;

class ExampleDataTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {

        DB::table('netcore_content__entries')->delete();
        DB::table('netcore_content__channels')->delete();
        DB::table('netcore_content__sections')->delete();

        $sections = [
            'Blogs' => [
                [
                    'type'      => 'channel',
                    'name'      => 'News',
                    'is_active' => 1,
                    'entries'   => [
                        [
                            'name'      => 'First news entry',
                            'is_active' => 1,
                        ],
                        [
                            'name'      => 'Second news entry',
                            'is_active' => 1,
                        ],
                        [
                            'name'      => 'Third news entry',
                            'is_active' => 1,
                        ]
                    ]
                ],
                [
                    'type'      => 'channel',
                    'name'      => 'Reports',
                    'is_active' => 1,
                    'entries'   => [
                        [
                            'name'      => 'First report',
                            'is_active' => 1,
                        ],
                        [
                            'name'      => 'Second report',
                            'is_active' => 1,
                        ],
                        [
                            'name'      => 'Third report',
                            'is_active' => 1,
                        ]
                    ]
                ],
                [
                    'type'      => 'channel',
                    'name'      => 'Blog',
                    'is_active' => 1,
                    'entries'   => [
                        [
                            'name'      => 'First blogpost',
                            'is_active' => 1,
                        ],
                        [
                            'name'      => 'Second blogpost',
                            'is_active' => 1,
                        ],
                        [
                            'name'      => 'Third blogpost',
                            'is_active' => 1,
                        ]
                    ]
                ],
            ],


            'Static pages' => [
                [
                    'type'      => 'entry',
                    'name'      => 'Homepage',
                    'is_active' => 1,
                ],
                [
                    'type'      => 'entry',
                    'name'      => 'About us',
                    'is_active' => 1,
                ],
                [
                    'type'      => 'entry',
                    'name'      => 'Contacts',
                    'is_active' => 1,
                ],
            ]
        ];

        $sectionOrder = 1;

        foreach ($sections as $sectionName => $sectionData) {

            $section = Section::updateOrCreate([
                'name' => $sectionName
            ], [
                'order' => $sectionOrder
            ]);

            $sectionOrder++;

            foreach ($sectionData as $item) {

                $itemType = array_get($item, 'type');

                if ($itemType == 'channel') {
                    $this->createChannel($item, $section);
                }

                if ($itemType == 'entry') {
                    $this->createEntry($item, $section);
                }
            }
        }
    }

    /**
     * @param $item
     * @param $section
     * @return mixed
     */
    private function createChannel($item, $section)
    {

        $itemName = array_get($item, 'name');

        // Basic data
        $channelData = array_except($item, ['type', 'translations', 'entries']);
        $channelData['section_id'] = $section->id;

        $channel = Channel::updateOrCreate([
            'name' => $itemName
        ], $channelData);


        // Translations
        $channelTranslations = $this->translateKeyValuePairsToAllLocales([
            'slug' => $itemName
        ]);

        $channel->updateTranslations($channelTranslations);


        // Entries
        $entries = array_get($item, 'entries', []);
        foreach ($entries as $item) {
            $item['channel_id'] = $channel->id;
            $this->createEntry($item, $section);
        }

        return $channel;
    }

    /**
     * @param $item
     * @param $section
     * @return mixed
     */
    private function createEntry($item, $section)
    {
        $itemName = array_get($item, 'name');

        $entryData = array_except($item, ['type', 'name', 'translations']);
        $entryData['section_id'] = $section->id;

        $entry = Entry::forceCreate($entryData);

        $entryTranslations = $this->translateKeyValuePairsToAllLocales([
            'slug'    => $itemName,
            'title'   => $itemName,
            'content' => 'Example ' . strtolower($itemName)
        ]);

        $entry->updateTranslations($entryTranslations);

        $htmlBlock = HtmlBlock::create([]);
        $htmlBlock->storeTranslations($this->translateKeyValuePairsToAllLocales([
            'content' => 'Example ' . strtolower($itemName)
        ]));

        $entry->contentBlocks()->create([
            'order'  => 1,
            'widget' => 'simple_text',
            'data'   => [
                'html_block_id' => $htmlBlock->id
            ]
        ]);

        return $entry;
    }
<commit_msg>Work in progress<commit_after><?php

namespace Modules\Content\Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Modules\Content\Models\Channel;
use Modules\Content\Models\Entry;
use Modules\Content\Models\HtmlBlock;
use Modules\Content\Models\Section;
use Netcore\Translator\Models\Language;
use Netcore\Translator\Helpers\TransHelper;

class ExampleDataTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {

        DB::table('netcore_content__entries')->delete();
        DB::table('netcore_content__channels')->delete();
        DB::table('netcore_content__sections')->delete();

        $sections = [
            'Blogs' => [
                [
                    'type'      => 'channel',
                    'name'      => 'News',
                    'is_active' => 1,
                    'entries'   => [
                        [
                            'name'      => 'First news entry',
                            'is_active' => 1,
                        ],
                        [
                            'name'      => 'Second news entry',
                            'is_active' => 1,
                        ],
                        [
                            'name'      => 'Third news entry',
                            'is_active' => 1,
                        ]
                    ]
                ],
                [
                    'type'      => 'channel',
                    'name'      => 'Reports',
                    'is_active' => 1,
                    'entries'   => [
                        [
                            'name'      => 'First report',
                            'is_active' => 1,
                        ],
                        [
                            'name'      => 'Second report',
                            'is_active' => 1,
                        ],
                        [
                            'name'      => 'Third report',
                            'is_active' => 1,
                        ]
                    ]
                ],
                [
                    'type'      => 'channel',
                    'name'      => 'Blog',
                    'is_active' => 1,
                    'entries'   => [
                        [
                            'name'      => 'First blogpost',
                            'is_active' => 1,
                        ],
                        [
                            'name'      => 'Second blogpost',
                            'is_active' => 1,
                        ],
                        [
                            'name'      => 'Third blogpost',
                            'is_active' => 1,
                        ]
                    ]
                ],
            ],


            'Static pages' => [
                [
                    'type'      => 'entry',
                    'name'      => 'Homepage',
                    'is_active' => 1,
                ],
                [
                    'type'      => 'entry',
                    'name'      => 'About us',
                    'is_active' => 1,
                ],
                [
                    'type'      => 'entry',
                    'name'      => 'Contacts',
                    'is_active' => 1,
                ],
            ]
        ];

        $sectionOrder = 1;

        foreach ($sections as $sectionName => $sectionData) {

            $section = Section::updateOrCreate([
                'name' => $sectionName
            ], [
                'order' => $sectionOrder
            ]);

            $sectionOrder++;

            foreach ($sectionData as $item) {

                $itemType = array_get($item, 'type');

                if ($itemType == 'channel') {
                    $this->createChannel($item, $section);
                }

                if ($itemType == 'entry') {
                    $this->createEntry($item, $section);
                }
            }
        }
    }

    /**
     * @param $item
     * @param $section
     * @return mixed
     */
    private function createChannel($item, $section)
    {

        $itemName = array_get($item, 'name');

        // Basic data
        $channelData = array_except($item, ['type', 'translations', 'entries']);
        $channelData['section_id'] = $section->id;

        $channel = Channel::updateOrCreate([
            'name' => $itemName
        ], $channelData);


        // Translations
        $channelTranslations = $this->translateKeyValuePairsToAllLocales([
            'slug' => $itemName
        ]);

        $channel->updateTranslations($channelTranslations);


        // Entries
        $entries = array_get($item, 'entries', []);
        foreach ($entries as $item) {
            $item['channel_id'] = $channel->id;
            $this->createEntry($item, $section);
        }

        return $channel;
    }

    /**
     * @param $item
     * @param $section
     * @return mixed
     */
    private function createEntry($item, $section)
    {
        $itemName = array_get($item, 'name');

        $entryData = array_except($item, ['type', 'name', 'translations']);
        $entryData['section_id'] = $section->id;

        $entry = Entry::forceCreate($entryData);

        $exampleContent = 'We have been operating since 2009, and we already employ more than 250 professionals whose job it is to ensure everyone easily accessible and understandable daily financial services. At present, we have introduced and continue to develop advanced process management and automation systems, allowing us to significantly accelerate the examination of applications for customers and a reduction in lending-related financial risks, while providing fast, reliable and accurate lending services to our customers. In order to successfully serve all customers according to their needs and ensure high customer service standards, we manage the largest branch network in Latvia, which also offer Lombard and Western Union money transfer services.';

        $entryTranslations = $this->translateKeyValuePairsToAllLocales([
            'slug'    => $itemName,
            'title'   => $itemName,
            'content' => $exampleContent
        ]);

        $entry->updateTranslations($entryTranslations);

        $htmlBlock = HtmlBlock::create([]);
        $htmlBlock->storeTranslations($this->translateKeyValuePairsToAllLocales([
            'content' => $exampleContent
        ]));

        $entry->contentBlocks()->create([
            'order'  => 1,
            'widget' => 'simple_text',
            'data'   => [
                'html_block_id' => $htmlBlock->id
            ]
        ]);

        return $entry;
    }

{'fraction_non_alphanumeric': 0.12310781587890021, 'fraction_numerical': 0.003166512202656781, 'mean_word_length': 1.0695221352085664, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 147, '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': '1448542', 'n_tokens_mistral': 3328, 'n_tokens_neox': 3099, 'n_words': 618}