Exemplo n.º 1
0
 public function indexAction()
 {
     $breadcrumbService = new Service\BreadcrumbService();
     $breadcrumbService->reset();
     $breadcrumbService->set('participant', 'product');
     $form = new Form\Participant();
     $form->setServiceLocator($this->getServiceLocator());
     $optionService = $this->getServiceLocator()->get('ErsBase\\Service\\OptionService');
     $form->get('Country_id')->setValueOptions($optionService->getCountryOptions());
     $form->get('submit')->setAttribute('class', 'btn btn-lg btn-primary');
     $form->get('submit')->setValue('Register now!');
     return new ViewModel(array('ers_config' => $this->getServiceLocator()->get('Config')['ERS'], 'form' => $form));
 }
Exemplo n.º 2
0
 public function getServiceConfig()
 {
     return array('factories' => array('Zend\\Session\\SessionManager' => function ($sm) {
         $config = $sm->get('config');
         if (isset($config['session'])) {
             $session = $config['session'];
             $sessionConfig = null;
             if (isset($session['config'])) {
                 $class = isset($session['config']['class']) ? $session['config']['class'] : 'Zend\\Session\\Config\\SessionConfig';
                 $options = isset($session['config']['options']) ? $session['config']['options'] : array();
                 $sessionConfig = new $class();
                 $sessionConfig->setOptions($options);
             }
             $sessionStorage = null;
             if (isset($session['storage'])) {
                 $class = $session['storage'];
                 $sessionStorage = new $class();
             }
             $sessionSaveHandler = null;
             if (isset($session['save_handler'])) {
                 // class should be fetched from service manager since it will require constructor arguments
                 $sessionSaveHandler = $sm->get($session['save_handler']);
             }
             $sessionManager = new SessionManager($sessionConfig, $sessionStorage, $sessionSaveHandler);
             if (isset($session['validators'])) {
                 $chain = $sessionManager->getValidatorChain();
                 foreach ($session['validators'] as $validator) {
                     $validator = new $validator();
                     $chain->attach('session.validate', array($validator, 'isValid'));
                 }
             }
         } else {
             $sessionManager = new SessionManager();
         }
         Container::setDefaultManager($sessionManager);
         return $sessionManager;
     }, 'PreReg\\Form\\ProductView' => function ($sm) {
         $productView = new Form\ProductView();
         $productView->setServiceLocator($sm);
         return $productView;
     }, 'PreReg\\Form\\CreditCard' => function ($sm) {
         $form = new Form\CreditCard();
         $years = array();
         for ($i = date('Y'); $i <= date('Y') + 15; $i++) {
             $years[] = array('value' => $i, 'label' => $i);
         }
         $form->get('cc_expdate_year')->setAttribute('options', $years);
         $months = array();
         for ($i = 1; $i <= 12; $i++) {
             $months[] = array('value' => $i, 'label' => sprintf('%02d', $i));
         }
         $form->get('cc_expdate_month')->setAttribute('options', $months);
         return $form;
     }, 'PreReg\\Service\\LoginService' => function ($sm) {
         $loginService = new Service\LoginService();
         $loginService->setServiceLocator($sm);
         return $loginService;
     }, 'PreReg\\InputFilter\\Register' => function ($sm) {
         $inputFilter = new InputFilter\Register();
         $inputFilter->setServiceLocator($sm);
         return $inputFilter;
     }, 'PreReg\\InputFilter\\Participant' => function ($sm) {
         $inputFilter = new InputFilter\Participant();
         $inputFilter->setServiceLocator($sm);
         return $inputFilter;
     }, 'PreReg\\Form\\Participant' => function ($sm) {
         $form = new Form\Participant();
         $form->setServiceLocator($sm);
         return $form;
     }, 'PreReg\\InputFilter\\PaymentType' => function ($sm) {
         $inputFilter = new InputFilter\PaymentType();
         $inputFilter->setServiceLocator($sm);
         return $inputFilter;
     }));
 }
Exemplo n.º 3
0
 public function editAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         return $this->redirect()->toRoute('participant', array('action' => 'add'));
     }
     $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $orderService = $this->getServiceLocator()->get('ErsBase\\Service\\OrderService');
     $order = $orderService->getOrder();
     $participant = $order->getParticipantById($id);
     if (!$participant) {
         # TODO: add flash messenger message with error and return
     }
     $breadcrumbService = new Service\BreadcrumbService();
     $form = new Form\Participant();
     $form->setServiceLocator($this->getServiceLocator());
     $optionService = $this->getServiceLocator()->get('ErsBase\\Service\\OptionService');
     $form->get('Country_id')->setValueOptions($optionService->getCountryOptions());
     $form->bind($participant);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             if ($participant->getCountryId() == 0) {
                 $participant->setCountryId(null);
                 $participant->setCountry(null);
             }
             $em->persist($participant);
             $em->flush();
             $breadcrumb = $breadcrumbService->get('participant');
             return $this->redirect()->toRoute($breadcrumb->route, $breadcrumb->params, $breadcrumb->options);
         } else {
             $logger = $this->getServiceLocator()->get('Logger');
             $logger->warn($form->getMessages());
         }
     }
     if (!$breadcrumbService->exists('participant')) {
         $breadcrumbService->set('participant', 'participant');
     }
     $breadcrumb = $breadcrumbService->get('participant');
     return new ViewModel(array('id' => $id, 'form' => $form, 'breadcrumb' => $breadcrumb));
 }
Exemplo n.º 4
0
 public function addAction()
 {
     /*
      * Get and check parameters
      */
     $product_id = (int) $this->params()->fromRoute('product_id', 0);
     $item_id = (int) $this->params()->fromRoute('item_id', 0);
     if (!$product_id) {
         return $this->redirect()->toRoute('product', array('action' => 'index'));
     }
     $participant_id = $this->params()->fromQuery('participant_id');
     $agegroup_id = $this->params()->fromQuery('agegroup_id');
     if (!is_numeric($participant_id)) {
         $participant_id = null;
     }
     if (!is_numeric($agegroup_id)) {
         $agegroup_id = null;
     }
     /*
      * Build and set breadcrumbs
      */
     $forrest = new Service\BreadcrumbService();
     if (!$forrest->exists('product')) {
         $forrest->set('product', 'product');
     }
     $params = array();
     #$params2 = array();
     $options = $this->params()->fromQuery();
     $params['action'] = 'add';
     $params['product_id'] = $product_id;
     if ($participant_id != 0) {
         $options['query'] = array('participant_id' => $participant_id);
     } elseif ($agegroup_id != 0) {
         $options['query'] = array('agegroup_id' => $agegroup_id);
     }
     $params2 = $params;
     if ($item_id) {
         $params['action'] = 'edit';
         # When we're in edit mode there may not be a item_id from
         # returning back from participant (#114)
         $params2 = $params;
         $params2['item_id'] = $item_id;
     }
     $forrest->set('participant', 'product', $params2, $options);
     $forrest->set('cart', 'product', $params2, $options);
     $forrest->set('product', 'product', $params2, $options);
     $forrest->set('bc_stay', 'product', $params2, $options);
     /*
      * Get data for this product
      */
     $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
     $product = $em->getRepository("ErsBase\\Entity\\Product")->findOneBy(array('id' => $product_id));
     $status = $em->getRepository('ErsBase\\Entity\\Status')->findOneBy(array('value' => 'order pending'));
     $form = $this->getServiceLocator()->get('PreReg\\Form\\ProductView');
     #$url = $this->url()->fromRoute('cart', array('action' => 'add'));
     $url = $this->url()->fromRoute('product', $params2, $options);
     $form->setAttribute('action', $url);
     /*
      * Get variants for this product and subproducts
      */
     $variants = $em->getRepository("ErsBase\\Entity\\ProductVariant")->findBy(array('Product_id' => $product_id));
     $defaults = $this->params()->fromQuery();
     $package_info = array();
     foreach ($variants as $variant) {
         $package_info[$variant->getId()] = false;
     }
     $productPackages = $em->getRepository("ErsBase\\Entity\\ProductPackage")->findBy(array('Product_id' => $product_id));
     foreach ($productPackages as $package) {
         $subProduct = $package->getSubProduct();
         $subVariants = $em->getRepository("ErsBase\\Entity\\ProductVariant")->findBy(array('Product_id' => $subProduct->getId()));
         foreach ($subVariants as $variant) {
             $package_info[$variant->getId()] = true;
         }
         $variants = array_merge($variants, $subVariants);
     }
     $form->setVariants($variants, $defaults, $package_info);
     /*
      * get the according deadline
      */
     $deadlineService = $this->getServiceLocator()->get('ErsBase\\Service\\DeadlineService:price');
     $deadline = $deadlineService->getDeadline();
     /*
      * Here starts the cart add Action
      */
     $logger = $this->getServiceLocator()->get('Logger');
     #$this->initializeCart();
     $cartContainer = new Container('cart');
     $formfail = false;
     $request = $this->getRequest();
     if ($request->isPost()) {
         $inputFilter = $form->getInputFilter();
         $form->setInputFilter($inputFilter);
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $request->getPost();
             $logger->info(var_export($data, true));
             /*
              * get needed variables
              */
             $participant_id = 0;
             if (isset($data['participant_id'])) {
                 $participant_id = $data['participant_id'];
                 unset($data['participant_id']);
             }
             $agegroup_id = 0;
             if (isset($data['agegroup_id'])) {
                 $agegroup_id = $data['agegroup_id'];
                 unset($data['agegroup_id']);
             }
             /*
              *  check if participant already has a personalized ticket
              */
             $orderService = $this->getServiceLocator()->get('ErsBase\\Service\\OrderService');
             $order = $orderService->getOrder();
             $package = $order->getPackageByParticipantId($participant_id);
             if ($package != null && $package->hasPersonalizedItem()) {
                 $logger->warn('Package for participant ' . $participant_id . ' already has a personalized item. What should I do?');
             }
             /*
              * get according product entity from database
              */
             $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
             $product = $em->getRepository("ErsBase\\Entity\\Product")->findOneBy(array('id' => $data['Product_id']));
             /*
              * search the according agegroup
              */
             $agegroup = null;
             if ($participant_id != 0) {
                 $participant = $order->getParticipantById($participant_id);
                 if ($participant instanceof Entity\User) {
                     $agegroupService = $this->getServiceLocator()->get('ErsBase\\Service\\AgegroupService');
                     $agegroup = $agegroupService->getAgegroupByUser($participant);
                 }
             } elseif ($agegroup_id != 0) {
                 $agegroup = $em->getRepository("ErsBase\\Entity\\Agegroup")->findOneBy(array('id' => $agegroup_id));
             } else {
                 $logger->emerg('Unable to add/edit product!');
             }
             /*
              *  prepare product data to populate item
              */
             $product_data = $product->getArrayCopy();
             $product_data['Product_id'] = $product_data['id'];
             unset($product_data['id']);
             /*
              * build up item entity
              */
             $item = new Entity\Item();
             $item->setPrice($product->getProductPrice($agegroup, $deadline)->getCharge());
             $item->setStatus($status);
             $item->setProduct($product);
             $item->setAmount(1);
             if ($agegroup != null) {
                 $item->setAgegroup($agegroup->getAgegroup());
             }
             $item->populate((array) $product_data);
             /*
              * add variant data to item entity
              */
             $variant_data = $data['pv'];
             foreach ($product->getProductVariants() as $variant) {
                 $value = $em->getRepository("ErsBase\\Entity\\ProductVariantValue")->findOneBy(array('id' => $variant_data[$variant->getId()]));
                 if ($value && !$value->getDisabled()) {
                     $itemVariant = new Entity\ItemVariant();
                     $itemVariant->populateFromEntity($variant, $value);
                     $itemVariant->setProductVariant($variant);
                     $itemVariant->setProductVariantValue($value);
                     $item->addItemVariant($itemVariant);
                     $itemVariant->setItem($item);
                     #$logger->info('VARIANT '.$variant->getName().': '.$value->getValue());
                 } else {
                     $logger->warn('Unable to find value for variant: ' . $variant->getName() . ' (id: ' . $variant->getId() . ')');
                 }
             }
             /*
              * delete the item we edit when we're in edit mode
              */
             if (is_numeric($item_id) && $item_id != 0) {
                 #$order->removeItem($item_id);
                 $orderService->removeItemById($item_id);
                 #$cartContainer->order->removeItem($item_id);
             }
             /*
              * check product packages and add data to item entity
              */
             $productPackages = $em->getRepository("ErsBase\\Entity\\ProductPackage")->findBy(array('Product_id' => $product->getId()));
             foreach ($productPackages as $package) {
                 $subProduct = $package->getSubProduct();
                 $subItem = new Entity\Item();
                 $subItem->setStatus($status);
                 $subItem->setProduct($subProduct);
                 $subItem->setAmount($package->getAmount());
                 if ($agegroup) {
                     $subItem->setAgegroup($agegroup->getAgegroup());
                 }
                 $product_data = $subProduct->getArrayCopy();
                 $product_data['Product_id'] = $product_data['id'];
                 unset($product_data['id']);
                 $subItem->populate($product_data);
                 $subItem->setPrice(0);
                 $add = false;
                 foreach ($subProduct->getProductVariants() as $variant) {
                     $value = $em->getRepository("ErsBase\\Entity\\ProductVariantValue")->findOneBy(array('id' => $variant_data[$variant->getId()]));
                     if ($value && !$value->getDisabled()) {
                         $add = true;
                         $itemVariant = new Entity\ItemVariant();
                         $itemVariant->populateFromEntity($variant, $value);
                         $itemVariant->setProductVariant($variant);
                         $itemVariant->setProductVariantValue($value);
                         $subItem->addItemVariant($itemVariant);
                         $itemVariant->setItem($subItem);
                     } else {
                         $logger->warn('Unable to find value for variant of subItem: ' . $variant->getName() . ' (id: ' . $variant->getId() . ')');
                     }
                 }
                 if ($add) {
                     $itemPackage = new Entity\ItemPackage();
                     $itemPackage->setSurItem($item);
                     $itemPackage->setSubItem($subItem);
                     $item->addItemPackageRelatedBySurItemId($itemPackage);
                 }
             }
             /*
              * add the newly created item
              */
             $order->addItem($item, $participant_id);
             $em->persist($order);
             $em->flush();
             /*
              * the chooser for product, shopping cart or stay on product 
              * page will be visible for two pageloads. This prevents the 
              * chooser overlay from getting displayd in strange situations
              */
             $cartContainer->chooser = true;
             $cartContainer->chooserCount = 2;
             /*
              * go the route of the breadcrumbs and find the way back. :)
              */
             $forrest = new Service\BreadcrumbService();
             if (!$forrest->exists('product')) {
                 $forrest->set('product', 'product');
             }
             $breadcrumb = $forrest->get('product');
             return $this->redirect()->toRoute($breadcrumb->route, $breadcrumb->params, $breadcrumb->options);
         } else {
             $logger = $this->getServiceLocator()->get('Logger');
             $logger->warn($form->getMessages());
             $formfail = true;
         }
     }
     /*
      * Set form values
      */
     $form->get('submit')->setAttribute('value', 'Add to Cart');
     /*
      * build participant select options
      */
     $optionService = $this->getServiceLocator()->get('ErsBase\\Service\\OptionService');
     $person_options = $optionService->getPersonOptions($product, $participant_id);
     $form->get('participant_id')->setAttribute('options', $person_options);
     /*
      * Disable submit button when there is no person but the ticket is personalized
      */
     if (count($person_options) <= 0 && $product->getPersonalized()) {
         $form->get('submit')->setAttribute('disabled', 'disabled');
     }
     /*
      * Get and build agegroup select options
      */
     $form->get('agegroup_id')->setAttribute('options', $optionService->getAgegroupOptions($agegroup_id));
     /*
      * get all variables for ViewModel
      */
     $breadcrumb = $forrest->get('product');
     $chooser = $cartContainer->chooser;
     $cartContainer->chooser = false;
     $agegroups = $em->getRepository("ErsBase\\Entity\\Agegroup")->findBy(array('price_change' => '1'), array('agegroup' => 'DESC'));
     $participantForm = new Form\Participant();
     $participantForm->setServiceLocator($this->getServiceLocator());
     $participantForm->get('Country_id')->setValueOptions($optionService->getCountryOptions());
     return new ViewModel(array('product' => $product, 'formfail' => $formfail, 'form' => $form, 'participantForm' => $participantForm, 'breadcrumb' => $breadcrumb, 'bc_stay' => $forrest->get('bc_stay'), 'chooser' => $chooser, 'agegroups' => $agegroups, 'deadline' => $deadline));
 }