Today's MOST CHASED

    * @package equestions.components */ class EQUESTIONS_CMP_Question extends OW_Component { public function __construct( $questionId, $userContext = null, $count = null, $options = null ) { parent::__construct(); $language = OW::getLanguage(); $configs = OW::getConfig()->getValues('equestions'); $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count; $uniqId = uniqid('question_'); $this->assign('uniqId', $uniqId); $service = EQUESTIONS_BOL_Service::getInstance(); $userId = OW::getUser()->getId(); $question = $service->findQuestion($questionId); if ( empty($question) ) { $this->assign('noQuestion', true); return; } $settings = $question->getSettings(); $odds = null; $oddsService = EQUESTIONS_BOL_OddsService::getInstance(); $teams = $oddsService->extractTeamsFromQuestion($question->text); $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay( [ ['odds' => -110], ['odds' => +140] ], 20 ); // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
        
     * @package equestions.components
     */
    class EQUESTIONS_CMP_Question extends OW_Component
    {
        public function __construct( $questionId, $userContext = null, $count = null, $options = null )
        {
            parent::__construct();
    
            $language = OW::getLanguage();
    
            $configs = OW::getConfig()->getValues('equestions');
            $count = empty($count) ? EQUESTIONS_BOL_Service::MORE_DISPLAY_COUNT : $count;
    
            $uniqId = uniqid('question_');
            $this->assign('uniqId', $uniqId);
    
            $service = EQUESTIONS_BOL_Service::getInstance();
    
            $userId = OW::getUser()->getId();
            $question = $service->findQuestion($questionId);
    
            if ( empty($question) )
            {
                $this->assign('noQuestion', true);
    
                return;
            }
    
            $settings = $question->getSettings();
            
            $odds = null;
    
            $oddsService = EQUESTIONS_BOL_OddsService::getInstance();
            $teams = $oddsService->extractTeamsFromQuestion($question->text);
            $result = EQUESTIONS_BOL_OddsService::getInstance()->calculateParlay(
                [
                    ['odds' => -110],
                    ['odds' => +140]
                ],
                20
            );
            // echo "
    "; print_r($result); die;
    
            OW::getLogger()->addEntry(json_encode($result), 'parlay_test');
    
            if ( !empty($teams) )
            {
                $sportKey = $oddsService->detectSportKey($question->text);
            
                if ( $sportKey )
                {
                    $cache = OW::getCacheManager();
            
                    // Stable cache key (sport + teams)
                    $cacheKey = 'equestions_odds_' . md5($sportKey . '_' . implode('_', $teams));
            
                    // Cache contains either:
                    //  - game array
                    //  - false (no match)
                    $cachedGame = $cache->load($cacheKey);
            
                    if ( $cachedGame === null )
                    {
                        // 🔥 API CALL — ONLY ON FIRST REQUEST
                        $oddsData = $oddsService->fetchOdds($sportKey);
            
                        $game = $oddsService->findMatchingGame($oddsData, $teams);
            
                        // Cache result EVEN IF NO MATCH
                        $cache->save($game ?: false, $cacheKey, 300);
            
                        $odds = $game ?: null;
                    }
                    else
                    {
                        // false means "no match found previously"
                        $odds = $cachedGame ?: null;
                    }
                }
            }
            
        
            if ($odds)
            {
                $this->assign('odds', $odds);
            }
    
            // echo "odds 
    "; print_r($odds); die;
    
            $isPoll = !$settings['allowAddOprions'];
            $optionTotal = $service->findOptionCount($questionId);
            $answerCount = $service->findTotalAnswersCount($questionId);
            $postCount = BOL_CommentService::getInstance()->findCommentCount('question', $questionId);
            $isAutor = $question->userId == $userId;
    
            if ( $optionTotal - $count < 10 )
            {
                $count = $optionTotal;
            }
    
            $limit = $count ? array(0, $count) : null;
    
            $answers = new EQUESTIONS_CMP_Answers($question, $optionTotal, $limit);
            $answers->setExpandedView();
            $answers->setSettings($options);
    
    
            if ( isset($options['inPopup']) && $options['inPopup'] === true )
            {
                $answers->setInPopupMode();
            }
    
            if ( isset($options['loadStatic']) && $options['loadStatic'] === false )
            {
                $answers->setDoNotLoadStatic();
            }
            if ( !empty($options['odds']) )
            {
                $this->assign('odds', $options['odds']);
            }
    
            $editable = $service->isCurrentUserCanInteract($question);
            $answers->setEditable($editable && $service->isCurrentUserCanAnswer($question));
    
            if ( $userContext !== null )
            {
                $answers->setUsersContext($userContext);
            }
    
            $answers->showAddNew();
            $this->addComponent('answers', $answers);
    
            $followsCount = $service->findFollowsCount($question->id, $userContext, array($question->userId));
          
    
         
            $statusCmp = new EQUESTIONS_CMP_QuestionStatus($answers->getUniqId(), $postCount, $answerCount, $followsCount,$question);
            $plugin = OW::getPluginManager()->getPlugin('equestions');
            $statusCmp->setTemplate($plugin->getCmpViewDir() . 'question_static_status.html');
            $this->addComponent('questionStatus', $statusCmp);
    
            $tplQuestion = array(
                'text' => nl2br($question->text)
            );
    
            $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_ON_QUESTION_RENDER, array(
                "questionId" => $question->id,
                "questionDto" => $question,
                "text" => $question->text,
                "settings" => $settings,
                "uniqId" => $uniqId
            ), $tplQuestion);
            
            OW::getEventManager()->trigger($event);
            
            $this->assign('question', $event->getData());
            
            
            $js = UTIL_JsGenerator::newInstance()->newObject('question', 'QUESTIONS_Question', array($uniqId, $question->id));
    
            if ( $configs['allow_comments'] )
            {
                $commentsParams = new BASE_CommentsParams('equestions', EQUESTIONS_BOL_Service::ENTITY_TYPE);
                $commentsParams->setEntityId($question->id);
                $commentsParams->setDisplayType(BASE_CommentsParams::DISPLAY_TYPE_TOP_FORM_WITH_PAGING);
                $commentsParams->setCommentCountOnPage(5);
                $commentsParams->setOwnerId($question->userId);
    
                $commentsParams->setAddComment($editable);
    
                $commentCmp = new BASE_CMP_Comments($commentsParams);
                //$commentTemplate = OW::getPluginManager()->getPlugin('equestions')->getCmpViewDir() . 'comments.html';
                //$commentCmp->setTemplate($commentTemplate);
    
                $this->addComponent('comments', $commentCmp);
    
                if ( !empty($options['focusToPost']) )
                {
                    $js->addScript('question.focusOnPostInput()');
                }
            }
    
            $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
    
            $js->addScript('question.setAnswerList(' . $jsSelector . ');');
    
            if ( !empty($options['relation']) )
            {
                $js->addScript($jsSelector . '.setRelation("' . $options['relation'] . '");');
            }
    
            $js->equateVarables(array('QUESTIONS_QuestionColletction', $uniqId), 'question');
            OW::getDocument()->addOnloadScript($js);
    
            $toolbar = array();
    
            if ( $service->isCurrentUserCanInteract($question) )
            {
                if ( $configs['enable_follow'] )
                {
                    $this->assign('follow', array(
                        'isFollow' => $service->isFollow($userId, $question->id),
                        'followId' => $answers->getUniqId() . '-follow',
                        'unfollowId' => $answers->getUniqId() . '-unfollow',
                        'followClick' => $jsSelector . '.followQuestion()',
                        'unfollowClick' => $jsSelector . '.unfollowQuestion()'
                    ));
                }
    
                if ( $configs['ask_friends'] && $service->isCurrentUserCanAskFriend($question) )
                {
                    $friendMode = (bool) OW::getEventManager()->call('plugin.friends');
                    $askLabel = $friendMode ? $language->text('equestions', 'toolbar_ask_friends') : $language->text('equestions', 'toolbar_ask_users');
    
                    $this->assign('ask', array(
                        'label' => $askLabel,
                        'onClick' => $jsSelector . '.showUserSelector()'
                    ));
                }
            }
    
            if ( $isPoll )
            {
                $list = $service->findUserAnswerListByQuestionId($userId, $questionId );
    
                if ( count((array)$list) )
                {
                    $toolbar[] = array(
                        'label' => '' .
                            $language->text('equestions', 'toolbar_unvote_btn') . ''
                    );
                }
            }
    
            if ( $service->isCurrentUserCanEdit($question) )
            {
                $condEmbed = "confirm('" . $language->text('equestions', 'delete_question_confirm') . "')";
                $toolbar[] = array(
                    'label' => '' .
                            $language->text('equestions', 'toolbar_delete_btn') . ''
                );
            }
    
            $userData = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($question->userId));
            $questionInfo = array(
                'avatar' => $userData[$question->userId],
                'profileUrl' => $userData[$question->userId]['url'],
                'displayName' => $userData[$question->userId]['title'],
                'content' => '',
                'toolbar' => $toolbar,
                'date' => UTIL_DateTime::formatDate($question->timeStamp)
            );
    
            $this->assign('questionInfo', $questionInfo);
        }
    }
    
    
    
        
  • Username
    google_user_8802
    i
    google_user_8802
  • Username
    weaversplus
    Gender
    Male
    Birthday / Age
    Sep 28
    Looking for
    Male
    Profile Bio
    Weavers Plus is a Rug Store located in Toronto, Ontario. We have been in business for many years and are experts when it comes to rugs. We specialize in everything from Professional Rug Cleaning & Washing, Rug Repair & Restoration and Rug Underlay’s.
    Business phone
    +1 416-861-1480
    i
    weaversplus, 25
  • Username
    twicsynligfo
    Gender
    Male
    Birthday / Age
    Feb 1
    Looking for
    Male, Female
    Here for
    Networking, Dating
    Profile Bio
    Website: https://twicsy.com/nl/instagram-followers-kopen Address: District C1 Building, Office 209, World Trade Center, Dubai, UAE Phone: +1 855-848-9812 Email: twicsynligfollowerskopen@gmail.com Tags: #twicsy, #followers, #instagramfollowers, #buyfollowers, #buyinstagramfollowers, #instagram Google Sites: https://sites.google.com/view/twicsynligfollowerskopen Social: https://500px.com/p/twicsynligfollowerskopen https://profile.hatena.ne.jp/twicsynligfollowerskopen/ https://www.imdb.com/user/ur180298985/ https://dentalilan.com/uye/profil/73265 https://raspberrypi.dk/forum/users/twicsynligfollowerskopen/
    Business types
    Transportation and Trucking
    i
    twicsynligfo, 31
  • Username
    AssessmentHelps
    Gender
    Male
    Birthday / Age
    Jan 1
    Looking for
    Male
    Here for
    Networking, Marketing, Business Service, Work
    Profile Bio
    My name is edward and i am academic writing expert at http://assessmenthelps.com/.
    Business phone
    +61280067005
    Supplier Pro info
    Assignment Help,
    Business Info.
    Unlocking Success with Assignment Help
    Business types
    Accounting / Consultant / Administration Services, Education and Training, Writing & Editing / Media Services
    i
    AssessmentHelps, 26
  • Username
    google_user_8798
    i
    google_user_8798
  • Username
    google_user_8797
    i
    google_user_8797
  • Username
    google_user_8796
    Gender
    Male
    Birthday / Age
    Nov 17
    i
    google_user_8796, 27
  • Username
    google_user_8795
    i
    google_user_8795
  • Username
    wearochre
    Gender
    Male
    Birthday / Age
    Apr 25
    Looking for
    Female
    Profile Bio
    The brand Ochre was conceived in Karachi in the year 2013, to satiate the dire need of a good quality and reasonable priced fashion clothing brand for both young boys and girls.
    Business phone
    03111444920
    Business Info.
    Ochre Clothing
    i
    wearochre, 31
  • Username
    google_user_8793
    i
    google_user_8793
  • Username
    google_user_8792
    Gender
    Male
    Birthday / Age
    Oct 13
    Profile Bio
    Market Research Firm and Business Consulting Firm - Quadrant Market Insights offers syndicated, custom reports backed by industry connects and expert consultations.
    Business types
    Accounting / Consultant / Administration Services
    i
    google_user_8792, 30
  • Username
    CarraraLuxuryDrugLosAngeles
    Gender
    Male
    Birthday / Age
    Aug 15
    Profile Bio
    Many of us have worked in the world of treatment and luxury treatment for many years, and over the years, we have watched other “so-called” luxury treatment centers lose what it means to be luxury. Carrara Luxury Drug & Alcohol Rehab have come together to redefine what it means to be a luxury treatment center. Five Star accommodations with world-class treatment.
    Business phone
    3233029650
    Business Info.
    1814 Marcheeta Pl,, Los Angeles, CA 90069
    Business types
    Medical and Health Care Services
    Youtube Channel link
    https://www.youtube.com/@carraratreatment
    i
    CarraraLuxuryDrugLosAngeles, 37
  • Username
    CarraraLuxuryDrugandAlcoholRehab
    Gender
    Male
    Birthday / Age
    Sep 15
    Profile Bio
    Many of us have worked in the world of treatment and luxury treatment for many years, and over the years, we have watched other “so-called” luxury treatment centers lose what it means to be luxury. Carrara Luxury Drug & Alcohol Rehab have come together to redefine what it means to be a luxury treatment center. Five Star accommodations with world-class treatment.
    Business phone
    3233029650
    Business Info.
    1813 Marcheeta Pl, Los Angeles, CA 90069
    Business types
    Medical and Health Care Services
    Youtube Channel link
    https://www.youtube.com/@carraratreatment
    i
    CarraraLuxuryDrugandAlcoholRehab, 37
  • Username
    google_user_8789
    i
    google_user_8789
  • Username
    twicsyesprarigseguidores
    Gender
    Male
    Birthday / Age
    Jan 2
    Looking for
    Male
    Here for
    Friendship
    Profile Bio
    Website: https://twicsy.com/es/comprar-instagram-seguidores Address: District C1 Building, Office 209, World Trade Center, Dubai, UAE Phone: +1 855-848-9812 Email: twicsyesprarigseguidores@gmail.com Tags: #twicsy, #followers, #instagramfollowers, #buyfollowers, #buyinstagramfollowers, #instagram Google Sites: https://sites.google.com/view/twicsyesprarigseguidores
    i
    twicsyesprarigseguidores, 48
  • Username
    twicsykobuyinstagramfollowers
    Gender
    Female
    Birthday / Age
    Sep 5
    Profile Bio
    Twicsy에서 Instagram 팔로어 구매: 소셜 미디어 전략 강화 기업이 계속해서 소셜 미디어 마케팅의 힘을 수용함에 따라 Instagram과 같은 플랫폼에서 팔로어, 좋아요 및 참여를 위한 경쟁이 점점 더 치열해지고 있습니다. Instagram의 엄청난 수의 사용자로 인해 기업이 디지털 환경을 탐색하는 데 도움이 되는 다양한 도구와 서비스가 등장했습니다. 그러한 서비스 중 하나인 Twicsy는 Instagram 팔로어를 구매할 수 있는 기회를 제공하여 소셜 미디어 전략을 강화하는 지름길을 제공합니다. 이 기사에서는 Twicsy에서 Instagram 팔로어를 구매할 때의 이점을 살펴보고 기업이 이 서비스를 이용할 때 고려해야 할 사항을 자세히 살펴보겠습니다. Instagram에서 도달 범위와 가시성을 높이는 것은 강력한 온라인 입지를 구축하려는 모든 비즈니스에 매우 중요합니다. 월간 활성 사용자 수가 10억 명이 넘는 Instagram은 도달하기를 기다리는 방대한 잠재 고객 풀을 제공합니다. 그러나 팔로어 기반을 유기적으로 성장시키는 것은 시간이 많이 걸리고 어려운 과정이 될 수 있습니다. Twicsy가 Instagram에서 성장을 가속화하려는 기업을 위한 맞춤형 솔루션을 제공하는 곳이 바로 여기입니다. Twicsy에서 Instagram 팔로어를 구매하는 주요 이점은 그것이 제공하는 즉각적인 향상에 있습니다. 팔로어를 구매함으로써 기업은 Instagram에서의 인지도를 높이고 팔로어 수를 빠르게 늘릴 수 있습니다. 이 초기 부스트는 눈덩이 효과를 가져 시간이 지남에 따라 더 많은 진정한 팔로워를 끌어들일 수 있습니다. 또한, 팔로어 수가 많으면 신뢰성과 인기에 대한 인식을 형성하여 잠재 고객이 귀하의 브랜드에 참여하도록 유도할 수 있습니다. Instagram 팔로어를 구매하는 것이 간단한 해결책처럼 보일 수 있지만 기업은 신중하게 고려하여 접근해야 합니다. 구매하려는 팔로어가 진짜인지, 자동화된 봇이나 비활성 계정이 아닌지 확인하는 것이 중요합니다. Twicsy는 귀하의 콘텐츠에 진정한 관심을 갖고 있는 실제적이고 활동적인 팔로워를 제공하는 데 자부심을 갖고 있습니다. 이러한 구별은 게시물에 대한 참여와 상호 작용이 의미 있고 실제 전환으로 이어질 수 있음을 보장하므로 매우 중요합니다. 팔로어의 진위 여부 외에도 기업은 구매한 팔로어와 대상 고객의 관련성을 고려해야 합니다. Twicsy는 다양한 타겟팅 옵션을 제공하여 획득하려는 팔로어의 인구 통계, 관심사 및 위치를 지정할 수 있습니다. 이러한 수준의 맞춤화를 통해 팔로어 기반이 비즈니스 목표에 부합하도록 보장하여 충성 고객으로 전환할 가능성을 높입니다. 기업은 Instagram 팔로어 구매 옵션을 고려할 때 이를 광범위한 소셜 미디어 접근 방식에 대한 보완 전략으로 보아야 합니다. 계속해서 고품질 콘텐츠를 제작하고, 청중과 소통하고, 구매한 팔로어와 함께 기타 유기적 성장 전략을 활용하는 것이 중요합니다. Twicsy에서 얻은 팔로어는 전반적인 소셜 미디어 존재에 대한 촉매제 역할을 하여 가시성을 높이고 유기적 성장을 촉진해야 합니다. 일부 비평가들은 인스타그램 팔로어를 구매하는 것은 성공에 대한 인위적인 인식을 조성할 수 있기 때문에 비윤리적인 관행으로 보일 수 있다고 주장합니다. 그러나 모든 마케팅 전략의 목표는 브랜드에 대한 긍정적인 이미지를 만드는 것임을 기억하는 것이 중요합니다. 팔로어 구매는 청중을 속이는 방법이 아니라 소셜 미디어 존재를 활성화하기 위한 도구로 간주되어야 합니다. Twicsy에서 구매한 팔로어와 진정한 참여 및 가치 있는 콘텐츠를 결합함으로써 기업은 Instagram에서 진정성 있고 번성하는 커뮤니티를 구축할 수 있습니다. 요약하자면, Twicsy에서 Instagram 팔로어를 구매하는 것은 모든 비즈니스의 소셜 미디어 전략에 귀중한 추가가 될 수 있습니다. 이 서비스를 활용하면 기업은 팔로어 수를 빠르게 늘리고 Instagram에서 도달 범위와 가시성을 높일 수 있습니다. 진정한 팔로워 제공에 대한 Twicsy의 강조는 참여와 상호 작용이 의미 있고 궁극적으로 전환을 유도하도록 보장합니다. 그러나 포괄적인 소셜 미디어 접근 방식의 일부로 팔로어 구매에 접근하고 이를 고품질 콘텐츠 및 진정한 참여와 결합하는 것이 중요합니다. 올바른 사고방식과 전략을 갖춘 기업은 Twicsy를 사용하여 Instagram에서 성장을 가속화하고 플랫폼의 잠재력을 최대한 활용할 수 있습니다. 선도적인 온라인 공급업체인 Twicsy의 팔로어 증가를 통해 한국 기반 비즈니스를 글로벌 시장에서 새로운 차원으로 끌어올리세요. Instagram 존재의 모든 영역을 포괄하는 패키지를 통해 대부분의 고객이 다시 찾는 영역은 팔로어 수입니다. 이것이 바로 Twicsy가 연결하는 모든 프로필이 진짜인지 확인하는 데 중점을 두는 이유입니다. 특정 예산이나 KPI에 맞는 패키지를 구매하거나 저렴한 단일 거래를 통해 더 광범위한 잠재 고객 풀에 접근할 수 있는 이점을 누릴 수 있습니다. tags : #twicsy, #followers, #instagramfollowers, #buyfollowers, #buyinstagramfollowers, #instagram Address : District C1 Building, Office 209, World Trade Center, Dubai, UAE Hotline : +1 855-848-9812 Website : https://twicsy.com/ko/buy-instagram-followers Google Sites : https://sites.google.com/view/twicsykobuyinstagramfollowers Social : https://profile.hatena.ne.jp/twicsykobuyinstagramfollowers/ https://www.imdb.com/user/ur180302345/ https://www.furaffinity.net/...uyinstagramfollowers https://theotherboard.com/...yinstagramfollowers/
    Youtube Channel link
    https://www.youtube.com/@twicsykobuyinstagramfollowers/about
    i
    twicsykobuyinstagramfollowers, 50
  • Username
    google_user_8786
    i
    google_user_8786
  • Username
    google_user_8785
    i
    google_user_8785
  • Username
    google_user_8784
    i
    google_user_8784
  • Username
    google_user_8783
    i
    google_user_8783
Show users:
Packers and Movers Bangalore - Best movers and pac...
0.00 USD
It
may be essential in handling drug possession c...
500.00 USD
All
of these tests are subjective; rely on proper...
0.00 USD
View all

Birthdays

Latest tasks

No jobs or tasks posted
  • Recent talks between Casino.org and a Pennsylvania Gamblers Anonymous representative have revealed an increase in gambling addiction, with unregulated skill games being named as the principal cause of these new cases. During the discussion, a Gamblers Anonymous spokesperson shared that many new members cite skill games as what pushed them into gambling addiction. “PA skill […]
    34 minutes ago
  • Whether live dealers are some of the best-paid gambling professionals remains open to debate, but the fact is that the Cordish Companies now need a lot of them, as the $600-million property is due to open while a temporary casino is already up and running. The full-scale launch will see more than 1,600 slots, 65 […]
    45 minutes ago
  • Emmanuel Clase’s alleged pitch manipulation for betting purposes may prove to be far more extensive than it was initially reported.  According to a recent court filing highlighted by ESPN’s David Purdum, the three-time All-Star and two-time American League Reliever of the Year threw over 250 suspicious pitches across at least 48 games from 2023 to […]
    2 hours ago
  • A bettor in Las Vegas engineered a situation that allowed him to come away with a large profit from Super Bowl 60, no matter which team would have come out with flying colors on Sunday. Covering All Risks The gambler placed big preseason wagers on the Seattle Seahawks and then hedged with bets on the […]
    2 hours ago
  • Prediction markets are surging in popularity, with Kalshi, Polymarket, and Crypto.com seeming determined to remain in the United States while expanding their sports event contracts. Legal pushbacks in Nevada and elsewhere have not been enough to depress consumer interest, nor, it appears, investment from popular sports figures. The latest to join Kalshi as an investor […]
    4 hours ago
  • Rigoberto Mendez Morales is now facing charges of second-degree murder in North Dakota after he was arrested last month for allegedly killing a woman in a hotel room at a popular tribal casino destination in the state. Suspected Perpetrator Says He Has No Recollection of Events The heinous act took place in a hotel room […]
    4 hours ago
  • A newcomer to the sports betting scene has jumped into the limelight right before the year’s biggest game. Kalshi, a small-time player next to big-name sportsbooks, saw a big jump in people downloading its mobile app in January. It was ahead of well-known brands like DraftKings and FanDuel as the Super Bowl got closer. Kalshi […]
    7 hours ago
  • The group that runs Powerball is asking a Los Angeles judge to take it off a big lawsuit. A woman sued, saying she should have won a $1.08 billion jackpot from a 2023 draw. However, someone else already got the prize. Powerball Operator Says No Contract Exists in $1B Jackpot Dispute The Multi-State Lottery Association […]
    7 hours ago
  • Yet another lucky player from Michigan has won big, this time from the Michigan Lottery’s Lucky For Life game. This comes in the wake of several seven-figure sum wins in the Great Lakes State. The Winner Took Home $390K According to the Michigan Lottery’s announcement, David Holfelder, a 78-year-old man from Eastpointe, Macomb County, won […]
    Feb 6, 11:28
  • Global casino and hospitality giant MGM Resorts International has published its financial results for Q4 2025 and FY 2025, highlighting the continued strength of its portfolio. With the Osaka resort being built, MGM is even more optimistic about what the future might hold. Q4 Was a Strong Quarter Despite the Vegas Setbacks In its release, […]
    Feb 6, 11:00

Forum Topics

google_user_10694
RCS, or rich communication services, is an... More
google_user_10689
Bulk SMS in India is a powerful tool for... More
google_user_10687
Find the perfect Meeting room for Rent in... More
google_user_10687 Feb 4, 22:56
google_user_10681
The significance of a CIPD certification cannot... More
google_user_10676
The Hainan Airlines Sales Office Bangkokcaters... More
google_user_10543
Muy buenas, ¿cómo estamos? En Lugo un conocido... More
google_user_10543 Jan 26, 18:37
Sponsors

User ADS

Advertisement

Sponsors
Google this