From ed7a4312eac8ae31bcf0a74f057ac999e6b3de8d Mon Sep 17 00:00:00 2001 From: Naeltard Date: Tue, 6 Oct 2015 18:04:39 +0200 Subject: [PATCH] major leap --- uvote/api/api_uvote.php | 10 ++ uvote/api/votes/graphs.php | 10 ++ uvote/api/votes/votes.php | 83 ++++++++- uvote/page/default_page/default_page.php | 6 + uvote/page/default_page/js/loadtexts.js | 42 ++++- uvote/page/default_page/tpl/menu.tpl | 15 ++ .../page/default_page/tpl/menu_loggedout.tpl | 8 + uvote/page/default_page/tpl/page.tpl | 67 +++----- uvote/page/default_register/tpl/register.tpl | 73 ++------ uvote/page/page_uvote.php | 6 + .../js/user_main_analysis.js | 5 + .../user_main_analysis/tpl/according_laws.tpl | 0 .../page/user_main_analysis/tpl/all_polls.tpl | 23 ++- .../tpl/bt_to_user_overall.tpl | 28 ++- .../tpl/overall_all_polls.tpl | 18 +- .../tpl/urvotebt_by_choice.tpl | 17 ++ .../user_main_analysis/tpl/urvoteparties.tpl | 20 ++- .../tpl/urvoteparties_by_choice.tpl | 17 ++ .../tpl/user_main_analysis.tpl | 162 ++++++++++++++---- .../user_main_analysis/tpl/user_total.tpl | 52 ++++++ .../user_main_analysis/user_main_analysis.php | 26 ++- uvote/page/user_main_poll/tpl/full_vote.tpl | 55 ++++-- uvote/page/user_main_poll/tpl/table_bt.tpl | 2 +- uvote/page/user_main_poll/tpl/vote_bt.tpl | 19 +- uvote/page/user_main_poll/user_main_poll.php | 12 +- .../tpl/user_main_votelist.tpl | 35 ++-- uvote/page/user_main_votelist/tpl/vote.tpl | 2 +- ...TA_GRAPH_PARTY_TO_USER_OVERALL_BY_TIME.php | 16 ++ .../sql/qq/UVOTE_DATA_USER_CHOICE_OVERALL.php | 11 ++ 29 files changed, 638 insertions(+), 202 deletions(-) create mode 100644 uvote/page/default_page/tpl/menu.tpl create mode 100644 uvote/page/default_page/tpl/menu_loggedout.tpl create mode 100644 uvote/page/user_main_analysis/js/user_main_analysis.js create mode 100644 uvote/page/user_main_analysis/tpl/according_laws.tpl create mode 100644 uvote/page/user_main_analysis/tpl/urvotebt_by_choice.tpl create mode 100644 uvote/page/user_main_analysis/tpl/urvoteparties_by_choice.tpl create mode 100644 uvote/page/user_main_analysis/tpl/user_total.tpl create mode 100644 uvote/sql/qq/UVOTE_DATA_GRAPH_PARTY_TO_USER_OVERALL_BY_TIME.php create mode 100644 uvote/sql/qq/UVOTE_DATA_USER_CHOICE_OVERALL.php diff --git a/uvote/api/api_uvote.php b/uvote/api/api_uvote.php index 2bf568c..c2768ad 100644 --- a/uvote/api/api_uvote.php +++ b/uvote/api/api_uvote.php @@ -28,6 +28,16 @@ class api_uvote extends \SYSTEM\API\api_system { public static function call_graph_bt_to_user_overall_by_time($timespan = 84600){ return graphs::graph_bt_to_user_overall_by_time($timespan);} + public static function call_graph_party_to_user_overall_by_time_party_cdu($party = 'cdu', $timespan = 84600){ + return graphs::graph_party_to_user_overall_by_time($party, $timespan);} + public static function call_graph_party_to_user_overall_by_time_party_csu($party = 'csu', $timespan = 84600){ + return graphs::graph_party_to_user_overall_by_time($party, $timespan);} + public static function call_graph_party_to_user_overall_by_time_party_spd($party = 'spd', $timespan = 84600){ + return graphs::graph_party_to_user_overall_by_time($party, $timespan);} + public static function call_graph_party_to_user_overall_by_time_party_gruene($party = 'gruene', $timespan = 84600){ + return graphs::graph_party_to_user_overall_by_time($party, $timespan);} + public static function call_graph_party_to_user_overall_by_time_party_linke($party = 'linke', $timespan = 84600){ + return graphs::graph_party_to_user_overall_by_time($party, $timespan);} //comments public static function call_vote_action_comment($poll_ID, $c_choice, $c_txt, $c_src) { diff --git a/uvote/api/votes/graphs.php b/uvote/api/votes/graphs.php index a64bb21..c819397 100644 --- a/uvote/api/votes/graphs.php +++ b/uvote/api/votes/graphs.php @@ -24,4 +24,14 @@ class graphs { return $returnasjson ? SYSTEM\LOG\JsonResult::toString($result) : $result; } + public static function graph_party_to_user_overall_by_time ($party, $timespan, $returnasjson = true){ + $result = array(); + $res = \SQL\UVOTE_DATA_GRAPH_PARTY_TO_USER_OVERALL_BY_TIME::QQ(array($timespan, \SYSTEM\SECURITY\Security::getUser()->id, $party, \SYSTEM\SECURITY\Security::getUser()->id)); + while ($row = $res->next()){ + $result[] = array( 0 => $row['day'], + 'class_match' => $row['class_match'] / ($row['class_match']+$row['class_mismatch']+1)); + } + return $returnasjson ? SYSTEM\LOG\JsonResult::toString($result) : $result; + } + } diff --git a/uvote/api/votes/votes.php b/uvote/api/votes/votes.php index 0e29d89..783b5ef 100644 --- a/uvote/api/votes/votes.php +++ b/uvote/api/votes/votes.php @@ -11,6 +11,10 @@ class votes { $res = \SQL\UVOTE_DATA_COUNT_VOTES::QQ(); return $res;} + public static function get_user_choice_overall($user_ID){ + return \SQL\UVOTE_DATA_USER_CHOICE_OVERALL::Q1(array($user_ID)); + } + public static function get_user_choice_per_poll($poll_ID, $user_ID){ return \SQL\UVOTE_DATA_USER_CHOICE_PER_POLL::Q1(array($poll_ID, $user_ID)); } @@ -25,7 +29,84 @@ class votes { $result = $res->next(); return $result['choice']; } - + public static function get_user_match_per_choice($choice){ + switch($choice){ + case 1: + $bar = 'progress-bar-success'; + break; + case 2: + $bar = 'progress-bar-danger'; + break; + case 3: + $bar = 'progress-bar-info'; + break; + case 0: + $bar = 'progress-bar'; + } + $result = ''; + $con = new \SYSTEM\DB\Connection(); + $res = $con->prepare( 'user_to_party_by_choice', + 'SELECT party, sum(case when uvote_data.choice = uvote_votes_per_party.choice then 1 else 0 end) class_MATCH, + sum(case when uvote_data.choice != uvote_votes_per_party.choice then 1 else 0 end) class_MISSMATCH + FROM uvote_data INNER JOIN uvote_votes_per_party + ON uvote_data.poll_ID = uvote_votes_per_party.poll_ID + WHERE user_ID = ? AND uvote_data.choice = ? GROUP BY party;', + array(\SYSTEM\SECURITY\Security::getUser()->id, $choice)); + $i = 0; + while($row = $res->next()){ + $row['match_percentage'] = round($row['class_MATCH']/($row['class_MATCH']+$row['class_MISSMATCH'])*100,2); + $row['bar'] = $bar; + $result .= \SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'user_main_analysis/tpl/urvoteparties_by_choice.tpl'), $row);; + } + if(empty($result)){ + return 'Keine relevanten Daten verfügbar'; + } + + return $result; + } + public static function get_user_match_per_choice_bt($choice){ + switch($choice){ + case 1: + $bar = 'progress-bar-success'; + $icon_type = 'pro'; + break; + case 2: + $bar = 'progress-bar-danger'; + $icon_type = 'con'; + break; + case 3: + $bar = 'progress-bar-info'; + $icon_type = 'ent'; + break; + case 0: + $bar = 'progress-bar'; + } + $result = ''; + $con = new \SYSTEM\DB\Connection(); + $res = $con->prepare( 'user_to_party_by_choice_bt', + 'SELECT user_ID, sum(case when uvote_data.choice = uvote_votes.bt_choice then 1 else 0 end) class_MATCH, + sum(case when uvote_data.choice != uvote_votes.bt_choice then 1 else 0 end) class_MISSMATCH + FROM uvote_data INNER JOIN uvote_votes + ON uvote_data.poll_ID = uvote_votes.ID + WHERE user_ID = ? AND uvote_data.choice = ? GROUP by user_ID;', + array(\SYSTEM\SECURITY\Security::getUser()->id, $choice)); + $i = 0; + + while($row = $res->next()){ + if(empty($row['class_MATCH'])){ + return 'Keine relevanten Daten verfügbar
'; + } + $row['match_percentage'] = round($row['class_MATCH']/($row['class_MATCH']+$row['class_MISSMATCH'])*100,2); + $row['bar'] = $bar; + $row['icon_type'] = $icon_type; + $result .= \SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'user_main_analysis/tpl/urvotebt_by_choice.tpl'), $row);; + } + if(empty($result)){ + return 'Keine relevanten Daten verfügbar'; + } + + return $result; + } public static function get_barsperusers($poll_ID,$return_as_json = true){ $con = new \SYSTEM\DB\Connection(); //count diff --git a/uvote/page/default_page/default_page.php b/uvote/page/default_page/default_page.php index 112fd12..4ee7ac6 100644 --- a/uvote/page/default_page/default_page.php +++ b/uvote/page/default_page/default_page.php @@ -39,12 +39,18 @@ class default_page extends SYSTEM\PAGE\Page { public function exchange_loginform(){ return SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_page/tpl/loggedinformtop.tpl'),array());} + + public function get_menu(){ + return SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_page/tpl/menu.tpl'),array());} + public function exchange_menu(){ + return SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_page/tpl/menu_loggedout.tpl'),array());} public function html($_escaped_fragment_ = NULL){ $vars = array(); if(!$_escaped_fragment_){ $vars['js'] = $this->js();} $vars['css'] = $this->css(); + $vars['menu'] = \SYSTEM\SECURITY\Security::isLoggedIn() ? $this->get_menu() : $this->exchange_menu(); $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=files&cat=frontend_logos&id='; diff --git a/uvote/page/default_page/js/loadtexts.js b/uvote/page/default_page/js/loadtexts.js index 883dee7..19f566b 100644 --- a/uvote/page/default_page/js/loadtexts.js +++ b/uvote/page/default_page/js/loadtexts.js @@ -2,7 +2,15 @@ $(document).ready(function() { new SYSTEM('./api.php',1,'start'); register_login(); register_logout(); + navstate(); }); +function navstate(){ + $(".nav a").on("click", function(){ + $(".nav").find(".active").removeClass("active"); + $(this).parent().addClass("active"); +}); +} + function register_login(){ $("#form_login input").not("[type=submit]").jqBootstrapValidation({ @@ -268,8 +276,38 @@ function load_visualisation_urvote(id, timespan){ first = true; data.addRow($.map(value, function(v) { if(first){first=false;return [new Date(v)];}else{return [parseFloat(v)];}}));}); - console.log(data); var options = {title: id, aggregationTarget: 'category', selectionMode: 'multiple', curveType: 'function', /*focusTarget: 'category',*/ chartArea:{}, vAxis:{logScale: false}, interpolateNulls: false, width: "300", height: "250"}; new google.visualization.LineChart(document.getElementById(id)).draw(data, options); }); -} \ No newline at end of file +} + +function load_visualisation_user_to_party_overall(id, party, timespan){ + $('img#loader').show(); + $.getJSON('./api.php?call=graph_party_to_user_overall_by_time&party=' + party,function(json){ + if(!json || json.status != true || !json.result){ + $('img#loader').hide(); + return; + } + json = json.result; + $('img#loader').hide(); + var data = new google.visualization.DataTable(); + console.log(json); + first = true; + $.each(json[0], function(key, value){ + if(first){ + data.addColumn('datetime',key); + first = false; + } else { + data.addColumn('number',key); + } + }); + $.each(json, function(key, value){ + first = true; + data.addRow($.map(value, function(v) { if(first){first=false;return [new Date(v)];}else{return [parseFloat(v)];}}));}); + + + var options = {title: 'Übereinstimmung mit ' + party, aggregationTarget: 'category', selectionMode: 'multiple', curveType: 'function', /*focusTarget: 'category',*/ chartArea:{}, vAxis:{logScale: false}, interpolateNulls: false, width: "800", height: "250"}; + new google.visualization.LineChart(document.getElementById(id)).draw(data, options); + }); +} + diff --git a/uvote/page/default_page/tpl/menu.tpl b/uvote/page/default_page/tpl/menu.tpl new file mode 100644 index 0000000..0ee882c --- /dev/null +++ b/uvote/page/default_page/tpl/menu.tpl @@ -0,0 +1,15 @@ +
+ +
diff --git a/uvote/page/default_page/tpl/menu_loggedout.tpl b/uvote/page/default_page/tpl/menu_loggedout.tpl new file mode 100644 index 0000000..f9acf00 --- /dev/null +++ b/uvote/page/default_page/tpl/menu_loggedout.tpl @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/uvote/page/default_page/tpl/page.tpl b/uvote/page/default_page/tpl/page.tpl index b0f0678..4ca474f 100644 --- a/uvote/page/default_page/tpl/page.tpl +++ b/uvote/page/default_page/tpl/page.tpl @@ -10,49 +10,34 @@ ${js} -
- -
-
-

- Gallery -

-
- + \ No newline at end of file diff --git a/uvote/page/user_main_analysis/tpl/user_total.tpl b/uvote/page/user_main_analysis/tpl/user_total.tpl new file mode 100644 index 0000000..07576f6 --- /dev/null +++ b/uvote/page/user_main_analysis/tpl/user_total.tpl @@ -0,0 +1,52 @@ +
+
+
Deine Stimmverteilung
+
+
+
+
+
+ +
+
+ pro Stimmen +
+
${user_total_pro}
+
+
+
+
+
+
+ +
+
+ contra Stimmen +
+
${user_total_con}
+
+
+
+
+
+
+ +
+
+ Enthaltungen +
+
+
${user_total_ent}
+
+
+
+
+
+ +
+
+
+
Total: ${user_total_total}
+
+
+
diff --git a/uvote/page/user_main_analysis/user_main_analysis.php b/uvote/page/user_main_analysis/user_main_analysis.php index 5f0a2d2..c87a69e 100644 --- a/uvote/page/user_main_analysis/user_main_analysis.php +++ b/uvote/page/user_main_analysis/user_main_analysis.php @@ -46,6 +46,7 @@ class user_main_analysis extends SYSTEM\PAGE\Page { private function user_per_party_overall(){ + //$vars = votes::get_user_per_party_overall(array(\SYSTEM\SECURITY\Security::getUser()->id)); $result = ''; $con = new \SYSTEM\DB\Connection(); @@ -65,10 +66,16 @@ class user_main_analysis extends SYSTEM\PAGE\Page { $result .= \SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'user_main_analysis/tpl/urvoteparties.tpl'), $row);; } return $result; +} +private function user_per_party_by_choicetype($choice){ + return votes::get_user_match_per_choice($choice); +} +private function user_per_bt_by_choicetype($choice){ + return votes::get_user_match_per_choice_bt($choice); } public function build_according_law_html($part, $party){ $part = json_decode($part, true); - $result = "
Bei folgenden Gesetzen hast du genauso abgestimmt wie die '".$party."':

"; + $result = "
Bei folgenden Gesetzen hast du genauso abgestimmt wie die ".$party."':

"; foreach ($part['result'] as $p){ $result .= $p['title']."
"; } @@ -124,12 +131,29 @@ class user_main_analysis extends SYSTEM\PAGE\Page { } return $result; } + public static function get_basic_stats(){ + $vars = votes::get_user_choice_overall(\SYSTEM\SECURITY\Security::getUser()->id); + $vars['user_total_total'] = $vars['user_total_pro'] + $vars['user_total_con'] + $vars['user_total_ent']; + $vars['user_total_pro_percentage'] = round($vars['user_total_pro']/$vars['user_total_total']*100+1); + $vars['user_total_con_percentage'] = round($vars['user_total_con']/$vars['user_total_total']*100+1); + $vars['user_total_ent_percentage'] = round($vars['user_total_ent']/$vars['user_total_total']*100+1); + return \SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'user_main_analysis/tpl/user_total.tpl'),$vars); + } + public static function js(){ + return array(\SYSTEM\WEBPATH(new \PPAGE(),'user_main_analysis/js/user_main_analysis.js'));} public function html(){ $vars = array(); // $vars['poll_compare'] = $this->count_all_polls(); + $vars['basic_stats'] = $this->get_basic_stats(); $vars['votes_all'] = $this->votes_all(); $vars['votes_all_bt'] = $this->votes_all_bt(); $vars['choices_user_ID'] = $this->user_per_party_overall(); + $vars['choices_user_ID_per_party_pro'] = $this->user_per_party_by_choicetype('1'); + $vars['choices_user_ID_per_party_con'] = $this->user_per_party_by_choicetype('2'); + $vars['choices_user_ID_per_party_ent'] = $this->user_per_party_by_choicetype('3'); + $vars['choices_user_ID_per_bt_pro'] = $this->user_per_bt_by_choicetype('1'); + $vars['choices_user_ID_per_bt_con'] = $this->user_per_bt_by_choicetype('2'); + $vars['choices_user_ID_per_bt_ent'] = $this->user_per_bt_by_choicetype('3'); $vars['choices_bt_to_user'] = $this->user_to_bt(); $vars['frontend_logos'] = \SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_PATH_BASEURL).'api.php?call=files&cat=frontend_logos&id='; $vars['user_temp_votes'] = $this->user_temp_votes(); diff --git a/uvote/page/user_main_poll/tpl/full_vote.tpl b/uvote/page/user_main_poll/tpl/full_vote.tpl index eeea1e8..93851df 100644 --- a/uvote/page/user_main_poll/tpl/full_vote.tpl +++ b/uvote/page/user_main_poll/tpl/full_vote.tpl @@ -1,29 +1,60 @@ -
+
+

${title}

${openvote_help_text} - ${title} - ${openvote_help_text1} + ${title} abstimmen. +
${vote_buttons} +
${voice_weight}
-
- ${bars_user}
- ${bars_bt} +
+
+
+
+
+

+ Endergebnis +

+
+
+ ${bars_user}
+ ${bars_bt} +
+
+
-
- ${icons_party} - ${choice_party} +
+
+
+
+ +
+ + ${choice_party} +
+
+
-
-
+
+ +
+
-
+ +
+
+ diff --git a/uvote/page/user_main_poll/tpl/table_bt.tpl b/uvote/page/user_main_poll/tpl/table_bt.tpl index 7237f29..ad57733 100644 --- a/uvote/page/user_main_poll/tpl/table_bt.tpl +++ b/uvote/page/user_main_poll/tpl/table_bt.tpl @@ -1,5 +1,5 @@ Ergebnis Bundestag -
+
${bt_pro}%
${bt_con}%

${bt_ent}%

diff --git a/uvote/page/user_main_poll/tpl/vote_bt.tpl b/uvote/page/user_main_poll/tpl/vote_bt.tpl index 381e96e..ab90130 100644 --- a/uvote/page/user_main_poll/tpl/vote_bt.tpl +++ b/uvote/page/user_main_poll/tpl/vote_bt.tpl @@ -1,8 +1,11 @@ -
-
-
${choice}
-
${party_yes}%
-
${party_no}%
-
${party_ent}%
-
${party_off}%
-
\ No newline at end of file +
+
+
+
+
${party_yes}%
+
${party_no}%
+
${party_ent}%
+
+
+
+
\ No newline at end of file diff --git a/uvote/page/user_main_poll/user_main_poll.php b/uvote/page/user_main_poll/user_main_poll.php index e846ee1..ac6b636 100644 --- a/uvote/page/user_main_poll/user_main_poll.php +++ b/uvote/page/user_main_poll/user_main_poll.php @@ -113,15 +113,15 @@ class user_main_poll extends SYSTEM\PAGE\Page { if(!$user_poll){ return '
Stimme hier ab
';} $classes = array('','',''); @@ -134,16 +134,16 @@ class user_main_poll extends SYSTEM\PAGE\Page { return '
Ändere deine Stimme hier ab
diff --git a/uvote/page/user_main_votelist/tpl/user_main_votelist.tpl b/uvote/page/user_main_votelist/tpl/user_main_votelist.tpl index 96c5373..e640ac7 100644 --- a/uvote/page/user_main_votelist/tpl/user_main_votelist.tpl +++ b/uvote/page/user_main_votelist/tpl/user_main_votelist.tpl @@ -1,25 +1,38 @@
-
-
+ +

- uvote + Willkommen auf uvote.eu!

- ${welcome_text} -
+
+ ${welcome_text} +
+
+ ${user_temp_votes} + ${user_count} Nutzer auf uVote +
+
+ +
-
- ${user_temp_votes} - ${user_count} Nutzer auf uVote - -
+
+
+
+

+ Hier gehts zur Abstimmung +

+
+
+ ${votelist} +
+
-${votelist} \ No newline at end of file diff --git a/uvote/page/user_main_votelist/tpl/vote.tpl b/uvote/page/user_main_votelist/tpl/vote.tpl index 9dbabfe..b3d01d8 100644 --- a/uvote/page/user_main_votelist/tpl/vote.tpl +++ b/uvote/page/user_main_votelist/tpl/vote.tpl @@ -3,7 +3,7 @@
diff --git a/uvote/sql/qq/UVOTE_DATA_GRAPH_PARTY_TO_USER_OVERALL_BY_TIME.php b/uvote/sql/qq/UVOTE_DATA_GRAPH_PARTY_TO_USER_OVERALL_BY_TIME.php new file mode 100644 index 0000000..bbfbb03 --- /dev/null +++ b/uvote/sql/qq/UVOTE_DATA_GRAPH_PARTY_TO_USER_OVERALL_BY_TIME.php @@ -0,0 +1,16 @@ +