<commit_before><?php
declare(strict_types=1);

namespace Remp\Mailer\Forms;

use Nette\Application\UI\Form;
use Nette\Utils\ArrayHash;
use Remp\MailerModule\Repositories\BatchesRepository;
use Remp\MailerModule\Repositories\JobsRepository;
use Remp\MailerModule\Repositories\LayoutsRepository;
use Remp\MailerModule\Repositories\ListsRepository;
use Remp\MailerModule\Repositories\TemplatesRepository;
use Remp\MailerModule\Models\Segment\Crm;

class NovydenikNewsfilterTemplateFormFactory
{
    private $activeUsersSegment;

    private $inactiveUsersSegment;

    private $templatesRepository;

    private $layoutsRepository;

    private $jobsRepository;

    private $batchesRepository;

    private $listsRepository;

    public $onUpdate;

    public $onSave;

    public function __construct(
        $activeUsersSegment,
        $inactiveUsersSegment,
        TemplatesRepository $templatesRepository,
        LayoutsRepository $layoutsRepository,
        ListsRepository $listsRepository,
        JobsRepository $jobsRepository,
        BatchesRepository $batchesRepository
    ) {
        $this->activeUsersSegment = $activeUsersSegment;
        $this->inactiveUsersSegment = $inactiveUsersSegment;
        $this->templatesRepository = $templatesRepository;
        $this->layoutsRepository = $layoutsRepository;
        $this->listsRepository = $listsRepository;
        $this->jobsRepository = $jobsRepository;
        $this->batchesRepository = $batchesRepository;
    }

    public function create(): Form
    {
        $form = new Form;
        $form->addProtection();

        $form->addText('name', 'Name')
            ->setRequired("Field 'Name' is required.");

        $form->addText('code', 'Identifier')
            ->setRequired("Field 'Identifier' is required.");

        $form->addSelect('mail_layout_id', 'Template', $this->layoutsRepository->all()->fetchPairs('id', 'name'));

        $form->addSelect('locked_mail_layout_id', 'Template for non-subscribers', $this->layoutsRepository->all()->fetchPairs('id', 'name'));

        $mailTypes = $this->listsRepository->getTable()->where(['is_public' => true])->order('sorting ASC')->fetchPairs('id', 'code');

        $form->addSelect('mail_type_id', 'Type', $mailTypes)
            ->setRequired("Field 'Type' is required.");

        $form->addText('from', 'Sender')
            ->setHtmlAttribute('placeholder', 'e.g. <EMAIL>')
            ->setRequired("Field 'Sender' is required.");

        $form->addText('subject', 'Subject')
            ->setRequired("Field 'Subject' is required.");

        $form->addHidden('html_content');
        $form->addHidden('text_content');
        $form->addHidden('locked_html_content');
        $form->addHidden('locked_text_content');
        $form->addHidden('article_id');

        if (isset($_POST['source_template_id']) && $_POST['source_template_id'] == 21) {
            $defaults = [
                'name' => '<NAME> ' . date('j.n.Y'),
                'code' => 'nwsf_brnensky_orloj_' . date('dmY'),
                'mail_layout_id' => 2, // empty layout
                'locked_mail_layout_id' => 2, // empty layout
                'mail_type_id' => 15, // Brnensky orloj
                'from' => '<NAME> <<EMAIL>>',
            ];
        } elseif (isset($_POST['source_template_id']) && $_POST['source_template_id'] == 17) {
            $defaults = [
                'name' => 'PolitikoN ' . date('j.n.Y'),
                'code' => 'nwsf_politikon_' . date('dmY'),
                'mail_layout_id' => 2, // empty layout
                'locked_mail_layout_id' => 2, // empty layout
                'mail_type_id' => 14, // Politikon
                'from' => '<NAME> <<EMAIL>>',
            ];
        } elseif (isset($_POST['source_template_id']) && $_POST['source_template_id'] == 16) {
            $defaults = [
                'name' => '<NAME> ' . date('j.n.Y'),
                'code' => 'nwsf_amer_tydenik_' . date('dmY'),
                'mail_layout_id' => 2, // empty layout
                'locked_mail_layout_id' => 2, // empty layout
                'mail_type_id' => 13, // Americký týdeník
                'from' => '<NAME> <<EMAIL>>',<commit_msg>Added cinska depese newsletter default values for novy denik<commit_after><?php
declare(strict_types=1);

namespace Remp\Mailer\Forms;

use Nette\Application\UI\Form;
use Nette\Utils\ArrayHash;
use Remp\MailerModule\Repositories\BatchesRepository;
use Remp\MailerModule\Repositories\JobsRepository;
use Remp\MailerModule\Repositories\LayoutsRepository;
use Remp\MailerModule\Repositories\ListsRepository;
use Remp\MailerModule\Repositories\TemplatesRepository;
use Remp\MailerModule\Models\Segment\Crm;

class NovydenikNewsfilterTemplateFormFactory
{
    private $activeUsersSegment;

    private $inactiveUsersSegment;

    private $templatesRepository;

    private $layoutsRepository;

    private $jobsRepository;

    private $batchesRepository;

    private $listsRepository;

    public $onUpdate;

    public $onSave;

    public function __construct(
        $activeUsersSegment,
        $inactiveUsersSegment,
        TemplatesRepository $templatesRepository,
        LayoutsRepository $layoutsRepository,
        ListsRepository $listsRepository,
        JobsRepository $jobsRepository,
        BatchesRepository $batchesRepository
    ) {
        $this->activeUsersSegment = $activeUsersSegment;
        $this->inactiveUsersSegment = $inactiveUsersSegment;
        $this->templatesRepository = $templatesRepository;
        $this->layoutsRepository = $layoutsRepository;
        $this->listsRepository = $listsRepository;
        $this->jobsRepository = $jobsRepository;
        $this->batchesRepository = $batchesRepository;
    }

    public function create(): Form
    {
        $form = new Form;
        $form->addProtection();

        $form->addText('name', 'Name')
            ->setRequired("Field 'Name' is required.");

        $form->addText('code', 'Identifier')
            ->setRequired("Field 'Identifier' is required.");

        $form->addSelect('mail_layout_id', 'Template', $this->layoutsRepository->all()->fetchPairs('id', 'name'));

        $form->addSelect('locked_mail_layout_id', 'Template for non-subscribers', $this->layoutsRepository->all()->fetchPairs('id', 'name'));

        $mailTypes = $this->listsRepository->getTable()->where(['is_public' => true])->order('sorting ASC')->fetchPairs('id', 'code');

        $form->addSelect('mail_type_id', 'Type', $mailTypes)
            ->setRequired("Field 'Type' is required.");

        $form->addText('from', 'Sender')
            ->setHtmlAttribute('placeholder', 'e.g. <EMAIL>')
            ->setRequired("Field 'Sender' is required.");

        $form->addText('subject', 'Subject')
            ->setRequired("Field 'Subject' is required.");

        $form->addHidden('html_content');
        $form->addHidden('text_content');
        $form->addHidden('locked_html_content');
        $form->addHidden('locked_text_content');
        $form->addHidden('article_id');

        if (isset($_POST['source_template_id']) && $_POST['source_template_id'] == 23) {
            $defaults = [
                'name' => '<NAME> ' . date('j.n.Y'),
                'code' => 'nwsf_cinska_depese_' . date('dmY'),
                'mail_layout_id' => 2, // empty layout
                'locked_mail_layout_id' => 2, // empty layout
                'mail_type_id' => 17, // Čínská depeše
                'from' => '<NAME> <<EMAIL>>',
            ];
        } elseif (isset($_POST['source_template_id']) && $_POST['source_template_id'] == 21) {
            $defaults = [
                'name' => '<NAME> ' . date('j.n.Y'),
                'code' => 'nwsf_brnensky_orloj_' . date('dmY'),
                'mail_layout_id' => 2, // empty layout
                'locked_mail_layout_id' => 2, // empty layout
                'mail_type_id' => 15, // Brnensky orloj
                'from' => '<NAME> <<EMAIL>>',
            ];
        } elseif (isset($_POST['source_template_id']) && $_POST['source_template_id'] == 17) {
            $defaults = [
                'name' => 'PolitikoN ' . date('j.n.Y'),
                'code' => 'nwsf_politikon_' . date('dmY'),
                'mail_layout_id' => 2, // empty layout
                'locked_mail_layout_id' => 2, // empty layout
                'mail_type_id' => 14, // Politikon
                'from' => '<NAME> <<EMAIL>>',
            ];
        } elseif (isset($_POST['source_template_id']) && $_POST['source_template_id'] == 16) {
            $defaults = [
                'name' => 'Americký týdeník ' . date('j.n.Y'),
                'code' => 'nwsf_amer_tydenik_' . date('dmY'),
                'mail_layout_id' => 2, // empty layout
                'locked_mail_layout_id' => 2, // empty layout
                'mail_type_id' => 13, // Americký týdeník
                'from' => '<NAME> <<EMAIL>>',
{'fraction_non_alphanumeric': 0.15273257771293908, 'fraction_numerical': 0.0049377174278981036, 'mean_word_length': 2.624237494916633, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 148, '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': '1085286', 'n_tokens_mistral': 2719, 'n_tokens_neox': 2577, 'n_words': 450}