public function form() { $simple = new \Own\Bus\Simple\Form(); $post = Util\Converter::toString('send', 'post'); if (isset($post)) { if ($simple->setFromPost()->validate()->isValid()) { $result = Util\Media::UploadForm('photoId'); if ($result->result == ResultType::SUCCESS) { $simple->setPhotoId($result->id); } if ($result->result != ResultType::ERROR) { $simple->save(); Util\Session::set('siteSuccess', 'submitted'); } else { Util\Session::set('siteError', $result->message); } } else { Util\Session::set('siteError', 'invalid'); } } // view $this->setTpl(); // main $tplMain = new Util\Template(Util\Template::MODULE, ['bus', 'simple']); $tplMain->set('item', $simple); // layout $this->tplLayout->set('column1', $tplMain->render('form')); // template $this->tplMaster->set('layout', $this->tplLayout->render('layout-2-col')); return $this->tplMaster->render('tpl-default'); }
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 ranking() { \Own\Bus\Match\Data::checkMatchToView($this->player->getId()); // check $type = Converter::toString('type', 'get', 'race'); $page = Converter::toInt('page', 'get', 1); if (!in_array($type, ['race', 'tour'])) { $type = 'race'; } $url = '/tournament/ranking?type=' . $type; $options = []; $options['where'][] = 'player.active = 1'; $count = \Own\Bus\Player\Data::count($options); $players = \Own\Bus\Player\Service::loadRanking($type, $page - 1); // view $this->setTpl(); // filter $tplFilter = new Template(Template::SITE, ['www']); $tplFilter->set('type', $type); $tplFilter->set('otherType', $type == 'race' ? 'tour' : 'race'); $tplFilter->set('current', $page); $tplFilter->set('count', $count); $tplFilter->set('url', $url . '&page='); // main $tplMain = new Template(Template::SITE, ['www']); $tplMain->set('player', $this->player); $tplMain->set('players', $players); // layout $this->tplLayout->set('column1', $tplFilter->render('tour-ranking-filter')); $this->tplLayout->add('column1', $tplMain->render($type . '-ranking')); // template $this->tplMaster->set('layout', $this->tplLayout->render('layout-center')); return $this->tplMaster->render('tpl-default'); }
public function generic() { $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null; $error = Util\Converter::toString('404', 'get'); $tpl = new Util\Template(Util\Template::MODULE, ['app', 'error']); if ($error != '') { header('HTTP/1.1 404 Not Found'); $tpl->set('title', Util\Lang::lang('pageNotFound')); $tpl->set('error', $error); } else { $tpl->set('title', Util\Lang::lang('error')); $tpl->set('error', Util\Lang::lang('error.unknown')); } $tpl->set('referer', $referer); return $tpl->render('generic'); }
public function changePassword() { $signedUser = $this->app->user(); // auth if (!Util\Auth::isAuth($signedUser)) { header('Location: /profile'); exit; } $form = new \Rebond\Core\User\Form($signedUser); // action $change = Util\Converter::toString('resetPassword', 'post'); if (isset($change)) { $form->changePassword('/profile'); } $tpl = new Util\Template(Util\Template::MODULE, ['app', 'User']); $tpl->set('item', $form); $tpl->set('checkCurrentPassword', true); return $tpl->render('password-change'); }
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::loadByUserId($this->signedUser->getId()); if ($player == null) { $player = \Own\Bus\Player\Service::create($this->signedUser); } $player->setActive(true); $player->save(); } $email = Util\Converter::toString('email', 'post'); if (isset($email)) { $user = \Rebond\Core\User\Data::loadByEmail($email); } // view $this->setTpl(); // layout $this->tplLayout->set('column1', $register); // template $this->tplMaster->set('layout', $this->tplLayout->render('layout-center')); return $this->tplMaster->render('tpl-default'); }
public function view() { $matchId = Util\Converter::toInt('id'); $live = Util\Converter::toBool('live'); $key = Util\Converter::toString('key'); $options = []; $options['where'][] = 'match.id = ' . $matchId; $options['where'][] = 'match.status IN (' . MatchStatus::PLAYING . ', ' . MatchStatus::FINISHED . ')'; $match = \Own\Bus\Match\Data::load($options); if (!isset($match)) { Util\Session::siteError('matchNotFound', null, '/match/schedule'); } if ($this->player == null) { $this->player = new \Own\Bus\Player\Model(); } $realKey = \Rebond\Util\Security::encrypt($match->getId()); $hasViewed = $match->hasViewed($this->player->getId()); $options = []; $options['where'][] = ['match_id = ?', $match->getId()]; $options['order'][] = 'id'; $matchLog = \Own\Bus\Log\Data::loadAll($options); if ($live && count($matchLog) == 0) { $live = false; Util\Session::set('siteError', Util\Lang::lang('noMatchLog')); $key = $realKey; } // auth if (!$live) { if ($match->getStatus() == MatchStatus::PLAYING) { Util\Session::siteError('matchPlaying', null, '/match/schedule'); } if ($key != $realKey && !$hasViewed && count($matchLog) > 0 && ($this->player->getId() == $match->getPlayerMatch1()->getPlayerId() || $this->player->getId() == $match->getPlayerMatch2()->getPlayerId())) { $live = true; } } // view $this->setTpl(); // main $tplMain = new Util\Template(Util\Template::SITE, ['www']); $tplMain->set('match', $match); if ($live) { $logs = []; foreach ($matchLog as $log) { $logs[] = $log->toArray(); } $tplMain->set('logs', $logs); $isLive = !$hasViewed && $match->getModifiedDate() > time() - 1800 ? 1 : 0; $tplMain->set('isLive', $isLive); $tplMain->set('key', $realKey); $tpl = 'match-view-live'; $this->tplMaster->set('bodyClass', 'body-' . $match->getSurface()); } else { if ($key == $realKey) { $match->setViewed($this->player->getId()); \Own\Bus\Notification\Data::updateViewedByPlayerIdAndMatchId($this->player->getId(), $match->getId()); } $tpl = 'match-view'; $options = []; $options['where'][] = ['match_id = ?', $match->getId()]; $notification = \Own\Bus\Notification\Data::load($options); $tplMain->set('notification', $notification); $tplMain->set('serveLabels', \Own\Bus\PlayerMatch\Service::getServeLabels()); $tplMain->set('player1ServeStats', \Own\Bus\PlayerMatch\Service::getServeStats($match->getPlayerMatch1())); $tplMain->set('player2ServeStats', \Own\Bus\PlayerMatch\Service::getServeStats($match->getPlayerMatch2())); $tplMain->set('returnLabels', \Own\Bus\PlayerMatch\Service::getReturnLabels()); $tplMain->set('player1ReturnStats', \Own\Bus\PlayerMatch\Service::getReturnStats($match->getPlayerMatch1())); $tplMain->set('player2ReturnStats', \Own\Bus\PlayerMatch\Service::getReturnStats($match->getPlayerMatch2())); $tplMain->set('otherLabels', \Own\Bus\PlayerMatch\Service::getOtherLabels()); $tplMain->set('player1OtherStats', \Own\Bus\PlayerMatch\Service::getOtherStats($match->getPlayerMatch1())); $tplMain->set('player2OtherStats', \Own\Bus\PlayerMatch\Service::getOtherStats($match->getPlayerMatch2())); $tplMain->set('attitudeLabels', \Own\Bus\PlayerMatch\Service::getAttitudeLabels()); $tplMain->set('player1AttitudeStats', \Own\Bus\PlayerMatch\Service::getAttitudeStats($match->getPlayerMatch1())); $tplMain->set('player2AttitudeStats', \Own\Bus\PlayerMatch\Service::getAttitudeStats($match->getPlayerMatch2())); $tplMain->set('mentalLabels', \Own\Bus\PlayerMatch\Service::getMentalLabels()); $tplMain->set('player1MentalStats', \Own\Bus\PlayerMatch\Service::getMentalStats($match->getPlayerMatch1())); $tplMain->set('player2MentalStats', \Own\Bus\PlayerMatch\Service::getMentalStats($match->getPlayerMatch2())); $tplMain->set('shotLabels', \Own\Bus\PlayerMatch\Service::getShotLabels()); $tplMain->set('player1ShotStats', \Own\Bus\PlayerMatch\Service::getShotStats($match->getPlayerMatch1())); $tplMain->set('player2ShotStats', \Own\Bus\PlayerMatch\Service::getShotStats($match->getPlayerMatch2())); $tplMain->set('notificationCount', \Own\Bus\Notification\Data::countByPlayerId($this->player->getId())); } // layout $this->tplLayout->set('column1', $tplMain->render($tpl)); // template $this->tplMaster->set('layout', $this->tplLayout->render('layout-center')); return $this->tplMaster->render('tpl-default'); }
public function membership() { Util\Auth::isAdminAuthorized($this->signedUser, 'member', true, '/'); $this->setTpl(); $membershipId = Util\Converter::toInt('id'); if (!isset($membershipId)) { Util\Session::adminError('item.not.found', [Util\Lang::lang('membership'), $membershipId], '/own/memberships'); } $membership = \Own\Bus\Membership\Data::loadById($membershipId, true); $membershipForm = new \Own\Bus\Membership\Form($membership); // action $save = Util\Converter::toString('save', 'post'); $courtIds = Util\Converter::toArray('court', 'post'); if (isset($save)) { if ($membershipForm->setFromPost()->validate()->isValid()) { \Own\Bus\MembershipCourt\Data::deleteByMembershipId($membership->getId()); $newCourts = []; if (isset($courtIds)) { foreach ($courtIds as $courtId) { $membershipCourt = new \Own\Bus\MembershipCourt\Model(); $membershipCourt->setMembershipId($membership->getId()); $membershipCourt->setCourtId($courtId); $newCourts[] = $membershipCourt; } } \Own\Bus\MembershipCourt\Data::saveAll($newCourts); $membership->save(); Util\Session::adminSuccess('saved', '/own/memberships'); } else { Util\Session::set('adminError', $membershipForm->getValidation()->getMessage()); } } $tplEditor = new Util\Template(Util\Template::SITE, ['admin']); $tplEditor->set('item', $membershipForm); return $this->response('tpl-default', ['title' => Util\Lang::lang('own'), 'jsLauncher' => 'own'], 'layout-1-col', ['column1' => $tplEditor->render('membership-editor')]); }
public function adminBooking() { $isAllowed = Util\Auth::isAdminAuthorized($this->signedUser); $json = []; $json['result'] = \Rebond\Core\ResultType::ERROR; if (!$isAllowed) { $json['message'] = Util\Lang::lang('accessNonAuthorized'); return json_encode($json); } $title = Util\Converter::toString('title', 'post'); $color = Util\Converter::toString('color', 'post'); $courtIds = Util\Converter::toArray('courtIds', 'post'); $startDate = Util\Converter::toDate('startDate', 'post', new \DateTime()); $endDate = Util\Converter::toDate('endDate', 'post', new \DateTime()); $days = Util\Converter::toArray('days', 'post'); $startTime = Util\Converter::toInt('startTime', 'post'); $endTime = Util\Converter::toInt('endTime', 'post'); $count = 0; // @todo validate param $json['startDate'] = $startDate->format('datetime'); $json['endDate'] = $endDate->format('datetime'); $options = []; $options['where'][] = ['id IN (?)', $courtIds]; $courts = \Own\Bus\Court\Data::loadAll($options); $book = new Book\Model(); $book->setType(\Own\Bus\BookingType::ADMIN); $book->setTitle($title); $book->setSequence(uniqid()); $book->setColor($color); $dateLoop = clone $startDate; $today = new \DateTime(); $now = (int) $today->format('H') * 60 + (int) $today->format('i'); $today->setTime(0, 0, 0); $rule = \Own\Bus\Rule\Data::loadById(1, true); $timeLength = $rule->getTimeLength(); foreach ($courts as $court) { $book->setCourtId($court->getId()); while ($dateLoop <= $endDate) { if ($dateLoop < $today) { $dateLoop->add(new \DateInterval('P1D')); continue; } if (!in_array($dateLoop->format('w'), $days)) { $dateLoop->add(new \DateInterval('P1D')); continue; } $possibleTime = (int) $court->getStartTime()->format('H') * 60 + (int) $court->getStartTime()->format('i'); $limitTime = (int) $court->getEndTime()->format('H') * 60 + (int) $court->getEndTime()->format('i'); while ($possibleTime < min($limitTime, $endTime)) { if ($possibleTime >= $startTime && ($dateLoop != $today || $possibleTime >= $now)) { $dateLoop->setTime(floor($possibleTime / 60), $possibleTime % 60, 0); // check for court already booked $options = []; $options['where'][] = ['court_id = ?', $court->getId()]; $options['where'][] = ['booking_date = ?', $dateLoop->format('Y-m-d H:i:00')]; $booking = Book\Data::load($options); if (!isset($booking)) { $book->setBookingDate($dateLoop); $book->save(); $book->setId(0); $count++; } } $dateLoop->setTime(0, 0, 0); $possibleTime += $timeLength; } $dateLoop->add(new \DateInterval('P1D')); } $dateLoop = clone $startDate; } $json['result'] = \Rebond\Core\ResultType::SUCCESS; $json['count'] = $count; return json_encode($json); }
public function sign() { $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); } $tournamentId = Util\Converter::toInt('tournamentId', 'post'); $action = Util\Converter::toString('action', 'post'); if ($tournamentId == 0 || !in_array($action, ['up', 'out'])) { $json['message'] = 'Invalid options'; return json_encode($json); } $tournament = \Own\Bus\Tournament\Data::loadById($tournamentId); $playerId = $this->player->getId(); if ($tournament->getClassification() == Classification::AMATEUR && $this->player->getTourPoint() >= 10) { $json['message'] = Util\Lang::lang('tooManyPointsForAmateur'); return json_encode($json); } if ($tournament->getClassification() != Classification::AMATEUR && $this->player->getTourPoint() < 10) { $json['message'] = Util\Lang::lang('notEnoughPointForTournament'); return json_encode($json); } if ($tournament->getClassification() <= Classification::ATP_250 && $this->player->getTourPoint() <= 100) { $json['message'] = Util\Lang::lang('needMorePointsForATP'); return json_encode($json); } $options = []; $options['where'][] = 'tournament_player.tournament_id = ' . $tournamentId; $tp = \Own\Bus\TournamentPlayer\Data::loadAllByPlayerId($playerId, $options); if ($action == 'up') { if (count($tp) > 0) { $json['message'] = Util\Lang::lang('alreadySignedUp'); return json_encode($json); } if ($this->player->getIsInTournament() || $this->player->getIsRegistered()) { $json['message'] = Util\Lang::lang('alreadySignedUpInOtherTournament'); return json_encode($json); } $tp = new \Own\Bus\TournamentPlayer\Model(); $tp->setTournamentId($tournamentId); $tp->setPlayerId($playerId); $tp->save(); $this->player->setIsRegistered(true); $this->player->save(); $json['result'] = \Rebond\Core\ResultType::SUCCESS; $json['message'] = Util\Lang::lang('signedUp') . '!'; $json['newAction'] = 'out'; $json['html'] = Util\Lang::lang('signOut'); return json_encode($json); } if ($action == 'out') { if (count($tp) == 0) { $json['message'] = Util\Lang::lang('notRegistered'); return json_encode($json); } \Own\Bus\TournamentPlayer\Data::deleteById($tp[0]->getId()); $this->player->setIsRegistered(false); $this->player->save(); $json['result'] = \Rebond\Core\ResultType::SUCCESS; $json['message'] = Util\Lang::lang('signedOut') . '!'; $json['newAction'] = 'up'; $json['html'] = Util\Lang::lang('signUp'); return json_encode($json); } $json['message'] = 'nothing to do'; return json_encode($json); }