bars working, thx 2 rylon
This commit is contained in:
parent
ed0005dd82
commit
7cdf8a0925
@ -4,6 +4,7 @@ require_once '../system/autoload.inc.php';
|
||||
require_once 'uVote/autoload.inc.php'; //Project Classes
|
||||
require_once '../system/log/register_exception_shortcut.php'; //allow ERROR() instead of \SYSTEM\LOG\ERROR()
|
||||
require_once '../system/log/register_errorhandler_jsonoutput.php'; //print errors as json to caller
|
||||
require_once '../system/log/register_result_shortcut.php';
|
||||
|
||||
require_once 'config.php';
|
||||
SYSTEM\system::start($uvote_config);
|
||||
|
||||
@ -2,9 +2,7 @@
|
||||
|
||||
class ApiClass extends \SYSTEM\API\apiloginclass {
|
||||
public static function call_vote_action_vote($poll_ID, $vote) {
|
||||
return votes::write_vote($poll_ID, $vote);
|
||||
}
|
||||
public static function call_vote_action_openinfo($poll_ID) {
|
||||
return votes::get_openinfo($poll_ID);
|
||||
}
|
||||
return votes::write_vote($poll_ID, $vote);}
|
||||
public static function call_vote_action_barsperusers($poll_ID){
|
||||
return votes::get_barsperusers($poll_ID);}
|
||||
}
|
||||
@ -12,33 +12,61 @@ class votes {
|
||||
|
||||
return $result;
|
||||
}
|
||||
private static function getProgessbar($percentage){
|
||||
$vars = array('percentage' => $percentage);
|
||||
return SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_page/closedvoteinfo.tpl'), $vars);
|
||||
|
||||
public static function get_barsperusers($poll_ID,$return_as_json = true){
|
||||
$con = new \SYSTEM\DB\Connection(new \DBD\uVote());
|
||||
//count
|
||||
$res = $con->prepare( 'selVoteBy_count',
|
||||
'SELECT COUNT(*) as "count" FROM `uvote_data` WHERE `poll_ID` = ?;',
|
||||
array($poll_ID));
|
||||
$res = $res->next();
|
||||
$result = array();
|
||||
$result['poll_ID'] = $poll_ID;
|
||||
$result['count'] = $res['count'];
|
||||
//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',
|
||||
'SELECT COUNT(*) as "count" FROM `uvote_data` WHERE `poll_ID` = ? AND choice = 2;',
|
||||
array($poll_ID));
|
||||
$res = $res->next();
|
||||
$result['no'] = $res['count'];
|
||||
$result['no_perc'] = $res['count'] / $result['count'];
|
||||
//ent
|
||||
$res = $con->prepare( 'selVoteBy_count',
|
||||
'SELECT COUNT(*) as "count" FROM `uvote_data` WHERE `poll_ID` = ? AND choice = 3;',
|
||||
array($poll_ID));
|
||||
$res = $res->next();
|
||||
$result['ent'] = $res['count'];
|
||||
$result['ent_perc'] = $res['count'] / $result['count'];
|
||||
|
||||
return $return_as_json ? JsonResult::toString($result) : $result;
|
||||
}
|
||||
|
||||
public static function get_barsperparty($poll_ID){
|
||||
$con = new \SYSTEM\DB\Connection(new \DBD\uVote());
|
||||
$pbpp = "";
|
||||
$part = $con->prepare( 'selVoteByPoll_ID',
|
||||
'SELECT * FROM `uvote_votes_per_party` WHERE `poll_ID` = ?;',
|
||||
array($poll_ID));
|
||||
|
||||
while ($result = $part->next()){
|
||||
$pbpp .= self::getProgessbar($result['votes_pro']);}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function get_openinfo($poll_ID){
|
||||
public static function get_voteinfo($poll_ID){
|
||||
$con = new \SYSTEM\DB\Connection(new \DBD\uVote());
|
||||
$res = $con->prepare( 'selVoteByID',
|
||||
'SELECT * FROM `uvote_votes` WHERE `ID` = ?;',
|
||||
array($poll_ID));
|
||||
$res = $res->next();
|
||||
$result = array();
|
||||
$result['graph_right'] = get_barsperparty($pbpp);
|
||||
$result = array_merge($result,$res);
|
||||
return SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_page/openvoteinfo.tpl'),$result);
|
||||
return $res;
|
||||
}
|
||||
|
||||
public static function get_barsperparty($poll_ID){
|
||||
$con = new \SYSTEM\DB\Connection(new \DBD\uVote());
|
||||
$pbpp = array();
|
||||
$part = $con->prepare( 'selVoteByPoll_ID',
|
||||
'SELECT * FROM `uvote_votes_per_party` WHERE `poll_ID` = ?;',
|
||||
array($poll_ID));
|
||||
|
||||
while ($result = $part->next()){
|
||||
$pbpp[] = $result;}
|
||||
return $pbpp;
|
||||
}
|
||||
|
||||
public static function write_vote($poll_ID, $vote){
|
||||
|
||||
@ -42,5 +42,8 @@ class PageApi extends \SYSTEM\PAGE\PageClass {
|
||||
//require_once 'dasense/sai/autoload.inc.php';
|
||||
//require_once 'dasense/sai/register_modules.php';
|
||||
return new \SYSTEM\SAI\saigui();}
|
||||
|
||||
public static function action_openinfo($poll_ID){
|
||||
return new default_openinfo($poll_ID);}
|
||||
|
||||
}
|
||||
5
uVote/page/default_openinfo/bars_user.tpl
Normal file
5
uVote/page/default_openinfo/bars_user.tpl
Normal file
@ -0,0 +1,5 @@
|
||||
<div class="progress" style="height: 30px;">
|
||||
<div class="bar bar-success" style="width: ${vote_yes_perc}%;">Yes</div>
|
||||
<div class="bar bar-warning" style="width: ${vote_no_perc}%;">No</div>
|
||||
<div class="bar bar-danger" style="width: ${vote_ent_perc}%;">Ent</div>
|
||||
</div>
|
||||
10
uVote/page/default_openinfo/closedvoteinfo.tpl
Normal file
10
uVote/page/default_openinfo/closedvoteinfo.tpl
Normal file
@ -0,0 +1,10 @@
|
||||
<tr>
|
||||
<td>${party}</td>
|
||||
<td style="width: 100%;">
|
||||
<div class="progress" style="height: 30px; width: 100%;">
|
||||
<div class="bar bar-success" style="width: ${party_yes}%;">Pro</div>
|
||||
<div class="bar bar-warning" style="width: ${party_no}%;">Contra</div>
|
||||
<div class="bar bar-danger" style="width: ${party_ent}%;"><p>Enthaltung</p></div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
42
uVote/page/default_openinfo/default_openinfo.php
Normal file
42
uVote/page/default_openinfo/default_openinfo.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
class default_openinfo extends SYSTEM\PAGE\Page {
|
||||
|
||||
private $poll_ID;
|
||||
|
||||
public function __construct($poll_ID) {
|
||||
$this->poll_ID = $poll_ID;
|
||||
}
|
||||
|
||||
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);
|
||||
return SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_openinfo/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);
|
||||
$vote['party_ent'] = round(($vote['total'] - $vote['nr_attending'])/$vote['total']*100,0);
|
||||
$pbpp .= SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_openinfo/closedvoteinfo.tpl'), $vote);
|
||||
}
|
||||
|
||||
return $pbpp;
|
||||
}
|
||||
|
||||
public function html(){
|
||||
|
||||
$result = array();
|
||||
$result['bars_party'] = $this->bars_party();
|
||||
$result['bars_user'] = $this->bars_user();
|
||||
$result = array_merge($result,votes::get_voteinfo($this->poll_ID));
|
||||
return SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_openinfo/openvoteinfo.tpl'),$result);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,4 +1,7 @@
|
||||
${graph_right}
|
||||
<table style="widht: 1000px;;">
|
||||
${bars_party}
|
||||
</table>
|
||||
${bars_user}
|
||||
<div class="span6" style="margin: 0;">
|
||||
<div class="hero_unit" style="margin: 0; padding: 20px; background-color: gainsboro; width: 95%;">
|
||||
<p>${text}</p>
|
||||
@ -1,3 +0,0 @@
|
||||
<div class="progress progress-info progress-striped">
|
||||
<div class="bar" style="width: ${percentage}%"></div>
|
||||
</div>
|
||||
@ -36,8 +36,8 @@ class default_page extends SYSTEM\PAGE\Page {
|
||||
public function exchange_loginform(){
|
||||
return SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_page/loggedinformtop.tpl'),array());}
|
||||
|
||||
public function load_openvoteinfo(){
|
||||
return SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_page/openvoteinfo.tpl'),array());}
|
||||
//public function load_openvoteinfo(){
|
||||
// return SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_page/openvoteinfo.tpl'),array());}
|
||||
|
||||
|
||||
// public function create_account(){
|
||||
@ -65,7 +65,7 @@ public function html(){
|
||||
$vars['js'] = $this->js();
|
||||
$vars['votelist'] = $this->generate_votelist();
|
||||
// $vars['personaldata'] = $this->getuserpersonaldata();
|
||||
$vars['openvoteinfo'] = $this->load_openvoteinfo();
|
||||
//$vars['openvoteinfo'] = $this->load_openvoteinfo();
|
||||
$vars['registerform'] = \SYSTEM\SECURITY\Security::isLoggedIn() ? $this->getloggedinform() : $this->exchange_registerform();
|
||||
$vars['loginform'] = \SYSTEM\SECURITY\Security::isLoggedIn() ? $this->exchange_loginform() : $this->getloginform() ;
|
||||
$vars['PIC_PATH'] = SYSTEM\WEBPATH(new PPAGE(),'default_page/pics/');
|
||||
|
||||
@ -83,7 +83,7 @@ function account_create(inputEmail, inputPassword){
|
||||
|
||||
function load_openvoteinfo (poll_ID){
|
||||
var openvoteinfo;
|
||||
$.get('./api.php?call=vote&action=openinfo&poll_ID=' + poll_ID, function (data) {
|
||||
$.get('./index.php?action=openinfo&poll_ID=' + poll_ID, function (data) {
|
||||
openvoteinfo = data;
|
||||
bodyelem = $("");
|
||||
bodyelem.animate();
|
||||
|
||||
@ -6,3 +6,4 @@ $autoload->registerFolder(dirname(__FILE__),'');
|
||||
$autoload->registerFolder(dirname(__FILE__).'/default_page','');
|
||||
$autoload->registerFolder(dirname(__FILE__).'/default_myvote','');
|
||||
$autoload->registerFolder(dirname(__FILE__).'/default_register','');
|
||||
$autoload->registerFolder(dirname(__FILE__).'/default_openinfo','');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user