voting functionality works

This commit is contained in:
Ulf Gebhardt 2015-09-16 16:00:48 +02:00
parent 8027756cac
commit 56e3aa0b05
16 changed files with 88 additions and 14 deletions

View File

@ -5,4 +5,9 @@ class api_mojotrollz extends \SYSTEM\API\api_system {
\SYSTEM\LOG\JsonResult::ok() :
\SYSTEM\LOG\JsonResult::fail();
}
public static function call_mojo_action_vote($server){
return \SQL\MOJOTROLLZ_VOTE_INSERT::QI(array($server,$_SERVER['REMOTE_ADDR'])) ?
\SYSTEM\LOG\JsonResult::ok() :
\SYSTEM\LOG\JsonResult::fail();
}
}

View File

@ -0,0 +1,8 @@
<?php
namespace SQL;
class MOJOTROLLZ_VOTE_INSERT extends \SYSTEM\DB\QP {
public static function get_class(){return \get_class();}
public static function mysql(){return
'INSERT INTO mojotrollz_vote (`server`,`ip`) VALUES(?,?) ON DUPLICATE KEY UPDATE server=VALUES(server);';
}
}

View File

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

View File

Before

Width:  |  Height:  |  Size: 27 KiB

After

Width:  |  Height:  |  Size: 27 KiB

View File

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View File

@ -6,9 +6,20 @@ class default_serverlist extends \SYSTEM\PAGE\Page {
public function html(){
$vars = array();
$vars['server_list'] = '';
$vote = \SQL\MOJOTROLLZ_IP_VOTED::Q1(array($_SERVER['REMOTE_ADDR']));
$vote_server = $vote ? $vote['server'] : null;
$res = \SQL\MOJOTROLLZ_SERVER_LIST::QQ();
while($row = $res->next()){
$row['version'] = self::version_icon($row['version']);
$row['btn_vote_color'] = 'btn-warning';
$row['glyphicon_vote'] = 'glyphicon-hand-up';
if(!$vote_server){
$row['btn_vote_color'] = 'btn-success';}
if($vote_server == $row['id']){
$row['btn_vote_color'] = 'btn-success';
$row['glyphicon_vote'] = 'glyphicon-ok';
}
$row['score'] += $row['votes'];
$vars['server_list'] .= \SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_serverlist/tpl/serverlist_tr.tpl'),$row);}
return \SYSTEM\PAGE\replace::replaceFile(SYSTEM\SERVERPATH(new PPAGE(),'default_serverlist/tpl/serverlist.tpl'), $vars);
}
@ -16,11 +27,11 @@ class default_serverlist extends \SYSTEM\PAGE\Page {
private static function version_icon($version){
switch($version){
case 0:
return 'wow_normal.png';
return '1.12.1';
case 1:
return 'wow_bc_normal.png';
return '2.4.3';
case 2:
return 'wow_wotlk_normal.png';
return '3.3.5a';
default:
return '';
}

View File

@ -20,4 +20,14 @@ function init_serverlist(){
event.preventDefault();
}
});
$(".btn_vote").click(function(){
$.getJSON('./api.php?call=mojo&action=vote&server='+$(this).attr('server'), function (data) {
if(data.status){
location.reload();
} else {
alert("An Error occurred. Could not vote for Server. You can only vote once per day!");
}
});
});
}

View File

@ -0,0 +1,8 @@
<?php
namespace SQL;
class MOJOTROLLZ_IP_VOTED extends \SYSTEM\DB\QP {
public static function get_class(){return \get_class();}
public static function mysql(){return
'SELECT * FROM mojotrollz_vote WHERE ip = ?;';
}
}

View File

@ -3,6 +3,10 @@ namespace SQL;
class MOJOTROLLZ_SERVER_LIST extends \SYSTEM\DB\QQ {
public static function get_class(){return \get_class();}
public static function mysql(){return
'SELECT * FROM mojotrollz_server WHERE visible IS NOT NULL AND version IS NOT NULL;';
'SELECT mojotrollz_server.*, COUNT(ip) as votes FROM mojotrollz_server'.
' LEFT JOIN mojotrollz_vote ON mojotrollz_server.id = mojotrollz_vote.server'.
' WHERE visible IS NOT NULL AND version IS NOT NULL'.
' GROUP BY id'.
' ORDER BY votes DESC, score DESC;';
}
}

View File

@ -1,9 +1,10 @@
<hr>
<h3>SERVERS</h3>
<table style="width: 100%;">
<table style="width: 100%;" class="sai_table">
<tr>
<th>Name</th>
<th>Version</th>
<th>Description</th>
<th>Score</th>
<th>Vote</th>
</tr>

View File

@ -1,8 +1,25 @@
<tr>
<td><a href="${url}" target="blank">${name}</a></td>
<td>
<img style="" data-pyroimage="true" src="./api.php?call=files&cat=content&id=${version}" alt="WoW" height="24" width="24">
<a href="${magnet_${version}">
<img style="" data-pyroimage="true" src="./api.php?call=files&cat=content&id=wow_${version}.png" alt="WoW" height="24" width="24">
&nbsp;&nbsp;${version}
</a>
</td>
<td>${description}</td>
<td>${score}</td>
<td>${vote}</td>
<td>
<button type="submit" class="btn_vote btn-sm btn ${btn_vote_color}" server="${id}">
<span class="glyphicon ${glyphicon_vote}" aria-hidden="true"></span>
&nbsp;&nbsp;Vote
</button>
<button type="submit" class="btn-sm btn btn-primary" onClick="location.href='${url}'">
<span class="glyphicon glyphicon-globe" aria-hidden="true"></span>
&nbsp;&nbsp;Visit
</button>
<button type="submit" class="btn-sm btn btn-primary" onClick="location.href='${magnet_${version}}'">
<span class="glyphicon glyphicon-arrow-down" aria-hidden="true"></span>
&nbsp;&nbsp;Download
</button>
</td>
</tr>

View File

@ -4,7 +4,7 @@
<div style="background-image: url(./api.php?call=files&cat=content&id=download_client.png); background-repeat: no-repeat; background-size: cover; float: left; width: 250px; height: 80px;">
<a href="${magnet_classic}">
<div style="padding-top:20px; padding-left: 75px; font-size: 16px;">
<img style="float:right; margin-right:20px;" data-pyroimage="true" src="./api.php?call=files&cat=content&id=wow_normal.png" alt="Windows" height="48" width="48">
<img style="float:right; margin-right:20px;" data-pyroimage="true" src="./api.php?call=files&cat=content&id=wow_1.12.1.png" alt="Windows" height="48" width="48">
<div><a href="${magnet_classic}">WoW 1.12.1</a></div>
<div style="font-size: 10px;">Download this file with <a href="http://www.qbittorrent.org/download.php" target="blank">qBittorrent</a></div>
</div>
@ -13,7 +13,7 @@
<div style="background-image: url(./api.php?call=files&cat=content&id=download_client.png); background-repeat: no-repeat; background-size: cover; float: left; width: 250px; height: 80px;">
<a href="${magnet_bc}">
<div style="padding-top:20px; padding-left: 75px; font-size: 16px;">
<img style="float:right; margin-right:20px;" data-pyroimage="true" src="./api.php?call=files&cat=content&id=wow_bc_normal.png" alt="Windows" height="48" width="48">
<img style="float:right; margin-right:20px;" data-pyroimage="true" src="./api.php?call=files&cat=content&id=wow_2.4.3.png" alt="Windows" height="48" width="48">
<div><a href="${magnet_bc}">WoW 2.4.3</a></div>
<div style="font-size: 10px;">Download this file with <a href="http://www.qbittorrent.org/download.php" target="blank">qBittorrent</a></div>
</div>
@ -22,7 +22,7 @@
<div style="background-image: url(./api.php?call=files&cat=content&id=download_client.png); background-repeat: no-repeat; background-size: cover; float: left; width: 250px; height: 80px;">
<a href="${magnet_wotlk}">
<div style="padding-top:20px; padding-left: 75px; font-size: 16px;">
<img style="float:right; margin-right:20px;" data-pyroimage="true" src="./api.php?call=files&cat=content&id=wow_wotlk_normal.png" alt="Windows" height="48" width="48">
<img style="float:right; margin-right:20px;" data-pyroimage="true" src="./api.php?call=files&cat=content&id=wow_3.3.5a.png" alt="Windows" height="48" width="48">
<div><a href="${magnet_wotlk}">WoW 3.3.5a</a></div>
<div style="font-size: 10px;">Download this file with <a href="http://www.qbittorrent.org/download.php" target="blank">qBittorrent</a></div>
</div>

View File

@ -5,6 +5,7 @@ class DATA_MOJOTROLLZ extends \SYSTEM\DB\QI {
public static function files_mysql(){
return array( \SYSTEM\SERVERPATH(new \PSQL(),'/mysql/system_page.sql'),
\SYSTEM\SERVERPATH(new \PSQL(),'/mysql/system_api.sql'),
\SYSTEM\SERVERPATH(new \PSQL(),'/mysql/schema_mojotrollz_server.sql'));
\SYSTEM\SERVERPATH(new \PSQL(),'/mysql/schema_mojotrollz_server.sql'),
\SYSTEM\SERVERPATH(new \PSQL(),'/mysql/schema_mojotrollz_vote.sql'));
}
}

View File

@ -3,11 +3,12 @@ CREATE TABLE `mojotrollz_server` (
`name` CHAR(50) NULL DEFAULT NULL,
`url` CHAR(50) NOT NULL,
`version` INT(11) NULL DEFAULT NULL,
`description` TEXT NULL,
`visible` INT(11) NULL DEFAULT NULL,
`score` INT(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=2
;
AUTO_INCREMENT=9
;

View File

@ -0,0 +1,7 @@
CREATE TABLE `mojotrollz_vote` (
`server` INT(11) NOT NULL,
`ip` CHAR(50) NOT NULL,
PRIMARY KEY (`ip`)
)
ENGINE=InnoDB
;

View File

@ -1 +1,2 @@
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (200, 0, 2, 11, 'newserver', 'address', 'STRING');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (200, 0, 2, 11, 'newserver', 'address', 'STRING');
INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (205, 0, 2, 11, 'vote', 'server', 'INT');