/**
  * Returns a new PrayerRequestQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param   PrayerRequestQuery|Criteria $criteria Optional Criteria to build the query from
  *
  * @return PrayerRequestQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof PrayerRequestQuery) {
         return $criteria;
     }
     $query = new PrayerRequestQuery(null, null, $modelAlias);
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
 public function validate($value, Constraint $context)
 {
     $userId = UserQuery::create()->findIdByUsername($this->username);
     $matchFound = PrayerRequestQuery::create()->findIfUserHasRequest($value, $userId);
     if ($matchFound) {
         throw new HttpException(409, "You already have a prayer request titled that.");
     }
 }
 /**
  * @ApiDoc(
  *      section="Request",
  *      description="Returns the prayer request the user requested.",
  *      requirements={
  *          {
  *              "name"="username",
  *              "dataType"="integer",
  *              "requirement"="\d+",
  *              "description"="Provided username to verify authenticity of the request."
  *          },
  *          {
  *              "name"="id",
  *              "dataType"="integer",
  *              "requirement"="\d+",
  *              "description"="ID of prayer request to return"
  *          }
  *      },
  *      statusCodes={
  *          200="Returned when successful",
  *          404="Returned when the specified prayer request wasn't found.",
  *          403="Returned when the specified prayer request isn't associated with the user which requested it"
  *      }
  * )
  * @Rest\View()
  * @Route("/request/{id}", name="_get_request", requirements={"id": "\d+"})
  * @Method("GET")
  */
 public function getRequestAction($id)
 {
     $prayerRequest = PrayerRequestQuery::create()->findPk((int) $id);
     if (!$prayerRequest) {
         throw new NotFoundHttpException("Prayer request not found");
     }
     $this->get('prayer.verify_action')->verifyPrayerRequestRelationship($prayerRequest);
     return array('prayer_request' => $prayerRequest->toArray());
 }
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param PropelPDO $con
  * @return void
  * @throws PropelException
  * @throws Exception
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(PrayerRequestPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = PrayerRequestQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
 /**
  * @ApiDoc(
  *      section="Actions",
  *      description="Removes a prayer request entity from the database.",
  *      requirements={
  *          {
  *              "name"="username",
  *              "dataType"="string",
  *              "description"="Provided username to verify authenticity of the request."
  *          },
  *          {
  *              "name"="id",
  *              "dataType"="integer",
  *              "requirement"="\d+",
  *              "description"="ID of prayer request to delete"
  *          }
  *      },
  *      statusCodes={
  *          204="Returned when the model was successfully deleted.",
  *          401="Returned when your username is not valid.",
  *          403="Returned when the specified prayer request isn't associated with the user which requested it.",
  *          404="Returned when the specified prayer request wasn't found."
  *      }
  * )
  *
  * @Rest\View(statusCode=204)
  * @Route("/request/delete/{id}", name="_delete_request", requirements={"id": "\d+"})
  * @Method("DELETE")
  */
 public function deleteRequestAction($id)
 {
     $prayerRequest = PrayerRequestQuery::create()->findOneById($id);
     if (!$prayerRequest) {
         throw new NotFoundHttpException("The prayer request that you tried to delete wasn't found.");
     }
     $this->get('prayer.verify_action')->verifyPrayerRequestRelationship($prayerRequest);
     $prayerRequest->delete();
 }