public function player() { Util\Auth::isAdminAuthorized($this->signedUser, 'member', true, '/'); $playerId = Util\Converter::toInt('id'); if (!isset($playerId)) { Util\Session::adminError('item.not.found', [Util\Lang::lang('player'), $playerId], '/own'); } $user = \Rebond\Core\User\Data::loadById($playerId, true); $player = \Own\Bus\Player\Data::loadById($playerId, true); $userForm = new \Rebond\Core\User\Form($user); $playerForm = new \Own\Bus\Player\Form($player); // action $save = Util\Converter::toString('save', 'post'); $membershipIds = Util\Converter::toArray('membership', 'post'); if (isset($save)) { if ($user->getId() == 0) { $user->setUsername($user->getEmail()); $user->setPassword(Util\Security::encryptPassword($user->getPassword())); } if ($userForm->setFromPost()->validate()->isValid()) { if ($playerForm->setFromPost()->validate()->isValid()) { \Own\Bus\PlayerMembership\Data::deleteByPlayerId($player->getId()); $newMemberships = []; if (isset($membershipIds)) { foreach ($membershipIds as $membershipId) { $playerMembership = new \Own\Bus\PlayerMembership\Model(); $playerMembership->setPlayerId($player->getId()); $playerMembership->setMembershipId($membershipId); $newMemberships[] = $playerMembership; } } \Own\Bus\PlayerMembership\Data::saveAll($newMemberships); $user->save(); $player->save(); Util\Session::adminSuccess('saved', '/own/player?id=' . $user->getId()); } else { Util\Session::set('adminError', $playerForm->getValidation()->getMessage()); } } else { Util\Session::set('adminError', $userForm->getValidation()->getMessage()); } } $tplEditor = new Util\Template(Util\Template::SITE, ['admin']); $tplEditor->set('user', $userForm); $tplEditor->set('player', $playerForm); $tplInfo = new Util\Template(Util\Template::SITE, ['admin']); $tplInfo->set('user', $user); return $this->response('tpl-default', ['title' => Util\Lang::lang('own'), 'jsLauncher' => 'own'], 'layout-2-col', ['column1' => $tplEditor->render('player-editor'), 'column2' => $tplInfo->render('player-info')]); }
public function buy_credit() { // auth Util\Auth::isAuthorized($this->signedUser, 'member', true, '/'); $playerForm = new \Own\Bus\Player\Form($this->player, 'player'); $credits = $this->player->getCredits(); $this->player->setCredits(0); // action $add = Util\Converter::toString('add', 'post'); if (isset($add)) { $creditValidation = ['required' => true, 'integer' => true, 'minValue' => 1, 'maxValue' => 20]; $playerForm->setFromPost(['credits']); $fieldCredits = Util\Validate::validate('credits', $playerForm->getModel()->getCredits(), $creditValidation); $validation = new \Rebond\Core\Form(); $validation->addField($fieldCredits); $playerForm->setValidation($validation); if ($playerForm->getValidation()->isValid()) { $this->player->addCredits($credits); $this->player->save(); Util\Session::siteSuccess('creditsBought', '/profile'); } else { Util\Session::set('siteError', $playerForm->getValidation()->getMessage()); } } // layout $tplPlayer = new Util\Template(Util\Template::MODULE, ['bus', 'player']); $tplPlayer->set('credits', $credits); $tplPlayer->set('player', $playerForm); return $this->response('tpl-default', ['title' => Util\Lang::lang('profile')], 'layout-home', ['column1' => $tplPlayer->render('buy-credit')]); }
public function mastery() { // auth Util\Auth::isAuthorized($this->signedUser, 'member', false, '/profile/sign-in'); \Own\Bus\Match\Data::checkMatchToView($this->player->getId()); // params $form = true; $id = Util\Converter::toInt('id'); if ($id == 0) { $player = $this->player; } else { $player = \Own\Bus\Player\Data::loadById($id); if (!isset($player)) { $player = $this->player; } else { if ($player->getId() != $this->player->getId()) { $form = false; } } } $playerForm = new \Own\Bus\Player\Form($player); $save = Util\Converter::toString('save', 'post'); if ($save != '') { $oldMastery = $this->player->getMasteryValues(); $properties = \Own\Bus\Player\Service::getMasteryList(); if (!$playerForm->setFromPost($properties)->validate($properties)->isValid()) { Util\Session::setAndRedirect('siteError', $playerForm->getValidation()->getMessage(), '/profile/mastery'); } if (!$player->isValidMastery($oldMastery)) { Util\Session::setAndRedirect('siteError', 'Mastery skills could not be saved!', '/profile/mastery'); } $player->save(); Util\Session::setAndRedirect('siteSuccess', 'Mastery skills saved', '/profile/mastery'); } // view $this->setTpl(); // form $tplForm = new Util\Template(Util\Template::MODULE, ['bus', 'player']); $tplForm->set('form', $form); // layout $tplForm->set('item', $playerForm); $this->tplLayout->set('column1', $tplForm->render('form-mastery')); // template $this->tplMaster->set('layout', $this->tplLayout->render('layout-center')); return $this->tplMaster->render('tpl-default'); }
public function saveTactic() { $isAllowed = Util\Auth::isAuthorized($this->signedUser, 'member'); $json = []; $json['result'] = \Rebond\Core\ResultType::ERROR; if (!$isAllowed) { $json['message'] = Util\Lang::lang('accessNonAuthorized'); return json_encode($json); } $playerForm = new \Own\Bus\Player\Form($this->player); $saveTactic = Util\Converter::toString('save-tactic', 'post'); if ($saveTactic != '') { $oldTactic = $this->player->getTacticValues(); $properties = ['tacticIntensity', 'tacticServe1', 'tacticServe1Side', 'tacticServe2', 'tacticServe2Side', 'tacticReturn1', 'tacticReturn1Side', 'tacticReturn1Expect', 'tacticReturn1ExpectSide', 'tacticReturn1NetExpect', 'tacticReturn2', 'tacticReturn2Side', 'tacticReturn2Expect', 'tacticReturn2ExpectSide', 'tacticBaseline', 'tacticBaselineSide', 'tacticBaselineExpect', 'tacticBaselineExpectSide', 'tacticNet', 'tacticServeNet', 'tacticNetMove', 'tacticNetExpect', 'tacticTurnAround', 'tacticCounter', 'tacticDropshot', 'tacticImportantPoint']; if ($playerForm->setFromPost($properties)->validate($properties)->isValid()) { $this->player->changeTactic($oldTactic); $this->player->save(); $json['result'] = \Rebond\Core\ResultType::SUCCESS; $json['message'] = Util\Lang::lang('tacticSaved'); return json_encode($json); } else { $json['message'] = $playerForm->getValidation()->getMessage(); return json_encode($json); } } $json['message'] = Util\Lang::lang('errorUnknown'); return json_encode($json); }