/**
  * Filter the query by a related \ApostaAiApi\Models\Bet object
  *
  * @param \ApostaAiApi\Models\Bet|ObjectCollection $bet the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildUserQuery The current query, for fluid interface
  */
 public function filterByBet($bet, $comparison = null)
 {
     if ($bet instanceof \ApostaAiApi\Models\Bet) {
         return $this->addUsingAlias(UserTableMap::COL_ID, $bet->getUserId(), $comparison);
     } elseif ($bet instanceof ObjectCollection) {
         return $this->useBetQuery()->filterByPrimaryKeys($bet->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByBet() only accepts arguments of type \\ApostaAiApi\\Models\\Bet or Collection');
     }
 }
Exemple #2
0
 /**
  * @param ChildBet $bet The ChildBet object to add.
  */
 protected function doAddBet(ChildBet $bet)
 {
     $this->collBets[] = $bet;
     $bet->setUser($this);
 }
 /**
  * Exclude object from result
  *
  * @param   ChildBet $bet Object to remove from the list of results
  *
  * @return $this|ChildBetQuery The current query, for fluid interface
  */
 public function prune($bet = null)
 {
     if ($bet) {
         $this->addCond('pruneCond0', $this->getAliasedColName(BetTableMap::COL_USER_ID), $bet->getUserId(), Criteria::NOT_EQUAL);
         $this->addCond('pruneCond1', $this->getAliasedColName(BetTableMap::COL_CHOSEN_PARTICIPANT_ID), $bet->getChosenParticipantId(), Criteria::NOT_EQUAL);
         $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR);
     }
     return $this;
 }
            unset($result['Bets'][$i]['Participant']['Game']['Participants'][1]['Game']);
            unset($result['Bets'][$i]['Participant']['Game']['Participants'][1]['Bets']);
        }
        return $res->write(json_encode($result));
    })->add(new LoggedInMiddleware());
    $this->post("", function ($req, $res) {
        $body = $req->getParsedBody();
        $chosenParticipantId = $body['ChosenParticipantId'];
        $chosenResult = $body['ChosenResult'];
        $participant = ParticipantQuery::create()->findPk($chosenParticipantId);
        if (!$participant) {
            return $res->withJson(["Message" => "Participant couldn't be found"], 404);
        }
        $user = UserQuery::create()->findPk($_SESSION['id']);
        if ($user->getScore() < $participant->getGame()->getBetCost()) {
            return $res->withJson(["Message" => "User doesn't have enough points"], 400);
        }
        $bet = new Bet();
        $bet->setUserId($_SESSION['id']);
        $bet->setChosenParticipantId($chosenParticipantId);
        $bet->setChosenResult($chosenResult);
        try {
            if ($bet->save()) {
                $user->removeScore($participant->getGame()->getBetCost());
                return $res->withJson(["Message" => "Bet was placed"], 200);
            }
        } catch (Exception $e) {
        }
        return $res->withJson(["Message" => "Bet could not be placed"], 501);
    })->add(new LoggedInMiddleware());
});
 /**
  * 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 you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by find*()
  * and findPk*() calls.
  *
  * @param \ApostaAiApi\Models\Bet $obj A \ApostaAiApi\Models\Bet 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 (null === $key) {
             $key = serialize([null === $obj->getUserId() || is_scalar($obj->getUserId()) || is_callable([$obj->getUserId(), '__toString']) ? (string) $obj->getUserId() : $obj->getUserId(), null === $obj->getChosenParticipantId() || is_scalar($obj->getChosenParticipantId()) || is_callable([$obj->getChosenParticipantId(), '__toString']) ? (string) $obj->getChosenParticipantId() : $obj->getChosenParticipantId()]);
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
 /**
  * @param ChildBet $bet The ChildBet object to add.
  */
 protected function doAddBet(ChildBet $bet)
 {
     $this->collBets[] = $bet;
     $bet->setParticipant($this);
 }