Add sellerWindow

@author Tom Haskins-Vaughan <tom@harvestcloud.com>
@since  2012-10-24

@param HarvestCloud\CoreBundle\Entity\SellerWindow $sellerWindow
353868
public function addSellerWindow(\HarvestCloud\CoreBundle\Entity\SellerWindow $sellerWindow)
    {
        $this->sellerWindows[] = $sellerWindow;

        $sellerWindow->setHubWindow($this);
    }
1237255
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $em = $this->getContainer()->get('doctrine')->getEntityManager();

        $sellerHubRefs = $this->getSellerHubRefs();

        foreach ($sellerHubRefs as $sellerHubRef)
        {
            foreach ($sellerHubRef->getWindowMakers() as $windowMaker)
            {
                $output->writeln('');
                $output->writeln('WindowMaker: # '.$windowMaker->getId());
                $output->writeln('Seller:        '
                  .$windowMaker->getSeller()->getName().' (#'
                  .$windowMaker->getSeller()->getId().')'
                );
                $output->writeln('Hub:           '
                  .$windowMaker->getHub()->getName().' (#'
                  .$windowMaker->getHub()->getId().')'
                );
                $output->writeln('Day of Week:   '.$windowMaker->getDayOfWeek()->getShortName());
                $output->writeln('Time:          '.$windowMaker->getStartTime().'-'.$windowMaker->getEndTime());

                $output->writeln('Windows:');

                foreach ($windowMaker->getDateAdjustedStartTimes(new \DateTime(), 10) as $start_time)
                {
                    $startTime = new \DateTime($start_time);

                    if ($sellerHubRef->hasWindowAtThisTime($start_time))
                    {
                        $output->writeln('  Exists:      '.$startTime->format('D').' '.$start_time);
                    }
                    else
                    {
                        $output->writeln('  Make:        '.$startTime->format('D').' '.$start_time);

                        $endTime  = clone $startTime;
                        $endTime->add(\DateInterval::createFromDateString('+2 hour'))->format('Y-m-d H:i:s');

                        // Create a new window
                        $window = new SellerHubPickupWindow();
                        $window->setStartTime($startTime);
                        $window->setEndTime($endTime);

                        $sellerHubRef->addSellerHubPickupWindow($window);
                    }
                }

                // First we need to check that the window has not already been
                // created, perhaps by another WindowMaker
                // @todo

            }

            $em->persist($sellerHubRef);
        }

        $em->flush();
    }
1359714
public function addDealerContact(ChildDealerContact $l)
    {
        if ($this->collDealerContacts === null) {
            $this->initDealerContacts();
            $this->collDealerContactsPartial = true;
        }

        if (!in_array($l, $this->collDealerContacts->getArrayCopy(), true)) { // only add it if the **same** object is not already associated
            $this->doAddDealerContact($l);
        }

        return $this;
    }
1184729
public function addDealerFolder(ChildDealerFolder $l)
    {
        if ($this->collDealerFolders === null) {
            $this->initDealerFolders();
            $this->collDealerFoldersPartial = true;
        }

        if (!in_array($l, $this->collDealerFolders->getArrayCopy(), true)) { // only add it if the **same** object is not already associated
            $this->doAddDealerFolder($l);
        }

        return $this;
    }
1233531
public function load(ObjectManager $manager)
    {
        $sellerHubRef = new SellerHubRef();
        $sellerHubRef->setSeller($this->getReference('jon-seller'));
        $sellerHubRef->setHub($this->getReference('sam-hub'));
        $sellerHubRef->setIsDefault(true);
        $sellerHubRef->setFixedFee(0.5);
        $sellerHubRef->setVariableFee(4);

        $windowMaker = new SellerWindowMaker();
        $windowMaker->setDeliveryType(HubWindow::DELIVERY_TYPE_PICKUP);
        $windowMaker->setDayOfWeekNumber(6);
        $windowMaker->setStartTime('09:00');
        $windowMaker->setEndTime('11:00');

        $sellerHubRef->addWindowMaker($windowMaker);

        $manager->persist($sellerHubRef);
        $manager->flush();


        $sellerHubRef = new SellerHubRef();
        $sellerHubRef->setSeller($this->getReference('jon-seller'));
        $sellerHubRef->setHub($this->getReference('nick-hub'));
        $sellerHubRef->setIsDefault(true);
        $sellerHubRef->setFixedFee(0.6);
        $sellerHubRef->setVariableFee(4);

        $windowMaker = new SellerWindowMaker();
        $windowMaker->setDeliveryType(HubWindow::DELIVERY_TYPE_PICKUP);
        $windowMaker->setDayOfWeekNumber(6);
        $windowMaker->setStartTime('09:00');
        $windowMaker->setEndTime('11:00');

        $sellerHubRef->addWindowMaker($windowMaker);

        $manager->persist($sellerHubRef);
        $manager->flush();


        $sellerHubRef = new SellerHubRef();
        $sellerHubRef->setSeller($this->getReference('jon-seller'));
        $sellerHubRef->setHub($this->getReference('ramon-hub'));
        $sellerHubRef->setIsDefault(true);
        $sellerHubRef->setFixedFee(0.55);
        $sellerHubRef->setVariableFee(4);

        $windowMaker = new SellerWindowMaker();
        $windowMaker->setDeliveryType(HubWindow::DELIVERY_TYPE_PICKUP);
        $windowMaker->setDayOfWeekNumber(6);
        $windowMaker->setStartTime('09:00');
        $windowMaker->setEndTime('11:00');

        $sellerHubRef->addWindowMaker($windowMaker);

        $manager->persist($sellerHubRef);
        $manager->flush();




        $sellerHubRef = new SellerHubRef();
        $sellerHubRef->setSeller($this->getReference('stephen-seller'));
        $sellerHubRef->setHub($this->getReference('sam-hub'));
        $sellerHubRef->setIsDefault(true);
        $sellerHubRef->setFixedFee(0.5);
        $sellerHubRef->setVariableFee(4);

        $windowMaker = new SellerWindowMaker();
        $windowMaker->setDeliveryType(HubWindow::DELIVERY_TYPE_PICKUP);
        $windowMaker->setDayOfWeekNumber(6);
        $windowMaker->setStartTime('09:00');
        $windowMaker->setEndTime('11:00');

        $sellerHubRef->addWindowMaker($windowMaker);

        $manager->persist($sellerHubRef);
        $manager->flush();


        $sellerHubRef = new SellerHubRef();
        $sellerHubRef->setSeller($this->getReference('stephen-seller'));
        $sellerHubRef->setHub($this->getReference('nick-hub'));
        $sellerHubRef->setIsDefault(true);
        $sellerHubRef->setFixedFee(0.6);
        $sellerHubRef->setVariableFee(4);

        $windowMaker = new SellerWindowMaker();
        $windowMaker->setDeliveryType(HubWindow::DELIVERY_TYPE_PICKUP);
        $windowMaker->setDayOfWeekNumber(6);
        $windowMaker->setStartTime('09:00');
        $windowMaker->setEndTime('11:00');

        $sellerHubRef->addWindowMaker($windowMaker);

        $manager->persist($sellerHubRef);
        $manager->flush();


        $sellerHubRef = new SellerHubRef();
        $sellerHubRef->setSeller($this->getReference('stephen-seller'));
        $sellerHubRef->setHub($this->getReference('ramon-hub'));
        $sellerHubRef->setIsDefault(true);
        $sellerHubRef->setFixedFee(0.55);
        $sellerHubRef->setVariableFee(4);

        $windowMaker = new SellerWindowMaker();
        $windowMaker->setDeliveryType(HubWindow::DELIVERY_TYPE_PICKUP);
        $windowMaker->setDayOfWeekNumber(6);
        $windowMaker->setStartTime('09:00');
        $windowMaker->setEndTime('11:00');

        $sellerHubRef->addWindowMaker($windowMaker);

        $manager->persist($sellerHubRef);
        $manager->flush();




        $sellerHubRef = new SellerHubRef();
        $sellerHubRef->setSeller($this->getReference('jo-seller'));
        $sellerHubRef->setHub($this->getReference('sam-hub'));
        $sellerHubRef->setIsDefault(true);
        $sellerHubRef->setFixedFee(0.5);
        $sellerHubRef->setVariableFee(4);

        $windowMaker = new SellerWindowMaker();
        $windowMaker->setDeliveryType(HubWindow::DELIVERY_TYPE_PICKUP);
        $windowMaker->setDayOfWeekNumber(6);
        $windowMaker->setStartTime('09:00');
        $windowMaker->setEndTime('11:00');

        $sellerHubRef->addWindowMaker($windowMaker);

        $manager->persist($sellerHubRef);
        $manager->flush();


        $sellerHubRef = new SellerHubRef();
        $sellerHubRef->setSeller($this->getReference('jo-seller'));
        $sellerHubRef->setHub($this->getReference('nick-hub'));
        $sellerHubRef->setIsDefault(true);
        $sellerHubRef->setFixedFee(0.6);
        $sellerHubRef->setVariableFee(4);

        $windowMaker = new SellerWindowMaker();
        $windowMaker->setDeliveryType(HubWindow::DELIVERY_TYPE_PICKUP);
        $windowMaker->setDayOfWeekNumber(6);
        $windowMaker->setStartTime('09:00');
        $windowMaker->setEndTime('11:00');

        $sellerHubRef->addWindowMaker($windowMaker);

        $manager->persist($sellerHubRef);
        $manager->flush();


        $sellerHubRef = new SellerHubRef();
        $sellerHubRef->setSeller($this->getReference('jo-seller'));
        $sellerHubRef->setHub($this->getReference('ramon-hub'));
        $sellerHubRef->setIsDefault(true);
        $sellerHubRef->setFixedFee(0.55);
        $sellerHubRef->setVariableFee(4);

        $windowMaker = new SellerWindowMaker();
        $windowMaker->setDeliveryType(HubWindow::DELIVERY_TYPE_PICKUP);
        $windowMaker->setDayOfWeekNumber(6);
        $windowMaker->setStartTime('09:00');
        $windowMaker->setEndTime('11:00');

        $sellerHubRef->addWindowMaker($windowMaker);

        $manager->persist($sellerHubRef);
        $manager->flush();




        $sellerHubRef = new SellerHubRef();
        $sellerHubRef->setSeller($this->getReference('sterling-seller'));
        $sellerHubRef->setHub($this->getReference('sam-hub'));
        $sellerHubRef->setIsDefault(true);
        $sellerHubRef->setFixedFee(0.5);
        $sellerHubRef->setVariableFee(4);

        $windowMaker = new SellerWindowMaker();
        $windowMaker->setDeliveryType(HubWindow::DELIVERY_TYPE_PICKUP);
        $windowMaker->setDayOfWeekNumber(6);
        $windowMaker->setStartTime('09:00');
        $windowMaker->setEndTime('11:00');

        $sellerHubRef->addWindowMaker($windowMaker);

        $manager->persist($sellerHubRef);
        $manager->flush();


        $sellerHubRef = new SellerHubRef();
        $sellerHubRef->setSeller($this->getReference('sterling-seller'));
        $sellerHubRef->setHub($this->getReference('nick-hub'));
        $sellerHubRef->setIsDefault(true);
        $sellerHubRef->setFixedFee(0.6);
        $sellerHubRef->setVariableFee(4);

        $windowMaker = new SellerWindowMaker();
        $windowMaker->setDeliveryType(HubWindow::DELIVERY_TYPE_PICKUP);
        $windowMaker->setDayOfWeekNumber(6);
        $windowMaker->setStartTime('09:00');
        $windowMaker->setEndTime('11:00');

        $sellerHubRef->addWindowMaker($windowMaker);

        $manager->persist($sellerHubRef);
        $manager->flush();


        $sellerHubRef = new SellerHubRef();
        $sellerHubRef->setSeller($this->getReference('sterling-seller'));
        $sellerHubRef->setHub($this->getReference('nick-hub'));
        $sellerHubRef->setIsDefault(true);
        $sellerHubRef->setFixedFee(0.6);
        $sellerHubRef->setVariableFee(4);

        $windowMaker = new SellerWindowMaker();
        $windowMaker->setDeliveryType(HubWindow::DELIVERY_TYPE_PICKUP);
        $windowMaker->setDayOfWeekNumber(6);
        $windowMaker->setStartTime('11:00');
        $windowMaker->setEndTime('13:00');

        $sellerHubRef->addWindowMaker($windowMaker);

        $manager->persist($sellerHubRef);
        $manager->flush();


        $sellerHubRef = new SellerHubRef();
        $sellerHubRef->setSeller($this->getReference('sterling-seller'));
        $sellerHubRef->setHub($this->getReference('ramon-hub'));
        $sellerHubRef->setIsDefault(true);
        $sellerHubRef->setFixedFee(0.55);
        $sellerHubRef->setVariableFee(4);

        $windowMaker = new SellerWindowMaker();
        $windowMaker->setDeliveryType(HubWindow::DELIVERY_TYPE_PICKUP);
        $windowMaker->setDayOfWeekNumber(6);
        $windowMaker->setStartTime('09:00');
        $windowMaker->setEndTime('11:00');

        $sellerHubRef->addWindowMaker($windowMaker);

        $manager->persist($sellerHubRef);
        $manager->flush();




        $sellerHubRef = new SellerHubRef();
        $sellerHubRef->setSeller($this->getReference('tom-seller'));
        $sellerHubRef->setHub($this->getReference('sam-hub'));
        $sellerHubRef->setIsDefault(true);
        $sellerHubRef->setFixedFee(0.5);
        $sellerHubRef->setVariableFee(4);

        $windowMaker = new SellerWindowMaker();
        $windowMaker->setDeliveryType(HubWindow::DELIVERY_TYPE_PICKUP);
        $windowMaker->setDayOfWeekNumber(6);
        $windowMaker->setStartTime('09:00');
        $windowMaker->setEndTime('11:00');

        $sellerHubRef->addWindowMaker($windowMaker);

        $manager->persist($sellerHubRef);
        $manager->flush();


        $sellerHubRef = new SellerHubRef();
        $sellerHubRef->setSeller($this->getReference('tom-seller'));
        $sellerHubRef->setHub($this->getReference('nick-hub'));
        $sellerHubRef->setIsDefault(true);
        $sellerHubRef->setFixedFee(0.6);
        $sellerHubRef->setVariableFee(4);

        $windowMaker = new SellerWindowMaker();
        $windowMaker->setDeliveryType(HubWindow::DELIVERY_TYPE_PICKUP);
        $windowMaker->setDayOfWeekNumber(6);
        $windowMaker->setStartTime('09:00');
        $windowMaker->setEndTime('11:00');

        $sellerHubRef->addWindowMaker($windowMaker);

        $manager->persist($sellerHubRef);
        $manager->flush();


        $sellerHubRef = new SellerHubRef();
        $sellerHubRef->setSeller($this->getReference('tom-seller'));
        $sellerHubRef->setHub($this->getReference('ramon-hub'));
        $sellerHubRef->setIsDefault(true);
        $sellerHubRef->setFixedFee(0.55);
        $sellerHubRef->setVariableFee(4);

        $windowMaker = new SellerWindowMaker();
        $windowMaker->setDeliveryType(HubWindow::DELIVERY_TYPE_PICKUP);
        $windowMaker->setDayOfWeekNumber(6);
        $windowMaker->setStartTime('09:00');
        $windowMaker->setEndTime('11:00');

        $sellerHubRef->addWindowMaker($windowMaker);

        $manager->persist($sellerHubRef);
        $manager->flush();
    }
1279165
public function addProductSubscriptionsAsBuyer(\HarvestCloud\CoreBundle\Entity\ProductSubscription $productSubscription)
    {
        $this->productSubscriptionsAsBuyer[] = $productSubscription;

        return $this;
    }
1069825
public function setProduct(ChildProduct $v = null)
    {
        if ($v === null) {
            $this->setProductId(NULL);
        } else {
            $this->setProductId($v->getId());
        }

        $this->aProduct = $v;

        // Add binding for other direction of this n:n relationship.
        // If this object has already been added to the ChildProduct object, it will not be re-added.
        if ($v !== null) {
            $v->addDealerProduct($this);
        }


        return $this;
    }
755130
public function addDealerShedules(ChildDealerShedules $l)
    {
        if ($this->collDealerSheduless === null) {
            $this->initDealerSheduless();
            $this->collDealerShedulessPartial = true;
        }

        if (!in_array($l, $this->collDealerSheduless->getArrayCopy(), true)) { // only add it if the **same** object is not already associated
            $this->doAddDealerShedules($l);
        }

        return $this;
    }
143270
public function setSellerWindow(\HarvestCloud\CoreBundle\Entity\SellerWindow $sellerWindow)
    {
        $this->sellerWindow = $sellerWindow;

        if (!$this->getOrder()->getSellerWindow()) {
            $this->getOrder()->setSellerWindow($sellerWindow);
        }
    }
398532
public function makeAction(SellerWindowMaker $windowMaker)
    {
        $windows = $windowMaker->makeWindows();

        $em = $this->getDoctrine()->getEntityManager();
        $em->persist($windowMaker);
        $em->flush();

        return $this->redirect($this->generateUrl('Seller_window_maker_show', array(
            'id' => $windowMaker->getId(),
        )));
    }
1100919
public function showAction(Profile $seller, $product_slug)
    {
        $q  = $this->get('doctrine')
            ->getManager()
            ->createQuery('
                SELECT p
                FROM HarvestCloudCoreBundle:Product p
                WHERE p.seller = :seller
                AND p.slug = :product_slug
            ')
            ->setParameter('product_slug', $product_slug)
            ->setParameter('seller', $seller)
        ;

        $product = $q->getSingleResult();

        $form = $this->createForm(new AddToCartType(
            $product,
            $this->getCurrentCart()->getQuantity($product)
        ));

        return $this->render('HarvestCloudCoreBundle:Buyer/Product:show.html.twig', array(
          'product'          => $product,
          'quantity_in_cart' => $this->getCurrentCart()->getQuantity($product),
          'lineItem'         => $this->getCurrentCart()->getLineItemForProduct($product),
          'form'             => $form->createView(),
        ));
    }
302508
public function newAction(Request $request)
    {
        $windowMaker = new SellerWindowMaker();
        $form = $this->createForm(new SellerWindowMakerType($this->getCurrentProfile()), $windowMaker);

        if ($response = $this->processForm($request, $form, 'Seller_window_maker_show'))
        {
            return $response;
        }

        return $this->render('HarvestCloudCoreBundle:Seller/WindowMaker:new.html.twig', array(
          'form' => $form->createView(),
        ));
    }
1190404
public function setWindow($var)
    {
        GPBUtil::checkMessage($var, \Google\Cloud\Asset\V1\TimeWindow::class);
        $this->window = $var;

        return $this;
    }
680347
public function setSellerWindow(\HarvestCloud\CoreBundle\Entity\SellerWindow $sellerWindow)
    {
        $this->sellerWindow = $sellerWindow;
        $this->setHub($sellerWindow->getSellerHubRef()->getHub());

        // add fees
        $this->setFixedHubFee($sellerWindow->getSellerHubRef()->getFixedFee());
        $this->setVariableHubFee($sellerWindow->getSellerHubRef()->getVariableFee());

        // calculate the actual fee
        $this->setHubFee($sellerWindow->getTotalHubFeeForOrder($this));

        // Now recaculate the total
        $this->recalculateTotal();
    }
857572
public function setHubWindow(HubWindow $hubWindow)
    {
        // Apply the appropriate SellerWindow for each Order
        foreach ($hubWindow->getSellerWindows() as $sellerWindow)
        {
            foreach ($this->getOrders() as $order)
            {
                if ($sellerWindow->getSeller()->getId() == $order->getSeller()->getId())
                {
                    $order->setSellerWindow($sellerWindow);

                    break;
                }
            }
        }

        // Now make sure every Order has a SellerWindow
        foreach ($this->getOrders() as $order)
        {
            if (!$order->getSellerWindow()->getId())
            {
                throw new \Exception('Order #'.$order->getId().' has no SellerWindow');
            }
        }
    }
710098
public function addWindowMaker(\HarvestCloud\CoreBundle\Entity\SellerWindowMaker $windowMaker)
    {
        $this->windowMakers[] = $windowMaker;

        $windowMaker->setSellerHubRef($this);
    }
725510
public function setDealerBrand(ChildDealerBrand $v = null)
    {
        if ($v === null) {
            $this->setId(NULL);
        } else {
            $this->setId($v->getId());
        }

        $this->aDealerBrand = $v;

        // Add binding for other direction of this n:n relationship.
        // If this object has already been added to the ChildDealerBrand object, it will not be re-added.
        if ($v !== null) {
            $v->addDealerBrandVersion($this);
        }


        return $this;
    }