Ejemplo n.º 1
0
 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')]);
 }
Ejemplo n.º 2
0
 public function edit()
 {
     // auth
     Util\Auth::isAuthorized($this->signedUser, 'member', false, '/profile/sign-in');
     $playerForm = new \Own\Bus\Player\Form($this->player);
     $save = Util\Converter::toString('save', 'post');
     if ($save != '') {
         $properties = ['country', 'hand', 'toss', 'acceptChallenge', 'sendNotificationEmail'];
         $playerForm->setFromPost($properties)->validate($properties);
         $fieldAvatar = Util\Validate::validate('avatar', $playerForm->getModel()->getUser()->getAvatarId(), ['media' => false, 'image' => true]);
         $playerForm->getValidation()->addField($fieldAvatar);
         if (!$playerForm->getValidation()->isValid()) {
             Util\Session::set('siteError', $playerForm->getValidation()->getMessage());
         } else {
             $this->player->save();
             $obj = Util\Media::uploadForm('avatarId');
             if ($obj->result == ResultType::SUCCESS) {
                 $this->signedUser->setAvatarId($obj->id);
             }
             if ($obj->result != ResultType::ERROR) {
                 $this->signedUser->save();
             } else {
                 Util\Session::set('siteError', $obj->message);
             }
             Util\Session::setAndRedirect('siteSuccess', 'Profile saved', '/profile');
         }
     }
     // view
     $this->setTpl();
     // main
     $tplMain = new Util\Template(Util\Template::MODULE, ['bus', 'player']);
     $tplMain->set('item', $playerForm);
     // layout
     $this->tplLayout->set('column1', $tplMain->render('editor-site'));
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }