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 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 matchLog() { $json = []; $json['result'] = \Rebond\Core\ResultType::ERROR; // check $matchId = Util\Converter::toInt('matchId', 'post'); $debug = Util\Converter::toBool('debug', 'post', false); $options = []; $options['where'][] = ['match_id = ?', $matchId]; $options['order'][] = 'id'; $matchLog = \Own\Bus\Log\Data::loadAll($options); if (count($matchLog) == 0) { $json['message'] = Util\Lang::lang('noMatchLog'); return json_encode($json); } $logs = []; foreach ($matchLog as $log) { $logs[] = $log->toArray(); } $htmlLog = ''; if (count($logs) > 0) { $htmlLog .= '<table class="list">'; foreach ($logs as $log) { $htmlLog .= '<tr>'; $htmlLog .= '<td class="score">' . \Own\Bus\Engine::renderScore($log['game'], $log['point1'], $log['point2']) . '</td>'; $htmlLog .= '<td>' . \Own\Bus\Engine::renderDescription($log['description'], $debug); $htmlLog .= '<strong>' . Util\Lang::lang($log['result']) . '</strong></td>'; $htmlLog .= '</tr>'; } $htmlLog .= '</table>'; } // layout $json['result'] = \Rebond\Core\ResultType::SUCCESS; $json['html'] = $htmlLog; return json_encode($json); }