<commit_before><?php

namespace PiggyBox\OrderBundle\EventListener;

use PiggyBox\OrderBundle\Entity\Order;
use Symfony\Component\DependencyInjection\ContainerInterface;
use PiggyBox\OrderBundle\Event\OrderEvent;

class OrderEmailler
{
    private $container;

    /**
     * Inject the whole container because otherwise we would have a circular dependency
     * DBAL -> ORM -> EventManager -> ACL Provider
     * @link https://groups.google.com/d/topic/symfony2/MreLJgfnn_U/discussion
     */
    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    public function onOrderValidation(OrderEvent $event)
    {
        $entity = $event->getOrder();

        if ($entity instanceof Order) {
            if (!in_array($this->container->get('kernel')->getEnvironment(), array('dev', 'test'))) {
                $message = \Swift_Message::newInstance()
                    ->setSubject('Validation de commande - Côtelettes & Tarte aux Fraises')
                    ->setFrom('<EMAIL>')
                    ->setTo($entity->getUser()->getEmail());
                $message->addBcc('<EMAIL>');

                $header = $message->embed(\Swift_Image::fromPath('../web/bundles/piggyboxorder/img/email-banner-commande-validee.jpg'));
                $tick = $message->embed(\Swift_Image::fromPath('../web/bundles/piggyboxorder/img/tick.png'));
                $mapmarker = $message->embed(\Swift_Image::fromPath('../web/bundles/piggyboxorder/img/mapmarker.png'));
                $highlightmarker = $message->embed(\Swift_Image::fromPath('../web/bundles/piggyboxorder/img/highlightmarker.png'));
                $footer = $message->embed(\Swift_Image::fromPath('../web/bundles/piggyboxorder/img/email-footer.jpg'));

                $message->setBody($this->container->get('templating')->render(
                        'PiggyBoxOrderBundle:Order:email.html.twig',
                        array('order' => $entity,
                              'header' => $header,
                              'tick' => $tick,
                              'mapmarker' => $mapmarker,
                              'highlightmarker' => $highlightmarker,
                              'footer' => $footer,
                            )), 'text/html')
                ;

                $this->container->get('mailer')->send($message);
            }
        }
    }

    public function onOrderPassed(OrderEvent $event)
    {
        $entity = $event->getOrder();

        if ($entity instanceof Order) {
            if (!in_array($this->container->get('kernel')->getEnvironment(), array('dev', 'test'))) {
                $em = $this->container->get('doctrine.orm.default_entity_manager');
                $user = $em->getRepository('PiggyBoxUserBundle:User')->findOneByOwnshop($entity->getShop());

                $message = \Swift_Message::newInstance()
                    ->setSubject('Commande Passée - Côtelettes & Tarte aux Fraises')
                    ->setFrom('<EMAIL>')
                    ->setTo('<EMAIL>');

                if ($user->getSlug() == 'boucherie-zola') {
                    $message->addBcc( $user->getSlug() );
                }

                $email_body = 'Une commande vient d\'être passé au magasin:'.$entity->getShop()->getName().'.';
                $email_body .= 'Par l\'utilisateur '.$entity->getUser()->getFirstName().' '.$entity->getUser()->getLastName().'<'.$entity->getUser()->getEmail().'>';
                $email_body .= 'Telephone: '.$entity->getUser()->getPhone();

                $message->setBody($email_body, 'text/html');

                $this->container->get('mailer')->send($message);
            }
        }
    }
}<commit_msg>corrected email bug<commit_after><?php

namespace PiggyBox\OrderBundle\EventListener;

use PiggyBox\OrderBundle\Entity\Order;
use Symfony\Component\DependencyInjection\ContainerInterface;
use PiggyBox\OrderBundle\Event\OrderEvent;

class OrderEmailler
{
    private $container;

    /**
     * Inject the whole container because otherwise we would have a circular dependency
     * DBAL -> ORM -> EventManager -> ACL Provider
     * @link https://groups.google.com/d/topic/symfony2/MreLJgfnn_U/discussion
     */
    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    public function onOrderValidation(OrderEvent $event)
    {
        $entity = $event->getOrder();

        if ($entity instanceof Order) {
            if (!in_array($this->container->get('kernel')->getEnvironment(), array('dev', 'test'))) {
                $message = \Swift_Message::newInstance()
                    ->setSubject('Validation de commande - Côtelettes & Tarte aux Fraises')
                    ->setFrom('<EMAIL>')
                    ->setTo($entity->getUser()->getEmail());
                $message->addBcc('<EMAIL>');

                $header = $message->embed(\Swift_Image::fromPath('../web/bundles/piggyboxorder/img/email-banner-commande-validee.jpg'));
                $tick = $message->embed(\Swift_Image::fromPath('../web/bundles/piggyboxorder/img/tick.png'));
                $mapmarker = $message->embed(\Swift_Image::fromPath('../web/bundles/piggyboxorder/img/mapmarker.png'));
                $highlightmarker = $message->embed(\Swift_Image::fromPath('../web/bundles/piggyboxorder/img/highlightmarker.png'));
                $footer = $message->embed(\Swift_Image::fromPath('../web/bundles/piggyboxorder/img/email-footer.jpg'));

                $message->setBody($this->container->get('templating')->render(
                        'PiggyBoxOrderBundle:Order:email.html.twig',
                        array('order' => $entity,
                              'header' => $header,
                              'tick' => $tick,
                              'mapmarker' => $mapmarker,
                              'highlightmarker' => $highlightmarker,
                              'footer' => $footer,
                            )), 'text/html')
                ;

                $this->container->get('mailer')->send($message);
            }
        }
    }

    public function onOrderPassed(OrderEvent $event)
    {
        $entity = $event->getOrder();

        if ($entity instanceof Order) {
            //if (!in_array($this->container->get('kernel')->getEnvironment(), array('dev', 'test'))) {
                $em = $this->container->get('doctrine.orm.default_entity_manager');
                $user = $em->getRepository('PiggyBoxUserBundle:User')->findOneByOwnshop($entity->getShop());

                $message = \Swift_Message::newInstance()
                    ->setSubject('Commande Passée - Côtelettes & Tarte aux Fraises')
                    ->setFrom('<EMAIL>')
                    ->setTo('<EMAIL>');

                if ($entity->getShop()->getSlug() == 'boucherie-zola') {
                    $message->addBcc( $user->getEmail() );
                }

                $email_body = 'Une commande vient d\'être passé au magasin:'.$entity->getShop()->getName().'.';
                //$email_body .= 'Par l\'utilisateur '.$entity->getUser()->getFirstName().' '.$entity->getUser()->getLastName().'<'.$entity->getUser()->getEmail().'>';
                //$email_body .= 'Telephone: '.$entity->getUser()->getPhone();

                $message->setBody($email_body, 'text/html');

                $this->container->get('mailer')->send($message);
            //}
        }
    }
}
{'fraction_non_alphanumeric': 0.16368012837657128, 'fraction_numerical': 0.0002674511901577962, 'mean_word_length': 2.0576451349141456, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 136, 'https://': 2, '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': '4666700', 'n_tokens_mistral': 2141, 'n_tokens_neox': 2029, 'n_words': 286}