From eee619a7434a289a3b8bb10c973c362effccc866 Mon Sep 17 00:00:00 2001 From: MinSoo Kim Date: Sat, 23 Jan 2016 15:44:52 +0900 Subject: [PATCH] Reduce JSON request of POLL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 처음 설문조사 화면을 열 때는 JSON 요청을 하지 않고 바로 결과를 표시합니다. --- .../poll_maker/poll_maker.class.php | 7 ++- modules/poll/poll.model.php | 48 ++++++++++++------- widgets/pollWidget/pollWidget.class.php | 7 +++ .../pollWidget/skins/default/pollview.html | 17 +++---- widgets/pollWidget/skins/simple/pollview.html | 17 +++---- 5 files changed, 61 insertions(+), 35 deletions(-) diff --git a/modules/editor/components/poll_maker/poll_maker.class.php b/modules/editor/components/poll_maker/poll_maker.class.php index 46213c501..f86f60cc4 100644 --- a/modules/editor/components/poll_maker/poll_maker.class.php +++ b/modules/editor/components/poll_maker/poll_maker.class.php @@ -47,7 +47,7 @@ class poll_maker extends EditorHandler { $args = new stdClass(); - $args->poll_srl = $xml_obj->attrs->poll_srl; + $args->poll_srl = intval($xml_obj->attrs->poll_srl); $skin = $xml_obj->attrs->skin; if(!$skin) $skin = 'default'; $args->skin = $skin; @@ -61,6 +61,11 @@ class poll_maker extends EditorHandler $tpl_path = sprintf('%sskins/%s', _XE_PATH_ . 'widgets/pollWidget/', $args->skin); $tpl_file = 'pollview'; + // Get the information related to the survey + $oPollModel = getModel('poll'); + $poll_data = $oPollModel->_getPollinfo($args->poll_srl); + + Context::set('poll_data', $poll_data); Context::set('colorset', $args->colorset); Context::set('poll_srl', $args->poll_srl); Context::set('style', $args->style); diff --git a/modules/poll/poll.model.php b/modules/poll/poll.model.php index ee0ff4ab7..7c42be029 100644 --- a/modules/poll/poll.model.php +++ b/modules/poll/poll.model.php @@ -10,22 +10,21 @@ class pollModel extends poll /** * @brief Initialization */ - function init() + public function init() { } /** * @brief returns poll infomation */ - function getPollinfo() + public function _getPollinfo($poll_srl) { $args = new stdClass; - $poll_srl = Context::get('poll_srl'); + $args->poll_srl = intval($poll_srl); $logged_info = Context::get('logged_info'); - if(!$poll_srl || $poll_srl=='') return new Object(-1,"poll_no_poll_srl"); + if(!$args->poll_srl || $args->poll_srl === 0) return new Object(-1,"poll_no_poll_srl"); - $args->poll_srl = $poll_srl; // Get the information related to the survey $columnList = array('poll_count', 'stop_date','poll_type','member_srl'); $output = executeQuery('poll.getPoll', $args, $columnList); @@ -33,8 +32,11 @@ class pollModel extends poll if(!$output->data) return new Object(-1,"poll_no_poll_or_deleted_poll"); $poll = new stdClass; + + // if a person can vote is_polled=0, else 1 $poll->is_polled = 0; if($output->data->stop_date < date("Ymd")) $poll->is_polled = 1; + elseif($this->isPolled($poll_srl)) $poll->is_polled = 1; $poll->poll_count = (int)$output->data->poll_count; $poll->poll_type = (int)$output->data->poll_type; @@ -64,20 +66,31 @@ class pollModel extends poll } + $output = new stdClass; + $poll->poll_srl = $poll_srl; - $caniadditem = $this->isAbletoAddItem($poll->poll_type) && !!$logged_info->member_srl; + $output->caniadditem = $this->isAbletoAddItem($poll->poll_type) && !!$logged_info->member_srl; - $oPollModel = getModel('poll'); - if($oPollModel->isPolled($poll_srl)) $poll->is_polled = 1; + $output->poll = $poll; - $this->add('poll', $poll); - $this->add('caniadditem', $caniadditem); + return $output; + } + + /** + * @brief returns poll infomation + */ + public function getPollinfo() + { + $output = $this->_getPollinfo(Context::get('poll_srl')); + + $this->add('poll', $output->poll); + $this->add('caniadditem', $output->caniadditem); } /** * @brief returns poll item infomation */ - function getPollitemInfo() + public function getPollitemInfo() { $args = new stdClass; $poll_srl = Context::get('poll_srl'); @@ -160,13 +173,12 @@ class pollModel extends poll * @brief returns poll status * @see this function uses isPolled function below */ - function getPollstatus() + public function getPollstatus() { $poll_srl = Context::get('poll_srl'); if(!$poll_srl || $poll_srl=='') return new Object(-1,"poll_no_poll_srl"); - $oPollModel = getModel('poll'); - if($oPollModel->isPolled($poll_srl)) $is_polled = 1; + if($this->isPolled($poll_srl)) $is_polled = 1; else $is_polled = 0; $this->add('is_polled', $is_polled); @@ -175,7 +187,7 @@ class pollModel extends poll /** * @brief The function examines if the user has already been polled */ - function isPolled($poll_srl) + public function isPolled($poll_srl) { $args = new stdClass; $args->poll_srl = $poll_srl; @@ -199,7 +211,7 @@ class pollModel extends poll * Return the result after checking if the poll has responses * @deprecated this function uses poll skin, which will be removed */ - function getPollHtml($poll_srl, $style = '', $skin = 'default') + public function getPollHtml($poll_srl, $style = '', $skin = 'default') { $args = new stdClass; $args->poll_srl = $poll_srl; @@ -258,7 +270,7 @@ class pollModel extends poll * @brief Return the result's HTML * @deprecated this function uses poll skin, which will be removed */ - function getPollResultHtml($poll_srl, $skin = 'default') + public function getPollResultHtml($poll_srl, $skin = 'default') { $args = new stdClass; $args->poll_srl = $poll_srl; @@ -306,7 +318,7 @@ class pollModel extends poll * @brief Selected poll - return the colorset of the skin * @deprecated this function uses poll skin, which will be removed */ - function getPollGetColorsetList() + public function getPollGetColorsetList() { $skin = Context::get('skin'); diff --git a/widgets/pollWidget/pollWidget.class.php b/widgets/pollWidget/pollWidget.class.php index 1afc8d5a3..de3ed3499 100644 --- a/widgets/pollWidget/pollWidget.class.php +++ b/widgets/pollWidget/pollWidget.class.php @@ -16,10 +16,17 @@ class pollWidget extends WidgetHandler */ function proc($args) { + $args->poll_srl = intval($args->poll_srl); + + // Get the information related to the survey + $oPollModel = getModel('poll'); + $poll_data = $oPollModel->_getPollinfo($args->poll_srl); + // Set a path of the template skin (values of skin, colorset settings) $tpl_path = sprintf('%sskins/%s', $this->widget_path, $args->skin); $tpl_file = 'pollview'; + Context::set('poll_data', $poll_data); Context::set('colorset', $args->colorset); Context::set('poll_srl', $args->poll_srl); Context::set('style', $args->style); diff --git a/widgets/pollWidget/skins/default/pollview.html b/widgets/pollWidget/skins/default/pollview.html index 91030848f..20909baa3 100644 --- a/widgets/pollWidget/skins/default/pollview.html +++ b/widgets/pollWidget/skins/default/pollview.html @@ -3,24 +3,25 @@ var poll_alert_lang = "{$lang->msg_check_poll_item}"; var poll_checkcount_lang = "{$lang->poll_checkcount}"; var poll_member_lang = "{$lang->poll_item_members}"; - jQuery.exec_json("poll.getPollinfo", {/**/"poll_srl":{$poll_srl}/**/}, function(data){/**/ + jQuery(document).ready(function(){ + var data = {json_encode($poll_data)}; if(data.poll.is_polled==0) loadPoll({$poll_srl},data); else { loadPollResult({$poll_srl},data); - jQuery("#poll_{$poll_srl}_result_button").css({/**/ + jQuery("#poll_{$poll_srl}_result_button").css({ display: "none" - /**/}); + }); - jQuery("#poll_{$poll_srl}_result_nobutton").css({/**/ + jQuery("#poll_{$poll_srl}_result_nobutton").css({ display: "table-row" - /**/}); + }); - jQuery("#poll_{$poll_srl}_result_yesbutton").css({/**/ + jQuery("#poll_{$poll_srl}_result_yesbutton").css({ display: "none" - /**/}); + }); } - /**/}); + });