diff --git a/uVote/api/votes/votes.php b/uVote/api/votes/votes.php index 7c8f460..d206d82 100644 --- a/uVote/api/votes/votes.php +++ b/uVote/api/votes/votes.php @@ -4,8 +4,9 @@ class votes { public static function getAllVotesOfGroup($groupid){ return \DBD\UVOTE_GENERATE_VOTELIST::QA(array($groupid));} - public static function countAllPolls($group){ - return \DBD\UVOTE_DATA_COUNT_VOTES::Q1();} + public static function countAllPolls(){ + $res = \DBD\UVOTE_DATA_COUNT_VOTES::QQ(); + return $res;} public static function insertPartyChoice($poll_ID, $party, $votes_pro, $votes_contra, $nr_attending, $total, $choice){ return \DBD\UVOTE_GENERATE_VOTELIST::QI(array($poll_ID, $party, $votes_pro, $votes_contra, $nr_attending, $total, $choice));} @@ -71,16 +72,40 @@ class votes { return $res; } + public static function get_all_votes_bt(){ + $res = \DBD\UVOTE_DATA_CHOICE_BT_OVERALL::QA(); + return $res; + } + + public static function get_user_temp_votes($user_ID){ + return \DBD\UVOTE_DATA_TEMP_VOTES::Q1(array($user_ID, $user_ID, $user_ID));} + public static function get_bar_bt_per_poll($poll_ID){ return \DBD\UVOTE_DATA_BT_PER_POLL::Q1(array($poll_ID));} + public static function get_user_count(){ + return \DBD\UVOTE_DATA_USER_COUNT_USERS::Q1(array());} + + public static function get_count_user_votes_per_poll($poll_ID){ + return \DBD\UVOTE_DATA_USER_COUNT_CHOICE_PER_POLL::Q1(array($poll_ID));} + public static function get_user_per_party_overall($user_ID){ return \DBD\UVOTE_DATA_USER_PER_PARTY_OVERALL::QA(array($user_ID)); } public static function get_user_to_bt_overall($user_ID){ return \DBD\UVOTE_DATA_USER_TO_BT::QA(array($user_ID)); } + + public static function get_uvote_to_bt_overall(){ + return \DBD\UVOTE_DATA_UVOTE_TO_PARTY_OVERALL::QA(array()); + } + public static function get_users_choice_per_poll($poll_ID){ + return \DBD\UVOTE_DATA_USERS_CHOICE_PER_POLL::QA(array($poll_ID));} + + public static function get_pfields_per_poll($poll_ID){ + return \DBD\UVOTE_DATA_USERS_CHOICE_PER_POLL::QA(array($poll_ID));} + public static function get_voteinfo($poll_ID){ $con = new \SYSTEM\DB\Connection(new \DBD\uVote()); $res = $con->prepare( 'selVoteByID', @@ -92,6 +117,11 @@ class votes { public static function get_barsperparty($poll_ID){ return \DBD\UVOTE_DATA_PARTY_PER_POLL::QA(array($poll_ID));} + + public static function get_party_choice($poll_ID, $party){ + $res = \DBD\UVOTE_DATA_PARTY_CHOICE_PER_POLL::Q1(array($poll_ID, $party)); + return $res; + } public static function write_vote($poll_ID, $vote){ if(!\SYSTEM\SECURITY\Security::isLoggedIn()){ diff --git a/uVote/dbd/qq/UVOTE_DATA_PFIELDS_PER_POLL.php b/uVote/dbd/qq/UVOTE_DATA_PFIELDS_PER_POLL.php new file mode 100644 index 0000000..e4acac7 --- /dev/null +++ b/uVote/dbd/qq/UVOTE_DATA_PFIELDS_PER_POLL.php @@ -0,0 +1,11 @@ +poll_ID); - $pbpp = ""; + $result = ""; foreach($partyvotes as $vote){ $vote['party_yes'] = round($vote['votes_pro']/$vote['total']*100,0); $vote['party_no'] = round($vote['votes_contra']/$vote['total']*100,0); $vote['party_ent'] = round(($vote['nr_attending'] - $vote['votes_pro'] - $vote['votes_contra'])/$vote['total']*100,0); - $pbpp .= SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_bulletin/table_parties.tpl'), $vote); + $result .= SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_bulletin/table_parties.tpl'), $vote); } - return $pbpp; + return $result; } private function bars_bt(){ @@ -38,8 +38,26 @@ class default_bulletin extends SYSTEM\PAGE\Page { return SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_bulletin/table_bt.tpl'), $vars); } - private function vote_buttons($poll_expired){ - $user_poll = votes::getUserPollData($this->poll_ID); + private function voice_weight(){ + $vars = votes::get_count_user_votes_per_poll($this->poll_ID); + $vars['voteweight'] = 1/$vars['count']*100; + return SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_bulletin/voteweight.tpl'), $vars); + } + + private function p_fields (){ + $result = ""; + + $list = array (array(1, 'Aussenpolitik'), + array(2, 'Aussenpolitik'), + array(4, 'Aussenpolitik'), + array(8, 'Aussenpolitik')); + foreach($list as $l){ + if($p_fields & $l[0]) $result .= $l[1]; + } + return $result; + } + + private function vote_buttons($poll_expired,$user_poll){ if($poll_expired){ if(!$user_poll){ return '

Stimme hier ab

@@ -92,20 +110,25 @@ class default_bulletin extends SYSTEM\PAGE\Page { public function html(){ $poll_expired = \DBD\UVOTE_POLL_EXPIRED::Q1(array($this->poll_ID)); + $user_vote = votes::getUserPollData($this->poll_ID); - /*$poll_data = array(); - $poll_data[] = DBD\UVOTE_DATA_CHOICE_OVERALL::Q1(array(1)); - $poll_data[] = DBD\UVOTE_DATA_CHOICE_OVERALL::Q1(array(2)); - $poll_data[] = DBD\UVOTE_DATA_CHOICE_OVERALL::Q1(array(3));*/ $vars = array(); - $vars['bars_party'] = $poll_expired ? '' : $this->bars_party(); - $vars['bars_user'] = $this->bars_user(); - $vars['bars_bt'] = $this->bars_bt(); + $vars['bars_party'] = $vars['bars_user'] = $vars['bars_bt'] = $vars['voice_weight'] = 'Vote to see results!'; $vars['js'] = $this->js(); $vars['css'] = $this->css(); - $vars['frontend_logos'] = \SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_PATH_BASEURL).'api.php?call=img&cat=frontend_logos&id='; - $vars ['vote_buttons'] = $this->vote_buttons($poll_expired); - $vars['poll_ID'] = $this->poll_ID; + + $vars['vote_buttons'] = $this->vote_buttons($poll_expired,$user_vote); +// $vars['p_fields'] = $this->p_fields(); + if($user_vote){ + $vars['bars_party'] = $poll_expired ? '' : $this->bars_party(); + $vars['bars_user'] = $this->bars_user(); + $vars['bars_bt'] = $this->bars_bt(); + $vars['voice_weight'] = $this->voice_weight(); + } + + $vars['poll_ID'] = $this->poll_ID; //put it here - so its filled in! + $vars['frontend_logos'] = \SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_PATH_BASEURL).'api.php?call=img&cat=frontend_logos&id='; + $vars = array_merge($vars,votes::get_voteinfo($this->poll_ID)); return SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_bulletin/bulletin.tpl'),$vars); } diff --git a/uVote/page/default_page/css/default_page.css b/uVote/page/default_page/css/default_page.css index 020b979..b73b977 100644 --- a/uVote/page/default_page/css/default_page.css +++ b/uVote/page/default_page/css/default_page.css @@ -11,10 +11,11 @@ body { background: #5eb95e; } -.contra{ +.con{ background: #ee5f5b; } .ent{ background: lightgrey; } + diff --git a/uVote/page/default_page/default_page.php b/uVote/page/default_page/default_page.php index d72ea37..3171a59 100644 --- a/uVote/page/default_page/default_page.php +++ b/uVote/page/default_page/default_page.php @@ -14,42 +14,98 @@ class default_page extends SYSTEM\PAGE\Page { } private function css(){ - return '';} - - + return '';} + + private function get_party_per_poll($choice){ + switch($choice){ + case 1: + return 'PRO'; + case 2: + return 'CON'; + case 3: + return 'ENT'; + default: + return 'NONE'; + } + } + private static function tablerow_class($choice){ switch($choice){ case 1: return 'pro'; case 2: - return 'contra'; + return 'con'; case 3: return 'ent'; default: - return ''; + return 'open'; } } - public function generate_votelist(){ - + + private static function badge_class($choice){ + switch($choice){ + case 1: + return 'badge-success'; + case 2: + return 'badge-important'; + case 3: + return 'badge-info'; + default: + return ''; + } + } + + public function generate_votelist(){ $result = array('',''); $votes = votes::getAllVotesOfGroup(1); foreach($votes as $vote){ $time_remain = strtotime($vote['time_end'])- microtime(true); $time_span = strtotime($vote['time_end']) - strtotime($vote['time_start']); - $vote['vote_class'] = $this->tablerow_class(votes::getUserPollData($vote['ID'])); - $vote['bt_vote_class'] = $this->tablerow_class($vote['bt_choice']); - $vote['full_vote_btn'] = $time_remain > 0 ? 'Abstimmen' : 'Ansehen'; + $vote_count = votes::get_count_user_votes_per_poll($vote['ID']); + + $vote['title'] = utf8_encode($vote['title']); $vote['time_left'] = round($time_remain/($time_span+1)*100,0); $vote['time_done'] = 100-$vote['time_left']; - if($time_remain > 0){ + + $vote['full_vote_btn'] = $time_remain > 0 ? 'Abstimmen' : 'Ansehen'; + $vote['uv'] = $vote['bt'] = ''; + $vote['uv_count'] = $vote_count['count'] > 4 ? $vote_count['count'] : '< 5'; + + $user_vote = votes::getUserPollData($vote['ID']); + $vote['vote_class'] = $this->tablerow_class($user_vote); + if($user_vote){ + //user vote + $vote['vote_class'] = $this->tablerow_class($user_vote); + + //bt vote + $party_votes = votes::get_barsperparty($vote['ID']); + $vote['bt_vote_class'] = $this->tablerow_class($vote['bt_choice']); + foreach($party_votes as $pv){ + $vote['bt'] .= \SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_page/vote_bt.tpl'), + array( 'party' => $pv['party'], + 'choice' => $this->get_party_per_poll($pv['choice']), + 'choice_class' => $this->tablerow_class($pv['choice']))); + } + + //uvote vote + $uvote = votes::get_users_choice_per_poll($vote['ID']); + $vote['uv_vote_class'] = count($uvote) > 0 ? $this->tablerow_class($uvote[0]['choice']) : ''; + foreach($uvote as $v){ + $vote['uv'] .= \SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_page/vote_uv.tpl'), + array( 'badge' => self::badge_class($v['choice']), + 'perc' => $v['count'] > 0 ? $v['count']/$vote_count['count']*100 : 0)); + } + } + + if($time_remain > 0){ $result[0] .= SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_page/vote.tpl'), $vote); } else { $result[1] .= SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_page/vote.tpl'), $vote); } } return $result[0].$result[1]; - } - + } + public function get_coverpage(){ return SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_page/cover.tpl'), array());} @@ -68,11 +124,11 @@ class default_page extends SYSTEM\PAGE\Page { public function html(){ $vars = array(); $vars['js'] = $this->js(); - $vars['css'] = $this->css(); - $vars['votelist'] = \SYSTEM\SECURITY\Security::isLoggedIn() ? $this->generate_votelist() : $this->get_coverpage() ; + $vars['css'] = $this->css(); + $vars['votelist'] = $this->generate_votelist(); $vars['registerform'] = \SYSTEM\SECURITY\Security::isLoggedIn() ? $this->getloggedinform() : $this->exchange_registerform(); $vars['loginform'] = \SYSTEM\SECURITY\Security::isLoggedIn() ? $this->exchange_loginform() : $this->getloginform() ; - $vars['frontend_logos'] = \SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_PATH_BASEURL).'api.php?call=img&cat=frontend_logos&id='; + $vars['frontend_logos'] = \SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_PATH_BASEURL).'api.php?call=img&cat=frontend_logos&id='; $vars = array_merge($vars, \SYSTEM\locale::getStrings(DBD\locale_string::VALUE_CATEGORY_MAINPAGE)); $vars = array_merge($vars, \SYSTEM\locale::getStrings(150)); diff --git a/uVote/page/default_page/page.tpl b/uVote/page/default_page/page.tpl index 4daa1b9..2ad03a6 100644 --- a/uVote/page/default_page/page.tpl +++ b/uVote/page/default_page/page.tpl @@ -20,7 +20,7 @@ - +