/** * Close order workflow * * @param \Entity\Order $entity * @return mixed * @throws OrderNotFetchedException * @throws YouAreNotOwnerException */ public function close($entity) { if ($entity->getState()->getId() != 2) { throw new OrderNotFetchedException(); } if ($entity->getOwner()->getId() != $this->getUser()->getId()) { throw new YouAreNotOwnerException(); } $entity->setState($this->cast('Mapper\\OrderState', 3)); $entity->setClosedAt(new \DateTime()); //set new location on device $entity->getDevice()->setLocation($this->getUser()->getLocation()); $entity->getDevice()->setState($this->cast('Mapper\\DeviceState', 1)); $this->flush(); return $this->redirect('/order/show/' . $entity->getId()); }
/** * Close order workflow * * @param \Entity\Order $entity * @param string $bind * @return mixed * @throws OrderNotFetchedException * @throws YouAreNotOwnerException */ public function close($entity, $bind) { if ($entity->getState()->getId() != 2) { throw new OrderNotFetchedException(); } if ($entity->getOwner()->getId() != $this->getUser()->getId()) { throw new YouAreNotOwnerException(); } $entity->setState($this->cast('Mapper\\OrderState', 3)); $entity->setClosedAt(new \DateTime()); //set new location on device $entity->getDevice()->setLocation($this->getUser()->getLocation()); if ($bind == 'me') { $expirationDate = new \DateTime(); $expirationDate->add(new \DateInterval('P14D')); $entity->getDevice()->setUser($this->getUser()); $entity->getDevice()->setHireExpirationDate($expirationDate); } else { $entity->getDevice()->setUser(null); $entity->getDevice()->setHireExpirationDate(null); } $entity->getDevice()->setState($this->cast('Mapper\\DeviceState', 2)); $this->flush(); return $this->redirect('/order/show/' . $entity->getId()); }