

SRINAGAR & NEW DELHI, February 9 (IPS) - When the rain begins in Kashmir’s capital Srinagar, Ghulam Nabi Bhat does not watch the clouds with relief anymore. He watches them with calculation. How much can the gutters take? How fast will the river rise? Which corner of the house will leak first? Where should the children sleep if the floor turns damp?
Read the full story, “‘When Rains Come, Our Hearts Beat Faster’”, on globalissues.org →

Far from global newsrooms and editorial boardrooms, a radically different model of journalism has been taking shape for over two decades in rural India.

The UN Secretary-General has strongly condemned the surge in violence across South Sudan, warning that civilians and aid workers are paying a devastating price as humanitarian operations are increasingly targeted.

While new digital technologies are transforming how the Holocaust is remembered and taught, experts warn that sustainability, ethics and collaboration are now as important as creativity to keep a global memory alive of Nazi Germany’s genocide that killed six million Jewish people and millions of others during the Second World War.

URBANA, Illinois, US, February 6 (IPS) - South Africa, Mozambique, and Zimbabwe are currently experiencing severe flooding. According to the World Health Organization, 1.3 million people have been affected. In addition, hundreds of people have died , infrastructure has been destroyed, access to health services has been disrupted, and the risks of water- and mosquito-borne diseases are rising.
"; 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' => '