Example #1
0
 /**
  * Get prices by agegroup
  * 
  * @param \ErsBase\Entity\Agegroup $agegroup
  * @return type
  */
 public function getProductPrice(Agegroup $agegroup = null, Deadline $deadline = null, $search = true)
 {
     $ret = new ProductPrice();
     foreach ($this->getProductPrices() as $price) {
         /* 
          * if a agegroup is given but price has none
          */
         if ($price->getAgegroup() == null && $agegroup != null) {
             continue;
         }
         /* 
          * if a deadline is given but price has none
          */
         if ($price->getDeadline() == null && $deadline != null) {
             continue;
         }
         /*
          * if no agegroup is given but price has one
          */
         if ($price->getAgegroup() != null && $agegroup == null) {
             continue;
         }
         /*
          * if no deadline is given but price has one
          */
         if ($price->getDeadline() != null && $deadline == null) {
             continue;
         }
         /*
          * if agegroup does not match
          */
         if ($price->getAgegroup() != null && $agegroup != null && $price->getAgegroup()->getId() != $agegroup->getId()) {
             continue;
         }
         /*
          * if deadline does not match
          */
         if ($price->getDeadline() != null && $deadline != null && $price->getDeadline()->getId() != $deadline->getId()) {
             continue;
         }
         /*
          * at this point we should only have the prices we want, take the highest one.
          */
         if ($ret->getCharge() < $price->getCharge()) {
             $ret = $price;
         }
     }
     if ($ret->getCharge() == null && $search) {
         /*
          * start searching only by agegroup
          */
         $ret = $this->getProductPrice($agegroup, null, false);
         if ($ret->getCharge() == null) {
             $ret = $this->getProductPrice(null, null, false);
         }
     }
     return $ret;
 }
Example #2
0
 public function addAction()
 {
     $form = new Form\Deadline();
     $form->get('submit')->setValue('Add');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $deadline = new Entity\Deadline();
         #$form->setInputFilter($deadline->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $deadline->populate($form->getData());
             $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
             $em->persist($deadline);
             $em->flush();
             return $this->redirect()->toRoute('admin/deadline');
         } else {
             $logger = $this->getServiceLocator()->get('Logger');
             $logger->warn($form->getMessages());
         }
     }
     return new ViewModel(array('form' => $form));
 }