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 matchStat() { $json = []; $json['result'] = \Rebond\Core\ResultType::ERROR; $matchId = Util\Converter::toString('matchId', 'post'); if (!isset($matchId)) { $json['message'] = Util\Lang::lang('matchNotFound'); return json_encode($json); } $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)) { $json['message'] = Util\Lang::lang('matchNotFound'); return json_encode($json); } $tpl = new Util\Template(Util\Template::MODULE, ['bus', 'match']); $tpl->set('serveLabels', \Own\Bus\PlayerMatch\Service::getServeLabels()); $tpl->set('player1ServeStats', \Own\Bus\PlayerMatch\Service::getServeStats($match->getPlayerMatch1())); $tpl->set('player2ServeStats', \Own\Bus\PlayerMatch\Service::getServeStats($match->getPlayerMatch2())); $tpl->set('returnLabels', \Own\Bus\PlayerMatch\Service::getReturnLabels()); $tpl->set('player1ReturnStats', \Own\Bus\PlayerMatch\Service::getReturnStats($match->getPlayerMatch1())); $tpl->set('player2ReturnStats', \Own\Bus\PlayerMatch\Service::getReturnStats($match->getPlayerMatch2())); $tpl->set('otherLabels', \Own\Bus\PlayerMatch\Service::getOtherLabels()); $tpl->set('player1OtherStats', \Own\Bus\PlayerMatch\Service::getOtherStats($match->getPlayerMatch1())); $tpl->set('player2OtherStats', \Own\Bus\PlayerMatch\Service::getOtherStats($match->getPlayerMatch2())); $tpl->set('attitudeLabels', \Own\Bus\PlayerMatch\Service::getAttitudeLabels()); $tpl->set('player1AttitudeStats', \Own\Bus\PlayerMatch\Service::getAttitudeStats($match->getPlayerMatch1())); $tpl->set('player2AttitudeStats', \Own\Bus\PlayerMatch\Service::getAttitudeStats($match->getPlayerMatch2())); $tpl->set('mentalLabels', \Own\Bus\PlayerMatch\Service::getMentalLabels()); $tpl->set('player1MentalStats', \Own\Bus\PlayerMatch\Service::getMentalStats($match->getPlayerMatch1())); $tpl->set('player2MentalStats', \Own\Bus\PlayerMatch\Service::getMentalStats($match->getPlayerMatch2())); $tpl->set('shotLabels', \Own\Bus\PlayerMatch\Service::getShotLabels()); $tpl->set('player1ShotStats', \Own\Bus\PlayerMatch\Service::getShotStats($match->getPlayerMatch1())); $tpl->set('player2ShotStats', \Own\Bus\PlayerMatch\Service::getShotStats($match->getPlayerMatch2())); $json['html'] = $tpl->render('match-stat'); $json['result'] = \Rebond\Core\ResultType::SUCCESS; return json_encode($json); }
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'); }