/**
  * Hydrate $object with the provided $data.
  *
  * @param  array $data
  * @param  object $object
  * @return object
  */
 public function hydrate(array $data, $object)
 {
     $customer = null;
     $this->hydrator->hydrate($data, $object);
     if (isset($data['customer']) && isset($data['customer']['id'])) {
         $data['customer'] = $this->customerRepository->getById($data['customer']['id']);
     }
     return $this->hydrator->hydrate($data, $object);
 }
 /**
  * @param array $data
  * @param Order $order
  * @return Order
  */
 public function hydrate(array $data, $order)
 {
     if (isset($data['customer']) && isset($data['customer']['id'])) {
         if (empty($data['customer']['id'])) {
             unset($data['customer']);
         } else {
             $data['customer'] = $this->customerRepository->getById($data['customer']['id']);
         }
     }
     return $this->wrappedHydrator->hydrate($data, $order);
 }
 /**
  * @param Request $request
  * @param string $id
  * @return RedirectResponse|\Illuminate\View\View
  */
 public function newOrEditAction(Request $request, $id = '')
 {
     $viewModel = [];
     $customer = $id ? $this->customerRepository->getById($id) : new Customer();
     if ($request->getMethod() == 'POST') {
         $this->inputFilter->setData($request->request->all());
         if ($this->inputFilter->isValid()) {
             $this->hydrator->hydrate($this->inputFilter->getValues(), $customer);
             $this->customerRepository->begin()->persist($customer)->commit();
             Session::flash('success', 'Customer Saved');
             return new RedirectResponse('/customers/edit/' . $customer->getId());
         } else {
             $this->hydrator->hydrate($request->request->all(), $customer);
             $viewModel['error'] = $this->inputFilter->getMessages();
         }
     }
     $viewModel['customer'] = $customer;
     return view('customers/new-or-edit', $viewModel);
 }
 public function newOrEditAction()
 {
     $id = $this->params()->fromRoute('id');
     $viewModel = new ViewModel();
     $customer = $id ? $this->customerRepository->getById($id) : new Customer();
     if ($this->getRequest()->isPost()) {
         $this->inputFilter->setData($this->params()->fromPost());
         if ($this->inputFilter->isValid()) {
             $customer = $this->hydrator->hydrate($this->inputFilter->getValues(), $customer);
             $this->customerRepository->begin()->persist($customer)->commit();
             $this->flashMessenger()->addSuccessMessage('Customer saved.');
             $this->redirect()->toUrl('/customers/edit/' . $customer->getId());
         } else {
             $this->hydrator->hydrate($this->params()->fromPost(), $customer);
             $viewModel->setVariable('errors', $this->inputFilter->getMessages());
         }
     }
     $viewModel->setVariable('customer', $customer);
     return $viewModel;
 }
 /**
  * @return ViewModel
  */
 public function newAction()
 {
     $viewModel = new ViewModel();
     $order = new Order();
     if ($this->getRequest()->isPost()) {
         $this->orderInputFilter->setData($this->params()->fromPost());
         if ($this->orderInputFilter->isValid()) {
             $order = $this->hydrator->hydrate($this->orderInputFilter->getValues(), $order);
             $this->orders->begin()->persist($order)->commit();
             $this->flashMessenger()->addSuccessMessage('Order Created');
             $this->redirect()->toUrl('/orders/view/' . $order->getId());
         } else {
             $this->hydrator->hydrate($this->params()->fromPost(), $order);
             $viewModel->setVariable('errors', $this->orderInputFilter->getMessages());
         }
     }
     $viewModel->setVariable('customers', $this->customerRepository->getAll());
     $viewModel->setVariable('order', $order);
     return $viewModel;
 }
 /**
  * @param Request $request
  * @return \Illuminate\View\View|RedirectResponse
  */
 public function newAction(Request $request)
 {
     $viewModel = [];
     $order = new Order();
     if ($request->getMethod() == 'POST') {
         $this->inputFilter->setData($request->request->all());
         if ($this->inputFilter->isValid()) {
             $order = $this->hydrator->hydrate($this->inputFilter->getValues(), $order);
             $this->orderRepository->begin()->persist($order)->commit();
             Session::flash('success', 'Order Saved');
             return new RedirectResponse('/orders/view/' . $order->getId());
         } else {
             $this->hydrator->hydrate($request->request->all(), $order);
             $viewModel['error'] = $this->inputFilter->getMessages();
         }
     }
     $viewModel['customers'] = $this->customerRepository->getAll();
     $viewModel['order'] = $order;
     return view('orders/new', $viewModel);
 }