/**
  * @param \JesseMaxwell\PrayerBundle\Model\PrayerRequest $prayerRequest
  *
  * @return \FOS\RestBundle\View\View|\Symfony\Component\HttpFoundation\Response
  * @throws \Exception
  * @throws \PropelException
  */
 private function processRequest(PrayerRequest $prayerRequest)
 {
     $username = $this->get('request')->get('username');
     $userId = UserQuery::create()->findIdByUsername($username);
     $statusCode = $prayerRequest->isNew() ? 201 : 204;
     $headers = array();
     $prayerRequest->setUserId($userId);
     $prayerRequest = $this->setProvidedFields($prayerRequest);
     $errors = $this->get('validator')->validate($prayerRequest);
     if (count($errors) > 0) {
         return $this->view(array('errors' => $this->getErrorList($errors)), 400);
     }
     $prayerRequest->save();
     $content = array('id' => $prayerRequest->getId());
     if ($statusCode === 201) {
         $headers = array('Location' => $this->generateUrl("_get_request", array('username' => $username, 'id' => $prayerRequest->getId()), true));
     }
     return $this->view($content, $statusCode, $headers);
 }
 /**
  * @param \JesseMaxwell\PrayerBundle\Model\PrayerRequest $prayerRequest
  *
  * @return \FOS\RestBundle\View\View|\Symfony\Component\HttpFoundation\Response
  * @throws \Exception
  * @throws \PropelException
  */
 private function processForm(PrayerRequest $prayerRequest)
 {
     $request = $this->get('request');
     $userId = UserQuery::create()->findIdByUsername($request->get('username'));
     $statusCode = $prayerRequest->isNew() ? 201 : 204;
     $headers = null;
     $form = $this->createForm(new PrayerRequestType(), $prayerRequest, array('method' => 'PUT'));
     $form->handleRequest($request);
     $prayerRequest->setUserId($userId);
     if ($form->isValid()) {
         $prayerRequest->save();
         $content = array('id' => $prayerRequest->getId());
         if ($statusCode === 201) {
             $headers = array('Location' => $this->generateUrl("_get_request", array('username' => $request->get('username'), 'id' => $prayerRequest->getId()), true));
         }
         return $this->view($content, $statusCode, $headers);
     }
     return View::create($form, 400);
 }