Add get_teams and get_top functions for User class

This commit is contained in:
Quentin Grosyeux 2013-10-22 07:58:39 +02:00
parent b69ecd3e70
commit 68dcb996c9
7 changed files with 156 additions and 23 deletions

View File

@ -1,3 +1,74 @@
body {
.clock {
background:#202020;
margin: 0 auto;
padding: 30px;
border: 1px solid #333;
color: #fff;
}
#Date {
background:#202020;
font-family: bold, sans-serif;
text-align:center;
text-shadow:0 0 5px #00c6ff;
}
#Date + ul {
width: 800px;
margin: 0 auto;
padding: 0px;
list-style: none;
text-align: center;
}
#Date + ul li {
display: inline;
font-size: 5em;
text-align: center;
font-family: sans-serif;
text-shadow: 0 0 5px #00c6ff;
}
#point {
position: relative;
-moz-animation: mymove 1s ease infinite;
-webkit-animation: mymove 1s ease infinite;
padding-left: 10px;
padding-right: 10px;
}
/* Simple Animation */
@-webkit-keyframes mymove {
0% {
opacity: 1.0;
text-shadow: 0 0 20px #00c6ff;
}
50% {
opacity: 0;
text-shadow: none;
}
100% {
opacity: 1.0;
text-shadow: 0 0 20px #00c6ff;
}
}
@-moz-keyframes mymove {
0% {
opacity: 1.0;
text-shadow: 0 0 20px #00c6ff;
}
50% {
opacity: 0;
text-shadow: none;
}
100% {
opacity: 1.0;
text-shadow: 0 0 20px #00c6ff;
};
}

View File

@ -2,7 +2,7 @@
if(!defined('ONYX')) exit;
class User
class Team
{
var $id = null;
var $firstname;
@ -13,7 +13,8 @@ class User
var $points = null;
var $nb_themes = null;
function User ($id=null)
// Constructor
function Team ($id=null)
{
if (!empty($id))
{
@ -33,6 +34,7 @@ class User
}
}
// Class methods
function update()
{
$username = $this->username;
@ -110,29 +112,53 @@ class User
}
}
function get_groupIds()
{
$db = new BDD();
$res = $db->query("SELECT `id` FROM `users`");
$db->deconnexion();
return $res['id'];
}
function authenticate($certificate)
{
//TODO
}
// Points par theme (theme, user, sum_points)
//$res = $db->query("SELECT e.id_theme, s.id_user, SUM(e.points) as sum_points
//FROM exercices e
//LEFT OUTER JOIN solved s ON e.id = s.id_exercice
//WHERE s.id_user = " . intval($this->id) . "
//GROUP BY s.id_user, e.id_theme");
// Static methods
public static function get_teams()
{
$db = new BDD();
$ids = $db->query("SELECT `id` FROM `users`");
$db->deconnexion();
$array = array();
foreach ($ids as $id){
$array[] = new Team($id['id']);
}
//SELECT e.id_theme,
// (select e.points from exercices where e.id=???),
// (select e.points from exercices where e.id=???),
// (select e.points from exercices where e.id=???),
// (select e.points from exercices where e.id=???),
// (select e.points from exercices where e.id=???)
// (select max(e.points) from exercices)
//FROM exercices e
//LEFT OUTER JOIN solved s ON e.id = s.id_exercice
//WHERE s.id_user = " . intval($this->id) . "
//GROUP BY s.id_user, e.id_theme");
return $array;
}
// TODO: Not tested, need feeding BDD
public static function get_top()
{
function cmp($i1, $i2)
{
if ($i1->get_pts() == $i2->get_pts()){
return 0;
}
else{
return ($i1->get_pts() < $i2->get_pts) ? -1 : 1;
}
}
$teams = $this->get_teams();
usort($teams, "cmp");
return $teams;
}
}

View File

@ -2,6 +2,11 @@
if(!defined('ONYX')) exit;
$t = Team::get_teams();
foreach ($t as $tt){
var_dump ($tt->get_username());
}
if ($SESS->level < 1)
{
$page = "public/home";

View File

View File

@ -19,7 +19,11 @@
<li><a href="#contact">Contact</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
{if $auth_lvl gt 0}
<li><a href="/disconnect">Se deconnecter</a></li>
{else}
<li><a href="/login">Login</a></li>
{/if}
</ul>
</div><!--/.nav-collapse -->
</div>
@ -31,5 +35,8 @@
<i class="icon-warning-sign"></i> {$ERRmessage}
</div>
{/if}
<div class="container">
{block name=content}{/block}
</div>
{/block}

View File

@ -1,11 +1,22 @@
{extends file="layout.tpl"}
{block name=head}
<link href="css/score.css" rel="stylesheet">
<link href="/css/score.css" rel="stylesheet">
{/block}
{block name=content}
<div class="clock">
<div id="Date"></div>
<ul>
<li id="hours">00</li>
<li id="point">:</li>
<li id="min">00</li>
<li id="point">:</li>
<li id="sec">00</li>
</ul>
</div>
<div class="row">
<div class="col-md-2">
<h3>TOP #10</h3>
@ -56,7 +67,7 @@
<div class="col-md-10">
<div class="jumbotron">
<h1>Example</h1>
<p>This is a example</p>
<p><div id="test">This is a example</div></p>
<p>This is a example</p>
<p>This is a example</p>
<p>This is a example</p>
@ -103,8 +114,21 @@
{block name=end}
<script type="text/javascript">
$(document).ready(function() {
var time = {$END};
$('#carousel-team').carousel({
interval: 4000 })
interval: 2000 });
setInterval( function() {
var heure = Math.floor(time / 3600);
var min = Math.floor((time / 60) % 60);
var sec = Math.floor(time % 60);
$("#hours").html(( heure < 10 ? "0" : "" ) + heure);
$("#min").html(( min < 10 ? "0" : "" ) + min);
$("#sec").html(( sec < 10 ? "0" : "" ) + sec);
time--;
}, 1000);
});
</script>
{/block}