public function clean() { $count = \Own\Bus\Log\Data::deleteOldMatches(); $this->log('clean matches: ' . $count); $count = \Own\Bus\PlayerMatch\Service::cleanHasViewed(); $this->log('clean has viewed: ' . $count); $count = \Own\Bus\Notification\Data::clean(); $this->log('clean notifications: ' . $count); }
public function index() { if (isset($_POST['sign-out'])) { \Rebond\Core\UserSecurity\Service::signOut($this->signedUser); } // main $tplMain = new Util\Template(Util\Template::SITE, ['www']); if ($this->player->getId() == 0) { $tpl = 'index-guest'; $matchView = \Own\Bus\Match\Data::loadLastMatch(); } else { $tpl = 'index'; $matchView = \Own\Bus\Match\Data::loadRecentByPlayerId($this->player->getId()); $nextMatch = \Own\Bus\Match\Data::loadNextMatchByPlayerId($this->player->getId()); $soon = isset($nextMatch) && $nextMatch->getScheduled() < time() + Engine::DAY * 360 ? true : false; $tplMain->set('player', $this->player); $tplMain->set('notificationCount', \Own\Bus\Notification\Data::countByPlayerId($this->player->getId())); $tplMain->set('isBonusDayXp', $this->player->isBonusDayXp()); $tplMain->set('nextBonusDayXp', $this->player->getNextBonusDayXp()); $tplMain->set('nextMatch', $nextMatch); $tplMain->set('soon', $soon); } $tplMain->set('matchView', $matchView); $options = []; $options['where'][] = 'configuration.property = \'nextWeek\''; $nextWeek = \Own\Bus\Configuration\Data::load($options); $options = []; $options['where'][] = 'configuration.property = \'nextMonth\''; $nextMonth = \Own\Bus\Configuration\Data::load($options); $options = []; $options['where'][] = 'configuration.property = \'nextYear\''; $nextYear = \Own\Bus\Configuration\Data::load($options); if (!isset($nextWeek, $nextMonth, $nextYear)) { Util\error::kill(Util\Code::UNHANDLED_ERROR, 'nextWeek, nextMonth or nextYear is not set in bus_configuration', __FILE__, __LINE__); } $tplMain->set('gameTime', Engine::renderTime($this->app->site()->getCreatedDate())); $tplMain->set('endWeek', (new Util\DateTime())->setTimestamp($nextWeek->getValue())); $tplMain->set('endMonth', (new Util\DateTime())->setTimestamp($nextMonth->getValue())); $tplMain->set('endYear', (new Util\DateTime())->setTimestamp($nextYear->getValue())); // view $this->setTpl(); // 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 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 notification() { $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); } $options = []; $options['where'][] = 'notification.has_read = false'; $options['where'][] = 'notification.match_id = 0'; $options['where'][] = 'notification.created_date > NOW() - INTERVAL ' . \Own\Bus\Engine::DAY * 28 . ' HOUR'; $options['order'][] = 'notification.created_date DESC'; $notifications = \Own\Bus\Notification\Data::loadAllByPlayerId($this->player->getId(), $options); $options = []; $options['where'][] = 'notification.has_read = true'; $options['where'][] = 'notification.match_id = 0'; $options['where'][] = 'notification.created_date > NOW() - INTERVAL ' . \Own\Bus\Engine::DAY * 28 . ' HOUR'; $options['order'][] = 'notification.created_date DESC'; $oldNotifications = \Own\Bus\Notification\Data::loadAllByPlayerId($this->player->getId(), $options); $result = \Own\Bus\Notification\Data::updateReadByPlayerId($this->player->getId()); $json['result'] = $result; $tpl = new Util\Template(Util\Template::MODULE, ['bus', 'notification']); $tpl->set('items', $notifications); $tpl->set('oldItems', $oldNotifications); $json['html'] = $tpl->render('listing'); $json['result'] = \Rebond\Core\ResultType::SUCCESS; return json_encode($json); }