resq/src/Command/SetCustomerPrivacyPolicyCommand.php

84 lines
2.6 KiB
PHP

<?php
namespace App\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Common\Persistence\ObjectManager;
use App\Entity\Customer;
use App\Entity\PrivacyPolicy;
use App\Entity\MobileSession;
class SetCustomerPrivacyPolicyCommand extends Command
{
private $em;
private $policy_promo_id;
private $policy_third_party_id;
private $policy_mobile_id;
public function __construct(ObjectManager $om, $policy_promo,
$policy_third_party, $policy_mobile)
{
$this->em = $om;
$this->policy_promo_id = $policy_promo;
$this->policy_third_party_id = $policy_third_party;
$this->policy_mobile_id = $policy_mobile;
parent::__construct();
}
protected function configure()
{
$this->setName('customer:setprivacypolicy')
->setDescription('Set customer private policy.')
->setHelp('Set customer private policy.');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
// get third party policy
$third_party_policy = $this->em->getRepository(PrivacyPolicy::class)->find($this->policy_third_party_id);
// get customers on third party
$third_party_customers = $this->em->getRepository(Customer::class)->findBy(['priv_third_party' => true]);
foreach ($third_party_customers as $cust)
{
$cust->setPrivacyPolicyThirdParty($third_party_policy);
}
// get promo policy
$promo_policy = $this->em->getRepository(PrivacyPolicy::class)->find($this->policy_promo_id);
// get customers on promo
$promo_customers = $this->em->getRepository(Customer::class)->findBy(['priv_promo' => true]);
foreach ($promo_customers as $cust)
{
$cust->setPrivacyPolicyPromo($promo_policy);
}
$this->em->flush();
// get mobile policy
$mobile_policy = $this->em->getRepository(PrivacyPolicy::class)->find($this->policy_mobile_id);
// get mobile sessions
$mobile_sessions = $this->em->getRepository(MobileSession::class)->findAll();
foreach ($mobile_sessions as $session)
{
$cust = $session->getCustomer();
if (!(is_null($cust)))
{
$cust->setPrivacyPolicyMobile($mobile_policy);
}
}
$this->em->flush();
}
}