From 8059716e46c78f84552816489575c5105deb89f4 Mon Sep 17 00:00:00 2001 From: Nael Date: Wed, 12 Feb 2014 22:39:27 +0100 Subject: [PATCH] multiple api functionality for statistics on fronted various style changes for buttons and bars (still bootstrap though) vote functionality restored switched list and main frame positions and reversed floats (looks same as before!) --- uVote/api/votes/votes.php | 22 +++--- uVote/dbd/qq/UVOTE_DATA_BT_PER_POLL.php | 16 ++++ uVote/dbd/qq/UVOTE_DATA_CHOICE_OVERALL.php | 11 +++ uVote/dbd/qq/UVOTE_POLL_EXPIRED.php | 11 +++ uVote/page/default_bulletin/bars_user.tpl | 6 ++ uVote/page/default_bulletin/bulletin.tpl | 35 ++++----- .../default_bulletin/default_bulletin.php | 73 +++++++++++++++++-- uVote/page/default_bulletin/table_bt.tpl | 8 ++ uVote/page/default_bulletin/table_parties.tpl | 8 ++ uVote/page/default_cover/cover.tpl | 2 +- uVote/page/default_page/css/default_page.css | 8 +- uVote/page/default_page/default_page.php | 29 ++++---- uVote/page/default_page/full_vote.tpl | 14 +--- uVote/page/default_page/loggedinformtop.tpl | 2 +- uVote/page/default_page/page.html | 14 ++-- uVote/page/default_page/vote.tpl | 14 ++-- .../page/user_main_uVote/user_main_uVote.php | 23 +++++- 17 files changed, 213 insertions(+), 83 deletions(-) create mode 100644 uVote/dbd/qq/UVOTE_DATA_BT_PER_POLL.php create mode 100644 uVote/dbd/qq/UVOTE_DATA_CHOICE_OVERALL.php create mode 100644 uVote/dbd/qq/UVOTE_POLL_EXPIRED.php create mode 100644 uVote/page/default_bulletin/bars_user.tpl create mode 100644 uVote/page/default_bulletin/table_bt.tpl create mode 100644 uVote/page/default_bulletin/table_parties.tpl diff --git a/uVote/api/votes/votes.php b/uVote/api/votes/votes.php index fd63261..cf43f0b 100644 --- a/uVote/api/votes/votes.php +++ b/uVote/api/votes/votes.php @@ -34,13 +34,14 @@ class votes { $res = $res->next(); $result = array(); $result['poll_ID'] = $poll_ID; - $result['count'] = $res['count']; + $result['count'] = $res['count'] >= 1 ? $res['count'] : 1; //yes $res = $con->prepare( 'selVoteBy_count', 'SELECT COUNT(*) as "count" FROM `uvote_data` WHERE `poll_ID` = ? AND choice = 1;', array($poll_ID)); $res = $res->next(); $result['yes'] = $res['count']; + $result['yes_perc'] = $res['count'] / $result['count']; //no $res = $con->prepare( 'selVoteBy_count', @@ -60,6 +61,10 @@ class votes { return $return_as_json ? JsonResult::toString($result) : $result; } + 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_voteinfo($poll_ID){ $con = new \SYSTEM\DB\Connection(new \DBD\uVote()); $res = $con->prepare( 'selVoteByID', @@ -87,14 +92,14 @@ class votes { $con = new \SYSTEM\DB\Connection(new \DBD\uVote()); $res = $con->prepare( 'selVote', - 'SELECT * FROM `uvote_data` WHERE `poll_ID` = ? AND user_ID = ?;', - array($poll_ID, \SYSTEM\SECURITY\Security::getUser()->id)); + 'SELECT * FROM `uvote_votes` WHERE `ID` = ? AND time_end < CURDATE();', + array($poll_ID)); if ($res->next()){ - throw new ERROR('You already voted!');} + throw new ERROR('Your rights have expired!');} $res = $con->prepare( 'insertVote', - 'INSERT INTO uvote_data - VALUES (?, ?, ?);', + 'REPLACE uvote_data + VALUES (?, ?, ?, 0);', array($poll_ID, \SYSTEM\SECURITY\Security::getUser()->id, $vote)); return JsonResult::ok(); } @@ -115,9 +120,8 @@ class votes { public static function open_vote($poll_ID){ $vote = votes::getVoteOfGroup($poll_ID); - new INFO(print_r($vote, true)); - $vars = array('vote_text' => $vote['text'], 'vote_title' => $vote['title'], 'vote_init' => $vote['initiative'], 'poll_ID' => $vote['ID'], 'time_end' => $vote['time_end']); - $result = SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_page/full_vote.tpl'), $vars); +// $vars = array('vote_text' => $vote['text'], 'vote_title' => $vote['title'], 'vote_init' => $vote['initiative'], 'poll_ID' => $vote['ID'], 'time_end' => $vote['time_end']); + $result = SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_page/full_vote.tpl'), $vote); return $result; } } diff --git a/uVote/dbd/qq/UVOTE_DATA_BT_PER_POLL.php b/uVote/dbd/qq/UVOTE_DATA_BT_PER_POLL.php new file mode 100644 index 0000000..b2af6f8 --- /dev/null +++ b/uVote/dbd/qq/UVOTE_DATA_BT_PER_POLL.php @@ -0,0 +1,16 @@ + CURDATE();' +);}} \ No newline at end of file diff --git a/uVote/page/default_bulletin/bars_user.tpl b/uVote/page/default_bulletin/bars_user.tpl new file mode 100644 index 0000000..09ee604 --- /dev/null +++ b/uVote/page/default_bulletin/bars_user.tpl @@ -0,0 +1,6 @@ +

${title}

+
+
Yes
+
No
+
Ent
+
\ No newline at end of file diff --git a/uVote/page/default_bulletin/bulletin.tpl b/uVote/page/default_bulletin/bulletin.tpl index 259aec2..12d1d51 100644 --- a/uVote/page/default_bulletin/bulletin.tpl +++ b/uVote/page/default_bulletin/bulletin.tpl @@ -3,22 +3,19 @@
-
Auf einen Blick
- ${vote_quick} -
- Pro - Contra - Enthaltung -
\ No newline at end of file + ${vote_buttons} + +
+ +
+ ${bars_user} +
+ +
+

Ergebnis der Fraktionen

+ ${bars_party} +
+
+
+ ${bars_bt} +
\ No newline at end of file diff --git a/uVote/page/default_bulletin/default_bulletin.php b/uVote/page/default_bulletin/default_bulletin.php index ac72a09..4dc0852 100644 --- a/uVote/page/default_bulletin/default_bulletin.php +++ b/uVote/page/default_bulletin/default_bulletin.php @@ -6,16 +6,77 @@ class default_bulletin extends SYSTEM\PAGE\Page { } -private function js(){ - return ''; -} - + + + private function bars_user(){ + $bars = votes::get_barsperusers($this->poll_ID,false); + $bars['vote_yes_perc'] = round($bars['yes_perc']*100,0); + $bars['vote_no_perc'] = round($bars['no_perc']*100,0); + $bars['vote_ent_perc'] = round($bars['ent_perc']*100,0); + $bars['title'] = 'Gemessen auf uVote'; + return SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_bulletin/bars_user.tpl'),$bars); + } + + private function bars_party(){ + $partyvotes = votes::get_barsperparty($this->poll_ID); + + $pbpp = ""; + 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); + } + + return $pbpp; + } + + private function bars_bt(){ + $vars = votes::get_bar_bt_per_poll($this->poll_ID); + if (!$vars['bt_total']){ + return 'no data yet';} + $vars['bt_ent'] = round(($vars['bt_attending'] - $vars['bt_pro'] - $vars['bt_con'])/$vars['bt_total']*100,0); + $vars['bt_pro'] = round($vars['bt_pro']/$vars['bt_total']*100,0); + $vars['bt_con'] = round($vars['bt_con']/$vars['bt_total']*100,0); + return SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_bulletin/table_bt.tpl'), $vars); + } + + private function js(){ + return '';} + private function css(){ + return '';} public function html(){ - - $vars['poll_ID'] = $this->poll_ID; + $poll_expired = DBD\UVOTE_POLL_EXPIRED::Q1(array($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'] = $this->bars_party(); + $vars['bars_user'] = $poll_expired ? '' : $this->bars_user(); + $vars['bars_bt'] = $this->bars_bt(); $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'] = $poll_expired ? + '

Stimme hier ab

+ Pro + Contra + Enthaltung' : + print_r($poll_data,TRUE); + $vars['poll_ID'] = $this->poll_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_bulletin/table_bt.tpl b/uVote/page/default_bulletin/table_bt.tpl new file mode 100644 index 0000000..9ac6950 --- /dev/null +++ b/uVote/page/default_bulletin/table_bt.tpl @@ -0,0 +1,8 @@ +
+

Ergebnis Bundestag

+
+
+
+

+
+
\ No newline at end of file diff --git a/uVote/page/default_bulletin/table_parties.tpl b/uVote/page/default_bulletin/table_parties.tpl new file mode 100644 index 0000000..d42008c --- /dev/null +++ b/uVote/page/default_bulletin/table_parties.tpl @@ -0,0 +1,8 @@ +
+${party} +
+
+
+

+
+
\ No newline at end of file diff --git a/uVote/page/default_cover/cover.tpl b/uVote/page/default_cover/cover.tpl index bced509..4be7ec8 100644 --- a/uVote/page/default_cover/cover.tpl +++ b/uVote/page/default_cover/cover.tpl @@ -1,6 +1,6 @@
-
+
diff --git a/uVote/page/default_page/css/default_page.css b/uVote/page/default_page/css/default_page.css index 04204ab..020b979 100644 --- a/uVote/page/default_page/css/default_page.css +++ b/uVote/page/default_page/css/default_page.css @@ -8,13 +8,13 @@ body { }*/ .pro{ - background: url(http://mojotrollz.eu/web/uVote/api.php?call=img&cat=frontend_logos&id=pro.png); + background: #5eb95e; } .contra{ - background: url(http://mojotrollz.eu/web/uVote/api.php?call=img&cat=frontend_logos&id=contra.png)no-repeat; + background: #ee5f5b; } .ent{ - background: url(http://mojotrollz.eu/web/uVote/api.php?call=img&cat=frontend_logos&id=enth.png)no-repeat; -} \ No newline at end of file + background: lightgrey; +} diff --git a/uVote/page/default_page/default_page.php b/uVote/page/default_page/default_page.php index 9e9b2df..0bed997 100644 --- a/uVote/page/default_page/default_page.php +++ b/uVote/page/default_page/default_page.php @@ -40,23 +40,26 @@ class default_page extends SYSTEM\PAGE\Page { 'vote_init' => $vote['initiative'], 'vote_class' => $this->tablerow_class(votes::getUserPollData($vote['ID'])), 'poll_ID' => $vote['ID'], - 'time_end' => $vote['time_end']); + 'time_end' => $vote['time_end'], + 'full_vote_btn' => (strtotime($vote['time_end'])- microtime(true)) > 0 ? 'Abstimmen' : 'Ansehen'); $result .= SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_page/vote.tpl'), $vars); } return $result; } - public function generate_vote(){ - $result = ""; - $votes = votes::getAllVotesOfGroup(1); - - foreach($votes as $vote){ - $vars = array('vote_title' => $vote['title'], 'vote_text' => $vote['text'], 'vote_init' => $vote['initiative'], 'poll_ID' => $vote['ID'], 'time_end' => $vote['time_end']); - $result .= SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_page/full_vote.tpl'), $vars); - } - return $result; - } - +// public function generate_vote(){ +// $result = ""; +// $votes = votes::getAllVotesOfGroup(1); +// +// foreach($votes as $vote){ +// new INFO (print_r($vote, TRUE)); +// $vars = array('vote_title' => $vote['title'], 'vote_text' => $vote['text'], 'vote_init' => $vote['initiative'], 'poll_ID' => $vote['ID'], 'time_end' => $vote['time_end'], 'iframe_link' => $vote['iframe_link']); +// $result .= SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_page/full_vote.tpl'), $vars); +// +// } +// return $result; +// } + public function get_coverpage(){ return SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_cover/cover.tpl'), array());} @@ -78,7 +81,7 @@ class default_page extends SYSTEM\PAGE\Page { $vars['js'] = $this->js(); $vars['css'] = $this->css(); $vars['votelist'] = \SYSTEM\SECURITY\Security::isLoggedIn() ? $this->generate_votelist() : $this->get_coverpage() ; - $vars['vote'] = $this->generate_vote(); +// $vars['vote'] = $this->generate_vote(); $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='; diff --git a/uVote/page/default_page/full_vote.tpl b/uVote/page/default_page/full_vote.tpl index 3bd648c..d32513d 100644 --- a/uVote/page/default_page/full_vote.tpl +++ b/uVote/page/default_page/full_vote.tpl @@ -1,16 +1,8 @@ -
+
-

${vote_title}

-
-
- Initiiert von: ${vote_init} -
-
-
-
- ${vote_text} -
+

${title}

+
diff --git a/uVote/page/default_page/loggedinformtop.tpl b/uVote/page/default_page/loggedinformtop.tpl index bb96526..091d50a 100644 --- a/uVote/page/default_page/loggedinformtop.tpl +++ b/uVote/page/default_page/loggedinformtop.tpl @@ -1,5 +1,5 @@ \ No newline at end of file diff --git a/uVote/page/default_page/page.html b/uVote/page/default_page/page.html index 9d0eeb3..df4ee33 100644 --- a/uVote/page/default_page/page.html +++ b/uVote/page/default_page/page.html @@ -23,7 +23,7 @@