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!)
This commit is contained in:
Nael 2014-02-12 22:39:27 +01:00
parent 69d3178e96
commit 8059716e46
17 changed files with 213 additions and 83 deletions

View File

@ -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;
}
}

View File

@ -0,0 +1,16 @@
<?php
namespace DBD;
class UVOTE_DATA_BT_PER_POLL extends \SYSTEM\DB\QP {
protected static function query(){
return new \SYSTEM\DB\QQuery(get_class(),
//pg
'',
//mys
'SELECT
sum(votes_pro) as bt_pro,
sum(votes_contra) as bt_con,
sum(nr_attending) as bt_attending,
sum(total) as bt_total
FROM uvote_votes_per_party WHERE poll_ID = ?;'
);}}

View File

@ -0,0 +1,11 @@
<?php
namespace DBD;
class UVOTE_DATA_CHOICE_OVERALL extends \SYSTEM\DB\QP {
protected static function query(){
return new \SYSTEM\DB\QQuery(get_class(),
//pg
'',
//mys
'SELECT COUNT(*) as "count" FROM uvote_data WHERE CHOICE = ?;'
);}}

View File

@ -0,0 +1,11 @@
<?php
namespace DBD;
class UVOTE_POLL_EXPIRED extends \SYSTEM\DB\QP {
protected static function query(){
return new \SYSTEM\DB\QQuery(get_class(),
//pg
'',
//mys
'SELECT * FROM `uvote_votes` WHERE `ID` = ? AND time_end > CURDATE();'
);}}

View File

@ -0,0 +1,6 @@
<h4>${title}</h4>
<div class="progress" style="height: 30px;">
<div class="bar bar-success" style="width: ${vote_yes_perc}%;">Yes</div>
<div class="bar bar-danger" style="width: ${vote_no_perc}%;">No</div>
<div class="bar bar-info" style="width: ${vote_ent_perc}%;">Ent</div>
</div>

View File

@ -3,22 +3,19 @@
</script>
<div style="margin-right: 10px;">
<img src="${frontend_logos}logo2.png" style="float: right" width="200px"/>
<h5>Auf einen Blick</h5>
${vote_quick}
<br>
<a class="btn btn-green btnvote_yes"
id="btnvote_yes"
style="width: 65px;"
poll_ID="${poll_ID}"><font
size="3">Pro</font></a>
<a class="btn btn-red btnvote_no"
style="width: 65px;"
href="#"
poll_ID="${poll_ID}"><font
size="3">Contra</font></a>
<a class="btn btn-grey btnvote_off"
style="width: 65px;"
href="#"
poll_ID="${poll_ID}"><font
size="3">Enthaltung</font></a>
</div>
${vote_buttons}
</div>
<br>
<div>
${bars_user}
</div>
<div>
<h4>Ergebnis der Fraktionen</h4>
${bars_party}
</div>
<div style="clear: both"></div>
<div>
${bars_bt}
</div>

View File

@ -6,16 +6,77 @@ class default_bulletin extends SYSTEM\PAGE\Page {
}
private function js(){
return '<script src="'.SYSTEM\WEBPATH(new PPAGE(),'default_bulletin/js/vote.js').'"></script>';
}
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 '<script src="'.SYSTEM\WEBPATH(new PPAGE(),'default_bulletin/js/vote.js').'"></script>';}
private function css(){
return '<link href="'.SYSTEM\WEBPATH(new PPAGE(),'default_page\css\default_page.css').'" rel="stylesheet">';}
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 ?
'<h4>Stimme hier ab</h4>
<a class="btn btn-success btn-default btnvote_yes"
style="width: 70px"
poll_ID="${poll_ID}"><font
size="3">Pro</font></a>
<a class="btn btn-danger btn-default btnvote_no"
style="width: 70px"
href="#"
poll_ID="${poll_ID}"><font
size="3">Contra</font></a>
<a class="btn btn-info btn-default btnvote_off"
style="width: 70px"
href="#"
poll_ID="${poll_ID}"><font
size="3">Enthaltung</font></a>' :
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);
}

View File

@ -0,0 +1,8 @@
<div style="margin-right: 10px;">
<h4>Ergebnis Bundestag</h4>
<div class="progress" style="width: 150px; height: 20px;">
<div class="bar bar-success" style="width: ${bt_pro}%;"></div>
<div class="bar bar-danger" style="width: ${bt_con}%;"></div>
<div class="bar bar-info" style="width: ${bt_ent}%;"><p></p></div>
</div>
</div>

View File

@ -0,0 +1,8 @@
<div style="float: left; margin-right: 10px;">
${party}
<div class="progress" style="width: 50px; height: 20px;">
<div class="bar bar-success" style="width: ${party_yes}%;"></div>
<div class="bar bar-danger" style="width: ${party_no}%;"></div>
<div class="bar bar-info" style="width: ${party_ent}%;"><p></p></div>
</div>
</div>

View File

@ -1,6 +1,6 @@
<div class="row" style="margin-right: 30px;">
<img src="${frontend_logos}cover.png"/>
<div style="float: right; margin-right: 25px;">
<div style="margin-right: 25px;">
<img src="${frontend_logos}chrome.png" width="200px"/>
</div>
</div>

View File

@ -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;
}
background: lightgrey;
}

View File

@ -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=';

View File

@ -1,16 +1,8 @@
<div class="row" style="margin: 0; background: #f1f1f1;">
<div class="row" style="margin: 0;">
<div class="span6" style="width: 50%;">
<h4>${vote_title}</h4>
<br>
<div style="">
Initiiert von: ${vote_init}
</div>
<br>
<br>
<div>
${vote_text}
</div>
<h4>${title}</h4>
<iframe src="${iframe_link}" width="730" height="580"></iframe>
</div>
</div>

View File

@ -1,5 +1,5 @@
<form class="navbar-form pull-right" id="form_logout">
<input class="span2" type="hidden" id="hidden" >
<button type="submit" class="btn">Logout</button>
<button type="submit" class="btn btn-primary">Logout</button>
</form>

View File

@ -23,7 +23,7 @@
<div class="navbar navbar-inverse navbar-fixed-top" style="width: 100%">
<div class="navbar-inner" style="width: 100%">
<div class="container" style="width: 90%">
<div class="container" style="width: 95%">
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
@ -46,15 +46,11 @@
</div>
</div>
<div class="box" style="margin-top: 0; clear: both;">
<div id="site-content" style="padding: 0; margin: 0; margin-left: 40px;">
<div id="list" style="padding: 0px; float: right; width: 50%;">
<div id="site-content" style="padding: 0; margin: 0; margin-left: 40px;">
<div id="user_main" style="padding: 0px; width: 600px; float: left;"></div>
<div id="list" style="padding: 0px; width: 50%; float: right;">
${votelist}
</div>
<div id="user_main" style="padding: 0px; width: 600px; float: left; position: fixed;">
</div>
</div>
</div>
</div>
<div id="wrap">

View File

@ -1,18 +1,16 @@
<table class="${vote_class} table table-hover" style="display: table; margin-bottom: 5px; border: 2px solid #ccc; float: left; width: 85%; height: 100px;">
<table class="table" style="display: table; margin-bottom: 5px; float: left; width: 95%; height: 100px;">
<div style="margin: 0; margin-top: 5px; margin-bottom: 8px;">
<tr>
<td style="border-right: 2px solid #ccc; width: 20px;">Nr.
<br>
${poll_ID}</td>
<td class="" style="">
<a class="btn btn-primary btn-small btn_vote" style="float:right" poll_ID="${poll_ID}">${full_vote_btn}</a>
<h4>${vote_title}</h4>
Politikfeld(er):
Nr.${poll_ID}
</td>
<td style="width: 70px; margin-top: 10px; border-left: 2px solid #ccc;">
<a class="btn btn_primary btn_vote" poll_ID="${poll_ID}">Abstimmen</a>
<td class="${vote_class}" style="width: 20px; margin-top: 10px; border-left: 2px solid black;">
</td>
</tr>
</tr>
<!--<div class="span5" style="margin-top: 15px;">
<a class="btn btn-large btn-green btnvote_yes" style="width: 110px;" poll_ID="$">Pro &raquo;</a>
<a class="btn btn-large btn-red btnvote_no" style="width: 110px; background-color: red;" href="#" poll_ID="$">Contra &raquo;</a>

View File

@ -1,6 +1,25 @@
<?php
class user_main_uVote extends SYSTEM\PAGE\Page {
public function html(){
class user_main_uVote extends SYSTEM\PAGE\Page {
private function votes_overall(){
$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;
}
public function html(){
$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['votes_overall'] = $this->votes_overall();
$vars['frontend_logos'] = \SYSTEM\CONFIG\config::get(\SYSTEM\CONFIG\config_ids::SYS_CONFIG_PATH_BASEURL).'api.php?call=img&cat=frontend_logos&id=';
return SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'user_main_uVote/uVote.tpl'),$vars);
}