/**
  * @param \JesseMaxwell\PrayerBundle\Model\PrayerRequest $prayerRequest
  */
 public function verifyPrayerRequestRelationship(PrayerRequest $prayerRequest)
 {
     $user = UserQuery::create()->findOneByUsername($this->username);
     if ($prayerRequest && $user->getId() !== $prayerRequest->getUserId()) {
         throw new HttpException(403, 'You are not allowed to access that prayer request.');
     }
 }
 /**
  * Exclude object from result
  *
  * @param   PrayerRequest $prayerRequest Object to remove from the list of results
  *
  * @return PrayerRequestQuery The current query, for fluid interface
  */
 public function prune($prayerRequest = null)
 {
     if ($prayerRequest) {
         $this->addUsingAlias(PrayerRequestPeer::ID, $prayerRequest->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
 /**
  * @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);
 }
 /**
  * Sets values if they are provided in the request.
  *
  * @param \JesseMaxwell\PrayerBundle\Model\PrayerRequest $prayerRequest
  *
  * @return \JesseMaxwell\PrayerBundle\Model\PrayerRequest
  */
 private function setProvidedFields(PrayerRequest $prayerRequest)
 {
     $providedRequest = $this->get('request')->request->get('prayer_request');
     if (!$providedRequest) {
         throw new HttpException(400, "No prayer request was provided.");
     }
     if (array_key_exists("Title", $providedRequest)) {
         $prayerRequest->setTitle($providedRequest["Title"]);
     }
     if (array_key_exists("Date", $providedRequest)) {
         $prayerRequest->setDate($providedRequest["Date"]);
     }
     if (array_key_exists("Description", $providedRequest)) {
         $prayerRequest->setDescription($providedRequest["Description"]);
     }
     if (array_key_exists("Answered", $providedRequest)) {
         $prayerRequest->setAnswered($providedRequest["Answered"]);
     }
     return $prayerRequest;
 }
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param PrayerRequest $obj A PrayerRequest object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool($obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         PrayerRequestPeer::$instances[$key] = $obj;
     }
 }