Пример #1
0
 public static function isAuthorized(\Rebond\Core\User\Model $user, $permission = null, $show = true, $redirect = null)
 {
     if (!isset($permission) || $permission == '') {
         return true;
     }
     if (!self::isAuth($user)) {
         if (isset($redirect)) {
             header('Location: ' . $redirect);
             exit;
         }
         return false;
     }
     $auth = \Rebond\Core\User\Data::hasAccess($user->getId(), $permission, false);
     if ($auth != 0) {
         return true;
     }
     if ($show) {
         Session::add('siteError', Lang::lang('errorAccess', [$permission]));
     }
     Log::log(Error::NOT_ENOUGH_PRIVILEGE, Lang::lang('errorAccess', [$permission]), __FILE__, __LINE__);
     if (isset($redirect)) {
         header('Location: ' . $redirect);
         exit;
     }
     return false;
 }
Пример #2
0
 public function signIn()
 {
     if (!isset($_POST['signIn'])) {
         return;
     }
     $this->setFromPost();
     $fields = [];
     $fields['token'] = $this->validateToken();
     $fields['email'] = $this->validateEmail(false);
     $fields['password'] = $this->validatePassword();
     $this->getValidation()->setFields($fields);
     if ($this->getValidation()->isValid()) {
         $signedUser = Service::loadByEmail($this->getModel()->getEmail(), $this->getModel()->getPassword());
         if (Util\Auth::isAuth($signedUser)) {
             Util\Session::set('allSuccess', Util\Lang::lang('hi', [$signedUser->getUsername()]));
             Util\Session::set('signedUser', $signedUser->getId());
             if (!empty($_POST['persistentCookie'])) {
                 \Rebond\Core\UserSecurity\Service::saveSecure($signedUser, \Rebond\Core\UserSecurity\Model::REMEMBER);
             }
             Util\Log::log(Util\Error::USER_SIGNIN, $signedUser->getId(), __FILE__, __LINE__);
             $this->setModel($signedUser);
         } else {
             Util\Session::set('allError', Util\Lang::lang('incorrectEmailPassword'));
         }
     } else {
         Util\Session::set('allError', $this->getValidation()->getMessage());
     }
 }
Пример #3
0
 public static function savePassword(\Rebond\Core\User\Model $user)
 {
     Util\Log::log(Util\Error::PASSWORD_CHANGE, $user->getId(), __FILE__, __LINE__);
     $db = new Util\Data();
     $query = 'UPDATE core_user SET password = ?, modified_date = ? WHERE id = ?';
     return $db->execute($query, [$user->getPassword(), Util\Format::date(time(), 'sqlDatetime'), $user->getId()]);
 }
Пример #4
0
 public function generate()
 {
     \Rebond\Util\Log::log(Error::LANG_GENERATED, 'Generation of language files', __FILE__, __LINE__);
     \Rebond\Util\Nav::createFolder(\Rebond\Config::getPath('rebond') . 'Cache/');
     $this->generatePhp('Rebond', $this->xmlRebondLang);
     $this->generatePhp('Custom', $this->xmlCustomLang);
     $this->generateJavascript(array($this->xmlRebondLang, $this->xmlCustomLang));
 }
Пример #5
0
 public static function validateToken($unique, $class, $value, $tokenPost)
 {
     $vrf = new \Rebond\Core\Field('token');
     if (self::encrypt($class . $value) != $tokenPost) {
         $log = '[field: token ' . $unique . ', value: ' . $value . ', tokenPost: ' . $tokenPost . ']';
         Log::log(Error::TOKEN, 'Invalid token ' . $log, __FILE__, __LINE__);
         $vrf->setResult(ResultType::ERROR);
         $vrf->setMessage(Lang::lang('errorInvalidToken'));
         return $vrf;
     }
     return $vrf;
 }
Пример #6
0
 public function single($contentGroup)
 {
     $item = Data::loadCurrent($contentGroup);
     if (isset($item)) {
         $tpl = new Util\Template(Util\Template::MODULE, ['app', 'Standard']);
         $tpl->set('item', $item);
         $tpl->set('filter', self::hasFilter());
         return $tpl->render('single');
     } else {
         Util\Log::log(Util\Code::CONTENT_NOT_FOUND, 'Standard contentGroup: ' . $contentGroup, __FILE__, __LINE__);
         return '';
     }
 }
Пример #7
0
 public static function getStadeReach($tournamentId, $points, $size, $classification)
 {
     $list = ['winner', 'finalist', 'semiFinal', 'quarterFinal', 'fourthRound', 'thirdRound', 'secondRound', 'firstRound'];
     if ($size <= 64) {
         unset($list[4]);
     }
     if ($size <= 32) {
         unset($list[5]);
     }
     if ($size <= 16) {
         unset($list[6]);
     }
     $list = array_values($list);
     $i = 0;
     $maxPoints = pow(2, 11 - $classification);
     while ($maxPoints != $points && $maxPoints > 1) {
         $i++;
         $maxPoints /= 2;
     }
     if (!isset($list[$i])) {
         Util\Log::log(\Rebond\Util\Code::DEBUG, 'getStadeReach id:' . $tournamentId . ', i:' . $i . ', count:' . count($list) . ', points:' . $points, __FILE__, __LINE__);
         return Lang::lang($list[count($list) - 1]);
     }
     return Lang::lang($list[$i]);
 }
Пример #8
0
 public static function classificationMove($up, $classification)
 {
     switch ($classification) {
         case Classification::MASTERS:
             return $up ? 0 : 4;
         case Classification::GRAND_SLAM:
             return $up ? 4 : 8;
         case Classification::ATP_1000:
             return $up ? 4 : 4;
         case Classification::ATP_500:
             return $up ? 4 : 4;
         case Classification::ATP_250:
             return $up ? 4 : 8;
         case Classification::CHALLENGER:
             return $up ? 4 : 4;
         case Classification::FUTURE:
             return $up ? 4 : 4;
         case Classification::AMATEUR:
             return $up ? 4 : 0;
     }
     Util\Log::log(Error::DEBUG, 'classificationMove: wrong classification: ' . $classification, __FILE__, __LINE__);
     return 4;
 }
Пример #9
0
 private function log($message, $log = false)
 {
     if ($this->cron) {
         if ($log) {
             Util\Log::log(Util\Code::CRON, date('Y-m-d H:i:s') . ': ' . $message, __FILE__, __LINE__);
         }
         return;
     }
     echo date('H:i:s') . ': ' . $message . '<br>';
 }
Пример #10
0
 public static function removeAndAddPlayer()
 {
     $options = [];
     $options['clearSelect'] = true;
     $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'username']);
     $options['where'][] = 'player.user_id = 0';
     $options['where'][] = 'player.active = 1';
     $players = \Own\Bus\Player\Data::loadAll($options);
     if (count($players) > 0) {
         $db = new Util\Data();
         $pick = \Own\Bus\Engine::dice(0, count($players) - 1);
         $remove = 'UPDATE bus_player SET active = 0 WHERE id = ' . $players[$pick]->getId();
         $db->execute($remove);
         Util\Log::log(Util\Code::CRON, 'player retired: ' . $players[$pick]->getUsername() . ' (' . $players[$pick]->getId() . ')', __FILE__, __LINE__);
         $leagues = \Own\Bus\League\Data::loadAll();
         $player = new \Own\Bus\Player\Model();
         $player->setRandom(1);
         $player->setActive(true);
         if (count($leagues) > 0) {
             $player->setLeagueId(\Own\Bus\Engine::findLeague($leagues, 1));
         }
         $player->save();
         Util\Log::log(Util\Code::CRON, 'new player: ' . $player->getUsername() . ' (' . $player->getId() . ')', __FILE__, __LINE__);
     }
 }
Пример #11
0
 public static function checkCssAndJs($env, $skin)
 {
     if ($env == \Rebond\Config::ENV_LOCAL) {
         return;
     }
     $ran = false;
     $sitePath = \Rebond\Config::getPath('site');
     $rebondCss = $sitePath . 'css/skin/' . $skin . '/rebond.css';
     $customCss = $sitePath . 'css/skin/' . $skin . '/custom.css';
     $minCss = $sitePath . 'css/skin/' . $skin . '/min.css';
     if (!file_exists($minCss) || filemtime($rebondCss) > filemtime($minCss) || filemtime($customCss) > filemtime($minCss)) {
         $css = [];
         $css[] = $sitePath . 'css/normalize.css';
         $css[] = $rebondCss;
         $css[] = $customCss;
         self::compact($css, $minCss);
         $ran = true;
     }
     $rebondJs = $sitePath . 'js/rebond.js';
     $customJs = $sitePath . 'js/custom.js';
     $minJs = $sitePath . 'js/min.js';
     if (!file_exists($minJs) || filemtime($rebondJs) > filemtime($minJs) || filemtime($customJs) > filemtime($minJs)) {
         $js = [];
         $js[] = $rebondJs;
         $js[] = $customJs;
         self::compact($js, $minJs);
         $ran = true;
     }
     if ($ran) {
         \Rebond\Util\Log::log(Error::MIN_GENERATED, 'Generation of minified css and js files', __FILE__, __LINE__);
     }
 }
Пример #12
0
 public static function kill($code, $error, $file, $line)
 {
     $app = \Rebond\App::instance();
     $redirect = (int) Session::get('redirect');
     if ($redirect > 5) {
         $app->setStep(\Rebond\Config::STEP_REDIRECT);
     } else {
         Session::set('redirect', $redirect + 1);
     }
     $logId = Log::log($code, $error, $file, $line);
     $json = [];
     $json['result'] = ResultType::ERROR;
     if ($app->step() != \Rebond\Config::STEP_RUNNING) {
         if ($app->ajax()) {
             $json['message'] = Lang::locale('configurationError');
             echo json_encode($json);
             exit;
         } else {
             $controller = new \Rebond\Controller\Admin\Error($app);
             echo $controller->config();
             session_write_close();
             exit;
         }
     } else {
         // update log level if user isDev
         $app->user();
         if ($app->logLevel() == 0) {
             if ($app->ajax()) {
                 $json['message'] = Lang::lang('serviceNotAvailable') . ': ' . $error . ' [<a href="http://' . \Rebond\Config::getPath('adminUrl') . '/tools/log" target="_blank">' . Lang::lang('logsView') . '</a>]';
                 echo json_encode($json, JSON_UNESCAPED_SLASHES);
                 exit;
             } else {
                 if (in_array($code, [self::PAGE_NOT_FOUND, self::ADMIN_PAGE_NOT_FOUND])) {
                     header('Location: /error/generic?404=' . $error);
                 } else {
                     header('Location: /error/detail?id=' . $logId);
                 }
                 session_write_close();
                 exit;
             }
         } else {
             if ($app->ajax()) {
                 $json['message'] = Lang::lang('errorUnknown');
                 echo json_encode($json);
                 exit;
             } else {
                 if (in_array($code, [self::PAGE_NOT_FOUND, self::ADMIN_PAGE_NOT_FOUND])) {
                     header('Location: /error/generic?404=' . $error);
                 } else {
                     header('Location: /error/generic');
                 }
                 session_write_close();
                 exit;
             }
         }
     }
 }
Пример #13
0
 public static function validate($field, $value, $validation)
 {
     foreach ($validation as $key => $condition) {
         switch ($key) {
             // required
             case 'required':
                 $resultField = self::validateRequired($field, $value, $condition);
                 break;
                 // file
             // file
             case 'image':
                 $resultField = File::validateImage($field, $condition);
                 break;
             case 'document':
                 $resultField = File::validateDocument($field, $condition);
                 break;
                 // type
             // type
             case 'date':
             case 'datetime':
                 $resultField = self::validateDate($field, $value, $condition);
                 break;
             case 'password':
             case 'string':
             case 'richtext':
             case 'text':
                 $resultField = self::validateString($field, $value, $condition);
                 break;
             case 'integer':
             case 'static':
             case 'enum':
             case 'status':
             case 'version':
                 $resultField = self::validateInteger($field, $value, $condition);
                 break;
             case 'multipleKey':
             case 'foreignKey':
             case 'singleKey':
             case 'media':
                 $resultField = self::validateForeignKey($field, $value, $condition);
                 break;
             case 'decimal':
                 $resultField = self::validateNumeric($field, $value, $condition);
                 break;
                 // other
             // other
             case 'exactLength':
                 $resultField = self::validateExactLength($field, $value, $condition);
                 break;
             case 'maxLength':
                 $resultField = self::validateMaxLength($field, $value, $condition);
                 break;
             case 'minLength':
                 $resultField = self::validateMinLength($field, $value, $condition);
                 break;
             case 'letters':
                 $resultField = self::validateLetters($field, $value, $condition);
                 break;
             case 'alphanumeric':
                 $resultField = self::validateAlphaNumeric($field, $value, $condition);
                 break;
             case 'filename':
                 $resultField = self::validateFilename($field, $value, $condition);
                 break;
             case 'username':
             case 'name':
                 $resultField = self::validateName($field, $value, $condition);
                 break;
             case 'url':
                 $resultField = self::validateUrl($field, $value, $condition);
                 break;
             case 'email':
                 $resultField = self::validateEmail($field, $value, $condition);
                 break;
             case 'phone':
                 $resultField = self::validatePhone($field, $value, $condition);
                 break;
             case 'equal':
                 $resultField = self::validateEqual($field, $value, $condition);
                 break;
             case 'different':
                 $resultField = self::validateDifferent($field, $value, $condition);
                 break;
             case 'maxValue':
                 $resultField = self::validateMaxValue($field, $value, $condition);
                 break;
             case 'minValue':
                 $resultField = self::validateMinValue($field, $value, $condition);
                 break;
             default:
                 Log::log(Error::VALIDATION, $key, __FILE__, __LINE__);
                 $resultField = new Field($field);
         }
         if ($resultField->getResult() == ResultType::ERROR) {
             return $resultField;
         }
     }
     return new Field($field);
 }
Пример #14
0
 public function run($app, $friendlyUrl)
 {
     // is site active
     if ($app->site()->getStatus() == 0) {
         $friendlyUrl = '/inactive';
     }
     // retrieve page
     $page = \Rebond\Cms\Page\Data::loadByUrl($friendlyUrl);
     // this should never occur
     if (!isset($page)) {
         Error::kill(Error::PAGE_NOT_FOUND, $friendlyUrl, __FILE__, __LINE__);
     }
     // redirection
     if ($page->getRedirect() != '' && $page->getRedirect() != $friendlyUrl) {
         $friendlyUrl = Nav::readCmsRequest($page->getRedirect());
         echo $this->run($app, $friendlyUrl);
         return;
     }
     // permission
     Auth::isAuthorized($app->user(), $page->getPermission(), true, $app->site()->getSignInUrl());
     $app->setUrl($friendlyUrl);
     // layout
     $layout = \Rebond\Cms\Layout\Data::loadById($page->getLayoutId());
     $tplLayout = new Template(Template::SITE, ['www']);
     // page components
     $options = [];
     $options['where'][] = 'gadget.status = 1';
     $options['order'][] = 'gadget.display_order';
     $gadgets = \Rebond\Cms\Gadget\Data::loadAllByPageId($page->getId(), $options);
     $cacheTime = $app->site()->getCacheTime();
     if ($gadgets) {
         $this->app = $app;
         $this->gadgets = [];
         foreach ($gadgets as $gadget) {
             if ($gadget->getComponent()->getId() == 0) {
                 Log::log(Error::COMPONENT_NOT_FOUND, 'title: ' . $gadget->getTitle() . ', componentId: ' . $gadget->getComponentId(), __FILE__, __LINE__);
                 continue;
             }
             $component = $gadget->getComponent();
             $appGadget = '\\Rebond\\App\\' . $component->getModule()->getTitle() . '\\Gadget';
             $appMethod = $component->getMethod();
             if (!method_exists($appGadget, $appMethod)) {
                 Log::log(Error::GADGET_NOT_FOUND, 'gadget: ' . $appGadget . ', method: ' . $appMethod, __FILE__, __LINE__);
                 continue;
             }
             if ($component->getStatus() !== StatusType::ACTIVE) {
                 continue;
             }
             if ($component->getModule()->getStatus() !== StatusType::ACTIVE) {
                 continue;
             }
             $name = $component->getModule()->getTitle() . '_' . $component->getMethod();
             // look for cache
             if ($cacheTime > 0) {
                 $html = Cache::getGadgetCache($name, $cacheTime);
                 if (isset($html)) {
                     $tplLayout->add('column' . $gadget->getCol(), $html);
                     continue;
                 }
             }
             $gadgetClass = $this->getGadget($appGadget);
             // get filter
             if ($component->getType() == ComponentType::SINGLE_ITEM || $component->getType() == ComponentType::FILTERED_LISTING) {
                 if ($gadget->getFilterId() == 0) {
                     Log::log(Error::EMPTY_FILTER, $name, __FILE__, __LINE__);
                     continue;
                 } else {
                     $render = $gadgetClass->{$appMethod}($gadget->getFilterId());
                 }
             } else {
                 if ($component->getType() == ComponentType::CUSTOM_LISTING) {
                     $render = $gadgetClass->{$appMethod}($gadget->getCustomFilter());
                 } else {
                     $render = $gadgetClass->{$appMethod}();
                 }
             }
             $tplLayout->add('column' . $gadget->getCol(), $render);
             // save cache
             if ($cacheTime > 0) {
                 Cache::saveGadgetCache($name, $cacheTime, $render);
             }
         }
     }
     // check for empty columns
     $columns = $layout->getColumns();
     $noComponent = '<div class="no-component">' . Lang::lang('noComponent') . '</div>';
     $emptyValue = $app->logLevel() == 0 ? $noComponent : '';
     for ($i = 1; $i <= $columns; $i++) {
         if ($tplLayout->varIsSet('column' . $i) === false) {
             $tplLayout->set('column' . $i, $emptyValue);
         }
     }
     // template
     $template = \Rebond\Cms\Template\Data::loadById($page->getTemplateId());
     $tplMaster = new Template(Template::SITE, ['www']);
     // navHeader
     $isMenuCached = false;
     if ($template->getMenu() != \Rebond\Cms\MenuType::NONE) {
         // Get cache
         if ($cacheTime > 0) {
             $navHeader = Cache::getCache('navHeader', $template->getMenu() . '_' . $template->getMenuLevel(), $cacheTime);
             if (isset($navHeader)) {
                 $isMenuCached = true;
             }
         }
         if (!$isMenuCached) {
             $navHeader = \Rebond\Cms\Page\Data::buildHeaderNav($template->getMenuLevel(), $template->getMenu());
             // Save cache
             if ($cacheTime > 0) {
                 Cache::saveCache('navHeader', $template->getMenu() . '_' . $template->getMenuLevel(), $cacheTime, $navHeader);
             }
         }
         $tpl = new Template(Template::SITE, ['www']);
         $tpl->set('title', $app->site()->getTitle());
         $tpl->set('nav', \Rebond\Cms\Page\Service::renderNav($navHeader, $page->getFullUrl()));
         $tplMaster->set('navHeader', $tpl->render('nav-header'));
     }
     // breacrumb
     $isMenuCached = false;
     if ($template->getInBreadcrumb()) {
         // Get cache
         if ($cacheTime > 0) {
             $breadcrumb = Cache::getCache('breadcrumb', $page->getId(), $cacheTime);
             if (isset($breadcrumb)) {
                 $isMenuCached = true;
             }
         }
         if (!$isMenuCached) {
             $breadcrumb = \Rebond\Cms\Page\Service::renderBreadcrumb($page->getId());
             // Save cache
             if ($cacheTime > 0) {
                 Cache::saveCache('breadcrumb', $page->getId(), $cacheTime, $breadcrumb);
             }
         }
         $tplMaster->set('breadcrumb', $breadcrumb);
     }
     // navSide
     $isMenuCached = false;
     if ($template->getSideNav() != \Rebond\Cms\SideNavType::NONE) {
         // Get cache
         if ($cacheTime > 0) {
             $navSide = Cache::getCache('navSide', $template->getSideNav() . '_' . $template->getSideNavLevel(), $cacheTime);
             if (isset($navSide)) {
                 $isMenuCached = true;
             }
         }
         if (!$isMenuCached) {
             switch ($template->getSideNav()) {
                 case \Rebond\Cms\SideNavType::PARENT_1:
                     $currentId = $page->getParentId();
                     break;
                 case \Rebond\Cms\SideNavType::CHILDREN:
                     $currentId = $page->getId();
                     break;
                 case \Rebond\Cms\SideNavType::HOME:
                     $currentId = 1;
                     break;
                 case \Rebond\Cms\SideNavType::PARENT_2:
                     $currentId = \Rebond\Cms\Page\Data::loadByParent($page->getParentId(), 1);
                     break;
                 case \Rebond\Cms\SideNavType::PARENT_3:
                     $currentId = \Rebond\Cms\Page\Data::loadByParent($page->getParentId(), 2);
                     break;
             }
             $navSide = \Rebond\Cms\Page\Data::buildSideNav($currentId, $template->getSideNavLevel());
             // Save cache
             if ($cacheTime > 0) {
                 Cache::saveCache('navSide', $template->getSideNav() . '_' . $template->getSideNavLevel(), $cacheTime, $navSide);
             }
         }
         $tpl = new Template(Template::SITE, ['www']);
         $tpl->set('nav', \Rebond\Cms\Page\Service::renderNav($navSide, $page->getFullUrl()));
         $tplMaster->set('navSide', $tpl->render('nav-side'));
     }
     // navFooter
     $isMenuCached = false;
     if ($template->getInFooter() != 0) {
         // Get cache
         if ($cacheTime > 0) {
             $navFooter = Cache::getCache('navFooter', $template->getFooterLevel(), $cacheTime);
             if (isset($navFooter)) {
                 $isMenuCached = true;
             }
         }
         if (!$isMenuCached) {
             $navFooter = \Rebond\Cms\Page\Data::buildFooterNav($template->getFooterLevel());
             // Save cache
             if ($cacheTime > 0) {
                 Cache::saveCache('navFooter', $template->getFooterLevel(), $cacheTime, $navFooter);
             }
         }
         $tpl = new Template(Template::SITE, ['www']);
         $tpl->set('nav', \Rebond\Cms\Page\Service::renderNav($navFooter, $page->getFullUrl()));
         $tplMaster->set('navFooter', $tpl->render('nav-footer'));
     }
     $tplMaster->set('layout', $tplLayout->render($layout->getFilename()));
     // master
     // head
     if ($app->site()->getKeywords() != '') {
         $tplMaster->addMeta('keywords', $app->site()->getKeywords());
     }
     if ($app->site()->getDescription() != '') {
         $tplMaster->addMeta('description', $app->site()->getDescription());
     }
     $tplMaster->set('title', $page->getTitle());
     $tplMaster->set('site', $app->site()->getTitle());
     $tplMaster->set('skin', $app->skin());
     $tplMaster->set('siteUrl', \Rebond\Config::getPath('siteUrl'));
     // bodyClass
     $tplMaster->set('bodyClass', $page->getClass());
     // footer
     $ga = \Rebond\Core\Site\Service::renderGoogleAnalytics($app->site()->getGoogleAnalytics());
     $tplMaster->set('footer', $ga);
     $tplMaster->addJs('//code.jquery.com/jquery-2.1.4.min.js');
     $tplMaster->addJs('/js/lang-' . $app->lang() . '.js');
     if ($app->site()->getJs() != '') {
         $jsList = explode(',', $app->site()->getJs());
         foreach ($jsList as $js) {
             $tplMaster->addJs($js);
         }
     }
     if ($page->getJs() != '') {
         $jsList = explode(',', $page->getJs());
         foreach ($jsList as $js) {
             $tplMaster->addJs($js);
         }
     }
     if ($app->env() == \Rebond\Config::ENV_PROD) {
         $tplMaster->addCss('/css/skin/' . $app->skin() . '/min.css');
         $tplMaster->addJs('/js/min.js');
     } else {
         $tplMaster->addCss('/css/normalize.css');
         $tplMaster->addCss('/css/skin/' . $app->skin() . '/rebond.css');
         $tplMaster->addCss('/css/skin/' . $app->skin() . '/custom.css');
         $tplMaster->addJs('/js/rebond.js');
         $tplMaster->addJs('/js/custom.js');
     }
     if ($app->site()->getCss() != '') {
         $cssList = explode(',', $app->site()->getCss());
         foreach ($cssList as $css) {
             $tplMaster->addCss($css);
         }
     }
     if ($page->getCss() != '') {
         $cssList = explode(',', $page->getCss());
         foreach ($cssList as $css) {
             $tplMaster->addCss($css);
         }
     }
     return $tplMaster->render($template->getFilename());
 }
Пример #15
0
 private function noPrivilege($permission)
 {
     Log::log(Error::NOT_ENOUGH_PRIVILEGE, 'permission: ' . $permission . ', user: '******'result' => ResultType::ERROR, 'message' => Lang::lang('accessNonAuthorized')];
     return json_encode($json);
 }
Пример #16
0
 public function findWinnerId()
 {
     $setWon1 = $this->getWinnerBySet(1, 1) + $this->getWinnerBySet(1, 2) + $this->getWinnerBySet(1, 3) + $this->getWinnerBySet(1, 4) + $this->getWinnerBySet(1, 5);
     if ($setWon1 == ($this->getBestOfSets() + 1) / 2) {
         $this->winnerId = $this->getPlayerMatch1Id();
         return $this->winnerId;
     }
     $setWon2 = $this->getWinnerBySet(2, 1) + $this->getWinnerBySet(2, 2) + $this->getWinnerBySet(2, 3) + $this->getWinnerBySet(2, 4) + $this->getWinnerBySet(2, 5);
     if ($setWon2 == ($this->getBestOfSets() + 1) / 2) {
         $this->winnerId = $this->getPlayerMatch2Id();
         return $this->winnerId;
     }
     // should not happen, bug
     if ($this->getCurrentSet() > $this->getBestOfSets()) {
         \Rebond\Util\Log::log(\Rebond\Util\Code::DEBUG, 'match finished (' . $setWon1 . '/' . $setWon2 . ') for best of ' . $this->getBestOfSets() . ' sets, but with no winner: ' . $this->getId(), __FILE__, __LINE__);
         $this->winnerId = $this->getPlayerMatch1Id();
         return $this->getPlayerMatch1Id();
     }
     $this->winnerId = 0;
     return $this->winnerId;
 }