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

View File

View File

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

View File

@ -1,11 +1,22 @@
{extends file="layout.tpl"} {extends file="layout.tpl"}
{block name=head} {block name=head}
<link href="css/score.css" rel="stylesheet"> <link href="/css/score.css" rel="stylesheet">
{/block} {/block}
{block name=content} {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="row">
<div class="col-md-2"> <div class="col-md-2">
<h3>TOP #10</h3> <h3>TOP #10</h3>
@ -56,7 +67,7 @@
<div class="col-md-10"> <div class="col-md-10">
<div class="jumbotron"> <div class="jumbotron">
<h1>Example</h1> <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> <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} {block name=end}
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
var time = {$END};
$('#carousel-team').carousel({ $('#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> </script>
{/block} {/block}