Ejemplo n.º 1
0
 public function buildMemberships()
 {
     $items = \Own\Bus\Membership\Data::loadAll();
     $memberships = \Own\Bus\PlayerMembership\Data::loadAllByPlayerId($this->getModel()->getId());
     $selectedValues = [];
     foreach ($memberships as $membership) {
         $selectedValues[] = $membership->getMembershipId();
     }
     return Util\Form::buildCheckboxList('membership' . $this->unique, $items, 'id', 'title', $selectedValues);
 }
Ejemplo n.º 2
0
Archivo: Own.php Proyecto: vincium/resa
 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')]);
 }