/** * @todo put this on sql transaction */ public function insert() { $dateCreated = date('Y-m-d H:i:s', time()); $this->setDateCreated($dateCreated); $this->setPlayed(sizeof($this->getOdds())); $this->setUserIdFK($this->getUser()->getUserId()); $this->setFinished(0); $this->setStatus(0); if (!parent::insert()) { return false; } $betSlipId = $this->getConnection()->getInsertId(); $transaction = new Model_TransactionModel(); $transaction->setMoney($this->getStake() * -1); $transaction->setTransactionTypeIdFK(3); $transaction->setUserIdFK($this->getUser()->getUserId()); $transaction->setTransactionTypeIdendifier($betSlipId); $transaction->setDateCreated($dateCreated); if (!$transaction->insert($dateCreated)) { $this->setValidationError('sql', 'Server Error'); $this->delete(); } /** * @todo put this in one query */ foreach ($this->getOdds() as $o) { $odds = new Model_BetSlipOddsModel(); $odds->setOddValueIdFK($o); $odds->setBetSlipIdFK($betSlipId); $odds->insert(); } }
public function registration() { $bookhouse = new Model_BookhouseModel(); $bookhouse->loadActiveBookhouse(); if ($bookhouse->getCanUserRegister() == 0) { $this->setValidationError('Bookhouse', 'Registration is disabled'); } $userCheckModel = new Model_UserModel(); $userCheckModel->load(array('user_name' => $this->getUserName())); $userId = $userCheckModel->getUserId(); if (isset($userId)) { $this->setValidationError('username', 'Username already exist'); return; } $userCheckModel->load(array('email' => $this->getEmail())); $userId = $userCheckModel->getUserId(); if (isset($userId)) { $this->setValidationError('username', 'Email already exist'); return; } $this->setLastLogin(date('Y-m-d H:i:s')); $this->setUserStatusIdFK(3); $this->setBanned(0); $this->setEmailValidated(0); $this->insert(); $userIdFK = $this->getConnection()->getInsertId(); $transaction = new Model_TransactionModel(); $transaction->setUserIdFK($userIdFK); $transaction->setTransactionTypeIdFK(1); $transaction->setMoney($bookhouse->getDefaultMoneyValue()); $transaction->setTransactionTypeIdendifier(null); $transaction->insert(); }