Friday release
This commit is contained in:
parent
10eb72688f
commit
c349769425
16 changed files with 319 additions and 89 deletions
|
|
@ -18,6 +18,8 @@ function remove_themes($id)
|
|||
$db->query("DELETE FROM exercices WHERE id_theme = ".$id);
|
||||
$db->query("DELETE FROM themes WHERE id = ".$id);
|
||||
$db->deconnexion();
|
||||
|
||||
Cache::del("ordered_th".$id);
|
||||
}
|
||||
|
||||
if (!empty($_GET["delete"]))
|
||||
|
|
|
|||
|
|
@ -75,6 +75,23 @@ class Exercice
|
|||
}
|
||||
}
|
||||
|
||||
static function __set_state(array $array)
|
||||
{
|
||||
$tmp = new Exercice();
|
||||
|
||||
$tmp->id = $array["id"];
|
||||
$tmp->number = $array["number"];
|
||||
$tmp->theme = $array["theme"];
|
||||
$tmp->require = $array["require"];
|
||||
$tmp->level = $array["level"];
|
||||
$tmp->points = $array["points"];
|
||||
$tmp->statement = $array["statement"];
|
||||
$tmp->files = $array["files"];
|
||||
$tmp->keys = $array["keys"];
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
function get_id()
|
||||
{
|
||||
return $this->id;
|
||||
|
|
@ -89,10 +106,12 @@ class Exercice
|
|||
// trié par date
|
||||
function get_solved()
|
||||
{
|
||||
$db = new BDD();
|
||||
$id = $this->id;
|
||||
|
||||
$db = new BDD();
|
||||
$db->escape($id);
|
||||
$res = $db->query("SELECT `id_team`, `time` FROM solved
|
||||
WHERE id_exercice = '$this->id'
|
||||
WHERE id_exercice = '$id'
|
||||
ORDER BY time");
|
||||
|
||||
$db->deconnexion();
|
||||
|
|
@ -105,11 +124,13 @@ class Exercice
|
|||
if ($this->require == "")
|
||||
return 1;
|
||||
|
||||
$db = new BDD();
|
||||
$req = $this->require;
|
||||
|
||||
$db = new BDD();
|
||||
$db->escape($req);
|
||||
$res = $db->unique_query("SELECT `id` FROM solved
|
||||
WHERE id_team = '".intval($team->id)."'
|
||||
AND id_exercice = '$this->require'");
|
||||
AND id_exercice = '$req'");
|
||||
$db->deconnexion();
|
||||
if (empty($res))
|
||||
return 0;
|
||||
|
|
@ -118,9 +139,11 @@ class Exercice
|
|||
|
||||
function has_solved($team)
|
||||
{
|
||||
$db = new BDD();
|
||||
$id = $this->id;
|
||||
|
||||
$res = $db->unique_query("SELECT `time` FROM solved WHERE id_exercice = '$this->id'
|
||||
$db = new BDD();
|
||||
$db->escape($id);
|
||||
$res = $db->unique_query("SELECT `time` FROM solved WHERE id_exercice = '$id'
|
||||
AND id_team = ".intval($team->get_id()));
|
||||
|
||||
$db->deconnexion();
|
||||
|
|
@ -143,6 +166,7 @@ class Exercice
|
|||
do
|
||||
{
|
||||
array_push($checked, $exo);
|
||||
$db->escape($exo);
|
||||
$res = $db->unique_query("SELECT `require` FROM exercices WHERE id = '".$exo."'");
|
||||
$exo = $res['require'];
|
||||
$ret++;
|
||||
|
|
@ -278,6 +302,28 @@ class Exercice
|
|||
|
||||
return $res['max'];
|
||||
}
|
||||
|
||||
public function first_to_solve_exercice()
|
||||
{
|
||||
$db = new BDD();
|
||||
|
||||
$id = $this->id;
|
||||
$db->escape($id);
|
||||
|
||||
$res = $db->unique_query("SELECT t3.team_name as result
|
||||
FROM solved AS t1
|
||||
INNER JOIN (
|
||||
SELECT MIN(s.time) AS minTime
|
||||
FROM solved AS s
|
||||
WHERE s.id_exercice = '".$id."'
|
||||
) AS t2
|
||||
INNER JOIN teams AS t3 ON t1.id_team = t3.id
|
||||
WHERE t1.time = t2.minTime");
|
||||
$db->deconnexion();
|
||||
|
||||
return $res['result'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ExerciceNotFoundException extends Exception
|
||||
|
|
|
|||
|
|
@ -60,6 +60,22 @@ class Team
|
|||
}
|
||||
}
|
||||
|
||||
static function __set_state(array $array)
|
||||
{
|
||||
$tmp = new Team();
|
||||
|
||||
$tmp->id = $array["id"];
|
||||
$tmp->team_name = $array["team_name"];
|
||||
$tmp->key_hash = $array["key_hash"];
|
||||
$tmp->auth_level = $array["auth_level"];
|
||||
$tmp->slogan = $array["slogan"];
|
||||
$tmp->members = $array["members"];
|
||||
$tmp->points = $array["points"];
|
||||
$tmp->revoked = $array["revoked"];
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
// Class methods
|
||||
function update()
|
||||
{
|
||||
|
|
@ -274,14 +290,20 @@ class Team
|
|||
|
||||
public static function get_top($nb=0)
|
||||
{
|
||||
$teams = Team::get_teams();
|
||||
$top = Cache::read("top");
|
||||
if (empty($top))
|
||||
{
|
||||
$top = Team::get_teams();
|
||||
|
||||
usort($teams, "cmp_team_pts");
|
||||
usort($top, "cmp_team_pts");
|
||||
|
||||
Cache::set("top", $top);
|
||||
}
|
||||
|
||||
if ($nb != 0)
|
||||
$teams = array_slice($teams, 0, $nb);
|
||||
$top = array_slice($top, 0, $nb);
|
||||
|
||||
return $teams;
|
||||
return $top;
|
||||
}
|
||||
|
||||
public static function get_nb_teams()
|
||||
|
|
@ -292,21 +314,4 @@ class Team
|
|||
|
||||
return $res['count_teams'];
|
||||
}
|
||||
|
||||
public static function first_to_solve_exercice($id_exercice)
|
||||
{
|
||||
$db = new BDD();
|
||||
$res = $db->unique_query("SELECT t3.team_name as result
|
||||
FROM solved AS t1
|
||||
INNER JOIN (
|
||||
SELECT MIN(s.time) AS minTime
|
||||
FROM solved AS s
|
||||
WHERE s.id_exercice = ".$id_exercice."
|
||||
) AS t2
|
||||
INNER JOIN teams AS t3 ON t1.id_team = t3.id
|
||||
WHERE t1.time = t2.minTime");
|
||||
$db->deconnexion();
|
||||
|
||||
return $res['result'];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,16 @@ class Theme
|
|||
}
|
||||
}
|
||||
|
||||
static function __set_state(array $array)
|
||||
{
|
||||
$tmp = new Theme();
|
||||
|
||||
$tmp->id = $array["id"];
|
||||
$tmp->name = $array["name"];
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
function update()
|
||||
{
|
||||
$name = $this->name;
|
||||
|
|
@ -52,6 +62,8 @@ class Theme
|
|||
}
|
||||
$db->deconnexion();
|
||||
|
||||
Cache::del("ordered_th".$this->id);
|
||||
|
||||
return ($aff == 1);
|
||||
}
|
||||
|
||||
|
|
@ -93,6 +105,10 @@ class Theme
|
|||
|
||||
function get_exercices_ordered()
|
||||
{
|
||||
$res = Cache::read("ordered_th".$this->id);
|
||||
if (!empty($res))
|
||||
return $res;
|
||||
|
||||
$db = new BDD();
|
||||
$res = $db->query("SELECT E.id, E.require FROM exercices E
|
||||
INNER JOIN themes T ON T.id = E.id_theme
|
||||
|
|
@ -130,13 +146,14 @@ class Theme
|
|||
foreach($res as &$r)
|
||||
$r = new Exercice($r["id"]);
|
||||
|
||||
Cache::set("ordered_th".$this->id, $res);
|
||||
return $res;
|
||||
}
|
||||
|
||||
public static function get_themes()
|
||||
{
|
||||
$db = new BDD();
|
||||
$ids = $db->query("SELECT `id` FROM `themes`");
|
||||
$ids = $db->query("SELECT `id` FROM `themes` ORDER BY `name`");
|
||||
$db->deconnexion();
|
||||
|
||||
$array = array();
|
||||
|
|
|
|||
|
|
@ -2,34 +2,45 @@
|
|||
|
||||
class Cache
|
||||
{
|
||||
|
||||
|
||||
static function set($id,$var)
|
||||
{
|
||||
$file = '<?php $cache = '.var_export($var,TRUE).'; ?>';
|
||||
|
||||
file_put_contents(ONYX.'cache/'.md5($id).'.cache.php',$file) or trigger_error('dossier cache inaccessible en écriture.',E_USER_ERROR);
|
||||
|
||||
$tmpfname = tempnam("/tmp", "cache");
|
||||
|
||||
if(file_put_contents($tmpfname, $file, LOCK_EX) !== FALSE)
|
||||
rename($tmpfname, ONYX.'cache/'.md5($id).'.cache.php') or trigger_error('dossier cache inaccessible en écriture.',E_USER_ERROR);
|
||||
else
|
||||
trigger_error('impossible d\'?crire dans '.$tmpfname,E_USER_ERROR);
|
||||
}
|
||||
|
||||
|
||||
static function read($id)
|
||||
{
|
||||
if(!is_readable(ONYX.'cache/'.md5($id).'.cache.php')) return FALSE;
|
||||
|
||||
include(ONYX.'cache/'.md5($id).'.cache.php');
|
||||
if(!$cache) return FALSE;
|
||||
|
||||
$tmpfname = tempnam("/tmp", "cache");
|
||||
copy(ONYX.'cache/'.md5($id).'.cache.php', $tmpfname);
|
||||
|
||||
include($tmpfname);
|
||||
|
||||
unlink($tmpfname);
|
||||
|
||||
if(empty($cache)) return FALSE;
|
||||
return $cache;
|
||||
}
|
||||
|
||||
|
||||
static function del($id)
|
||||
{
|
||||
if(!is_file(ONYX.'cache/'.md5($id).'.cache.php')) return FALSE;
|
||||
return unlink(ONYX.'cache/'.md5($id).'.cache.php');
|
||||
}
|
||||
|
||||
|
||||
static function flush()
|
||||
{
|
||||
foreach(glob(ONYX.'cache/*.cache.php') as $file) unlink($file);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -1,9 +1,13 @@
|
|||
{extends file="public/layout.tpl"}
|
||||
|
||||
{block name=main}
|
||||
<div class="well">
|
||||
|
||||
<table class="table" style="font-size: 12px;">
|
||||
{if isset($teams)}
|
||||
<div id="carousel-team" class="carousel slide">
|
||||
<div class="carousel-inner">
|
||||
|
||||
<div class="item active">
|
||||
<div class="well">
|
||||
<table class="table" style="font-size: 14px;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
|
|
@ -21,7 +25,7 @@
|
|||
{foreach from=$theme->get_exercices_ordered() item=exo}
|
||||
{$teamName=""}
|
||||
{for $i=0 to $nbExoMax}
|
||||
{$teamName=Team::first_to_solve_exercice($exo->get_id())}
|
||||
{$teamName=$exo->first_to_solve_exercice()}
|
||||
{/for}
|
||||
{if $teamName != ""}
|
||||
<td class="success text-center">{$teamName}</td>
|
||||
|
|
@ -33,6 +37,20 @@
|
|||
{/foreach}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{foreach from=$teams item=my_team key=k}
|
||||
<div class="item">
|
||||
<div class="well">
|
||||
{include file="summary.tpl"}
|
||||
</div>
|
||||
</div>
|
||||
{/foreach}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
|
||||
|
||||
{/block}
|
||||
|
|
|
|||
|
|
@ -17,32 +17,23 @@
|
|||
{/if}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-2">
|
||||
<div class="col-md-3">
|
||||
<h3>Top 10</h3>
|
||||
<div class="list-group">
|
||||
{foreach from=$top item=t key=k}
|
||||
<div class="list-group-item">{$k+1}. {link href="{$t->id}-{$t->get_name()}" href_prefix="/" label=$t->get_name()}</div>
|
||||
<div class="list-group-item">{$k+1}. {link href="{$t->id}-{$t->get_name()}" href_prefix="/" label=$t->get_name()}
|
||||
<span class="badge">
|
||||
{$t->get_pts()}
|
||||
</span>
|
||||
</div>
|
||||
{/foreach}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-10">
|
||||
<div class="col-md-9">
|
||||
{block name=main}{/block}
|
||||
</div>
|
||||
</div>
|
||||
{if isset($teams)}
|
||||
<div id="carousel-team" class="carousel slide">
|
||||
<div class="carousel-inner">
|
||||
{foreach from=$teams item=my_team key=k}
|
||||
<div class="item{if $k == 0} active{/if}">
|
||||
<div class="well">
|
||||
{include file="summary.tpl"}
|
||||
</div>
|
||||
</div>
|
||||
{/foreach}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/block}
|
||||
|
||||
|
|
@ -54,7 +45,7 @@
|
|||
$(document).ready(function() {
|
||||
update_end();
|
||||
$('#carousel-team').carousel({
|
||||
interval: 5000 });
|
||||
interval: 10000 });
|
||||
|
||||
setInterval( function() {
|
||||
update_end();
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
{block name=main}
|
||||
<div>
|
||||
<h1>{$my_team->get_name()}</h1>
|
||||
{include file="summary.tpl"}
|
||||
</div>
|
||||
{/block}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<table class="table" style="font-size: 12px; padding: 10px; margin-bottom: 10px;">
|
||||
<table class="table" style="font-size: 14px; padding: 10px; margin-bottom: 10px;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="font-size: 15px">{$my_team->get_name()}</th>
|
||||
<th style="font-size: 30px">{$my_team->get_name()}</th>
|
||||
{for $i=1 to $nbExoMax}
|
||||
<th class="text-center">Exercice {$i}</th>
|
||||
{/for}
|
||||
|
|
@ -12,7 +12,7 @@
|
|||
{$total=0}
|
||||
{foreach from=$themes item=theme}
|
||||
<tr>
|
||||
<th style="padding: 0px">{$theme->get_name()}</th>
|
||||
<th>{$theme->get_name()}</th>
|
||||
{$sum=0}
|
||||
{$cpt=0}
|
||||
{$themeID=$theme->get_id()}
|
||||
|
|
@ -43,8 +43,8 @@
|
|||
</tbody>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th colspan="{$nbExoMax+1}" style="text-align: right">Total :</th>
|
||||
<th class="active text-center">{$total}</th>
|
||||
<th colspan="{$nbExoMax+1}" style="text-align: right; font-size: 30px">Total :</th>
|
||||
<th class="active text-center" style="font-size: 30px">{$total}</th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
<div class="panel-body">
|
||||
<ul>
|
||||
<li><strong>Gain :</strong> {$cur_exercice->points}</li>
|
||||
<li><strong>Description :</strong> {$cur_exercice->statement}</li>
|
||||
<li><strong>Description :</strong> {$cur_exercice->statement|escape|nl2br}</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Reference in a new issue