Example #1
0
 public function register()
 {
     $userGadget = new \Own\App\User\Gadget($this->app);
     $register = $userGadget->register();
     $this->signedUser = $this->app->user();
     if ($this->signedUser->getId() != 0) {
         $player = \Own\Bus\Player\Data::loadById($this->signedUser->getId());
         if ($player == null) {
             $player = \Own\Bus\Player\Service::create($this->signedUser);
         }
     }
     return $this->response('tpl-default', ['title' => Util\Lang::lang('profile')], 'layout-home', ['column1' => $register]);
 }
Example #2
0
File: Own.php Project: 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')]);
 }
Example #3
0
 public function tour_points()
 {
     // auth
     Util\Auth::isAuthorized($this->signedUser, 'member', false, '/profile/sign-in');
     \Own\Bus\Match\Data::checkMatchToView($this->player->getId());
     $race = Util\Converter::toBool('race', 'get', true);
     // params
     $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;
         }
     }
     if ($race) {
         $options = [];
         $options['join'][] = 'bus_tournament tournament ON tournament.id = tournament_player.tournament_id';
         $options['where'][] = 'tournament.status = ' . TournamentStatus::FINISHED;
         $options['where'][] = 'tournament.start_date > \'' . Engine::getStartYearDate($this->app->site()->getCreatedDate()) . '\'';
         $options['order'][] = 'points DESC';
         $tournaments = \Own\Bus\TournamentPlayer\Data::loadAllByPlayerId($player->getId(), $options);
         $oldTournaments = null;
     } else {
         $options = [];
         $options['join'][] = 'bus_tournament tournament ON tournament.id = tournament_player.tournament_id';
         $options['where'][] = 'tournament.status = ' . TournamentStatus::FINISHED;
         $options['where'][] = 'tournament.start_date > NOW() - INTERVAL ' . Engine::DAY * 336 . ' HOUR';
         $options['order'][] = 'points DESC';
         $tournaments = \Own\Bus\TournamentPlayer\Data::loadAllByPlayerId($player->getId(), $options);
         $options = [];
         $options['join'][] = 'bus_tournament tournament ON tournament.id = tournament_player.tournament_id';
         $options['where'][] = 'tournament.status = ' . TournamentStatus::FINISHED;
         $options['where'][] = 'tournament.start_date < NOW() - INTERVAL ' . Engine::DAY * 336 . ' HOUR';
         $options['order'][] = 'tournament.start_date DESC';
         $oldTournaments = \Own\Bus\TournamentPlayer\Data::loadAllByPlayerId($player->getId(), $options);
     }
     // view
     $this->setTpl();
     // filter
     $tplFilter = new Util\Template(Util\Template::SITE, ['www']);
     $tplFilter->set('race', $race);
     $tplFilter->set('playerId', $player->getId());
     // main
     $tplMain = new Util\Template(Util\Template::SITE, ['www']);
     $tplMain->set('username', $player->getUsername());
     $tplMain->set('tournaments', $tournaments);
     $tplMain->set('oldTournaments', $oldTournaments);
     // layout
     $this->tplLayout->set('column1', $tplFilter->render('profile-tour-point-filter'));
     $this->tplLayout->add('column1', $tplMain->render('profile-tour-point'));
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }
Example #4
0
 public function history()
 {
     // check
     $type = Util\Converter::toString('type', 'get', 'own');
     $page = Util\Converter::toInt('page', 'get', 1);
     $id = Util\Converter::toInt('id', 'get', 0);
     $url = '/match/history?';
     $title = '';
     if (!in_array($type, ['own', 'all', 'f2f'])) {
         $type = 'own';
     }
     if ($type == 'all') {
         $count = \Own\Bus\Match\Data::countFinished($this->player->getId());
         $matches = \Own\Bus\Match\Data::loadAllFinished($this->player->getId(), true, $page - 1);
         $title = '(' . Util\Lang::lower('all') . ')';
         $url .= 'type=all&';
     } else {
         if ($type == 'f2f' && $id != 0) {
             $player = \Own\Bus\Player\Data::loadById($id);
             if (!isset($player)) {
                 $type = 'own';
             } else {
                 $count = \Own\Bus\Match\Data::countFace2Face($player->getId(), $this->player->getId());
                 $matches = \Own\Bus\Match\Data::loadAllFace2Face($player->getId(), $this->player->getId(), $page - 1);
                 $title = '(' . Util\Lang::lower('faceToFace') . ')';
                 $url .= 'type=f2f&id=' . $id . '&';
             }
         }
     }
     if ($type == 'own') {
         if ($id == 0) {
             $player = $this->player;
         } else {
             $player = \Own\Bus\Player\Data::loadById($id);
             if (!isset($player)) {
                 $player = $this->player;
             }
             $title = '';
             $url .= 'id=' . $id . '&';
         }
         $count = \Own\Bus\Match\Data::countFinishedByPlayerId($player->getId(), $this->player->getId() == $player->getId());
         $matches = \Own\Bus\Match\Data::loadAllFinishedByPlayerId($player->getId(), $this->player->getId() == $player->getId(), $page - 1);
     }
     // view
     $this->setTpl();
     // filter
     $tplFilter = new Util\Template(Util\Template::SITE, ['www']);
     $tplFilter->set('current', $page);
     $tplFilter->set('count', $count);
     $tplFilter->set('type', $type);
     $tplFilter->set('title', $title);
     $tplFilter->set('url', $url . 'page=');
     // main
     $tplMain = new Util\Template(Util\Template::SITE, ['www']);
     $tplMain->set('matches', $matches);
     if ($type != 'all') {
         $tplMain->set('playerId', 0);
         $tplMain->set('username', $player->getUsername());
     } else {
         $tplMain->set('playerId', $this->player->getId());
     }
     $tplMain->set('type', $type);
     // layout
     $this->tplLayout->set('column1', $tplFilter->render('match-history-filter'));
     $this->tplLayout->add('column1', $tplMain->render('match-history'));
     // template
     $this->tplMaster->set('layout', $this->tplLayout->render('layout-center'));
     return $this->tplMaster->render('tpl-default');
 }
Example #5
0
 public function bookCourt()
 {
     $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);
     }
     $courtId = Util\Converter::toInt('courtId', 'post');
     $dateTime = Util\Converter::toString('dateTime', 'post');
     $bookingType = Util\Converter::toInt('bookingType', 'post');
     $playerId = Util\Converter::toInt('playerId', 'post');
     $pay = Util\Converter::toInt('pay', 'post');
     $guest = Util\Converter::toString('guest', 'post');
     if (!isset($courtId, $dateTime, $bookingType, $playerId, $pay, $guest) || !array_key_exists($bookingType, \Own\Bus\BookingType::toArray())) {
         $json['message'] = Util\Lang::lang('error.invalid.parameters');
         return json_encode($json);
     }
     $dateTime = new Util\DateTime($dateTime);
     if ($dateTime < new \DateTime()) {
         $json['message'] = Util\Lang::lang('error.invalid.time');
         return json_encode($json);
     }
     switch ($bookingType) {
         case \Own\Bus\BookingType::PARTNER:
             $guest = '';
             break;
         case \Own\Bus\BookingType::GUEST:
             $pay = \Own\Bus\Pay::PLAYER_1;
             $playerId = 0;
             break;
         case \Own\Bus\BookingType::CAROUSSEL:
             $pay = \Own\Bus\Pay::BOTH;
             $playerId = 0;
             $guest = '';
             break;
         default:
     }
     // check player
     $player = \Own\Bus\Player\Data::loadById($playerId);
     if (!isset($player) || $player->getIdItem()->getStatus() != 1) {
         $json['message'] = Util\Lang::lang('playerNotFound');
         return json_encode($json);
     }
     if ($pay == \Own\Bus\Pay::BOTH && $this->player->getCredits() < 1 || $pay == \Own\Bus\Pay::PLAYER_1 && $this->player->getCredits() < 2) {
         $json['message'] = Util\Lang::lang('notEnoughCredits');
         return json_encode($json);
     }
     // check credits
     if ($pay == \Own\Bus\Pay::BOTH && $player->getCredits() < 1 || $pay == \Own\Bus\Pay::PLAYER_2 && $player->getCredits() < 2) {
         $json['message'] = Util\Lang::lang('partnerNotEnoughCredits');
         return json_encode($json);
     }
     // check membership
     $memberships = \Own\Bus\Player\Data::hasMembership($courtId, [$this->player->getId(), $playerId]);
     if ($memberships != 2 || $memberships != 1 && $bookingType != \Own\Bus\BookingType::PARTNER) {
         $json['message'] = Util\Lang::lang('noMembership');
         return json_encode($json);
     }
     // check court time
     $options = [];
     $options['where'][] = ['id = ?', $courtId];
     $court = \Own\Bus\Court\Data::load($options);
     if (!isset($court)) {
         $json['message'] = Util\Lang::lang('error.invalid.parameters');
         return json_encode($json);
     }
     $rule = \Own\Bus\Rule\Data::loadById(1, true);
     $timeLength = $rule->getTimeLength();
     $askedTime = (int) $dateTime->format('H') * 60 + (int) $dateTime->format('i');
     $possibleTime = (int) $court->getStartTime()->format('H') * 60 + (int) $court->getStartTime()->format('i');
     $limitTime = (int) $court->getEndTime()->format('H') * 60 + (int) $court->getEndTime()->format('i');
     if ($askedTime < $possibleTime || $askedTime > $limitTime || $askedTime % $timeLength != 0) {
         $json['message'] = Util\Lang::lang('error.invalid.time');
         return json_encode($json);
     }
     // check for court already booked
     $options = [];
     $options['where'][] = ['court_id = ?', $courtId];
     $options['where'][] = ['booking_date = ?', $dateTime->format('Y-m-d H:i:00')];
     $booking = Book\Data::load($options);
     if (isset($booking)) {
         $json['message'] = Util\Lang::lang('alreadyBookedTime');
         return json_encode($json);
     }
     // check for same hour
     $options = [];
     $options['where'][] = ['player1_id = ? OR player2_id = ?', $this->player->getId(), $this->player->getId()];
     $options['where'][] = ['booking_date BETWEEN ? AND ?', $dateTime->format('Y-m-d H:00:00'), $dateTime->format('Y-m-d H:59:00')];
     $booking = Book\Data::load($options);
     if (isset($booking)) {
         $json['message'] = Util\Lang::lang('alreadyBookedTime');
         return json_encode($json);
     }
     // check for max booking
     $maxBooking = $this->player->getMaxBooking();
     if ($maxBooking > 0) {
         $options = [];
         $options['where'][] = ['player1_id = ? OR player2_id = ?', $this->player->getId(), $this->player->getId()];
         $options['where'][] = 'booking_date > NOW()';
         $futureBookings = Book\Data::count($options);
         if ($futureBookings >= $maxBooking) {
             $json['message'] = Util\Lang::lang('maxBookingReachedByYou');
             return json_encode($json);
         }
     }
     $options = [];
     $options['where'][] = ['player1_id = ? OR player2_id = ?', $playerId, $playerId];
     $options['where'][] = 'booking_date > NOW()';
     $futureBookings = Book\Data::count($options);
     if ($futureBookings >= $player->getMaxBooking()) {
         $json['message'] = Util\Lang::lang('maxBookingReached', [$player->getIdItem()->getFullName()]);
         return json_encode($json);
     }
     // add booking
     if ($pay == \Own\Bus\Pay::BOTH) {
         $this->player->addCredits(-1);
         $this->player->save();
         $player->addCredits(-1);
         $player->save();
     } else {
         if ($pay == \Own\Bus\Pay::PLAYER_1) {
             $this->player->addCredits(-2);
             $this->player->save();
         } else {
             if ($pay == \Own\Bus\Pay::PLAYER_2) {
                 $player->addCredits(-2);
                 $player->save();
             }
         }
     }
     $book = new Book\Model();
     $book->setType($bookingType);
     $book->setPlayer1Id($this->player->getId());
     $book->setPlayer2Id($playerId);
     $book->setCourtId($courtId);
     $book->setBookingDate($dateTime);
     $book->setPay($pay);
     $book->setGuest($guest);
     $book->save();
     $json['result'] = \Rebond\Core\ResultType::SUCCESS;
     $json['message'] = Util\Lang::lang('courtBooked');
     return json_encode($json);
 }
Example #6
0
 public function player()
 {
     $json = [];
     $json['result'] = \Rebond\Core\ResultType::ERROR;
     $matchView = \Own\Bus\Match\Data::loadRecentByPlayerId($this->player->getId());
     if (isset($matchView)) {
         $json['message'] = Util\Lang::lang('matchView');
         return json_encode($json);
     }
     // check
     $id = Util\Converter::toInt('id', 'post');
     // cache
     $cacheTime = $this->app->site()->getCacheTime();
     $cache = Util\Cache::getCache('profile', $this->signedUser->getId() . '_' . $id, $cacheTime);
     if (isset($cache)) {
         $json['html'] = $cache;
         $json['result'] = \Rebond\Core\ResultType::SUCCESS;
         return json_encode($json);
     }
     $player = \Own\Bus\Player\Data::loadById($id);
     if (!isset($player)) {
         $json['message'] = Util\Lang::lang('playerNotFound');
         return json_encode($json);
     }
     $self = $player->getId() == $this->player->getId();
     $stats = \Own\Bus\Match\Data::loadStatsByPlayerId($player->getId(), $self);
     $options = [];
     $options['where'][] = 'winner_id = ' . $player->getId();
     $titles = \Own\Bus\Tournament\Data::count($options);
     $faceToFace = null;
     if (!$self) {
         $faceToFace = \Own\Bus\Match\Data::loadFaceToFace($this->player->getId(), $player->getId());
     }
     // main
     $tplMain = new Util\Template(Util\Template::SITE, ['www']);
     $tplMain->set('self', $self);
     $tplMain->set('player', $player);
     $tplMain->set('stats', $stats);
     $tplMain->set('titles', $titles);
     $tplMain->set('faceToFace', $faceToFace);
     $tplMain->set('ajax', true);
     // layout
     $cache = $tplMain->render('profile');
     Util\Cache::saveCache('profile', $this->signedUser->getId() . '_' . $id, $cacheTime, $cache);
     $json['title'] = $player->getUsername();
     $json['html'] = $cache;
     $json['result'] = \Rebond\Core\ResultType::SUCCESS;
     return json_encode($json);
 }