Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/mautic.corals.io/app/bundles/ChannelBundle/Model/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/mautic.corals.io/app/bundles/ChannelBundle/Model/FrequencyActionModel.php
<?php

namespace Mautic\ChannelBundle\Model;

use Mautic\LeadBundle\Entity\FrequencyRule;
use Mautic\LeadBundle\Entity\FrequencyRuleRepository;
use Mautic\LeadBundle\Entity\Lead;
use Mautic\LeadBundle\Model\LeadModel;

class FrequencyActionModel
{
    public function __construct(
        private LeadModel $contactModel,
        private FrequencyRuleRepository $frequencyRuleRepository
    ) {
    }

    /**
     * Update channels.
     *
     * @param string $preferredChannel
     */
    public function update(array $contactIds, array $params, $preferredChannel): void
    {
        $contacts = $this->contactModel->getLeadsByIds($contactIds);

        foreach ($contacts as $contact) {
            if (!$this->contactModel->canEditContact($contact)) {
                continue;
            }

            $this->updateFrequencyRules($contact, $params, $preferredChannel);
        }
    }

    /**
     * @param string $preferredChannel
     */
    private function updateFrequencyRules(Lead $contact, array $params, $preferredChannel): void
    {
        $frequencyRules = $contact->getFrequencyRules()->toArray();
        $channels       = $this->contactModel->getPreferenceChannels();

        foreach ($channels as $channel) {
            if (is_null($preferredChannel)) {
                $preferredChannel = $channel;
            }

            $frequencyRule = $frequencyRules[$channel] ?? new FrequencyRule();
            $frequencyRule->setChannel($channel);
            $frequencyRule->setLead($contact);

            if (!$frequencyRule->getDateAdded()) {
                $frequencyRule->setDateAdded(new \DateTime());
            }

            if (!empty($params['frequency_number_'.$channel]) && !empty($params['frequency_time_'.$channel])) {
                $frequencyRule->setFrequencyNumber($params['frequency_number_'.$channel]);
                $frequencyRule->setFrequencyTime($params['frequency_time_'.$channel]);
            } else {
                $frequencyRule->setFrequencyNumber(null);
                $frequencyRule->setFrequencyTime(null);
            }

            if (!empty($params['contact_pause_start_date_'.$channel])) {
                $frequencyRule->setPauseFromDate(new \DateTime($params['contact_pause_start_date_'.$channel]));
            }

            if (!empty($params['contact_pause_end_date_'.$channel])) {
                $frequencyRule->setPauseToDate(new \DateTime($params['contact_pause_end_date_'.$channel]));
            }

            $frequencyRule->setPreferredChannel($preferredChannel === $channel);

            $contact->addFrequencyRule($frequencyRule);

            $this->frequencyRuleRepository->saveEntity($frequencyRule);
        }
    }
}

Spamworldpro Mini