From 2d77512cdc59679b54853370b366f1e0c5350098 Mon Sep 17 00:00:00 2001
From: Li Chen
Date: Tue, 12 Nov 2013 16:52:50 +0100
Subject: [PATCH] Code cleaned
---
htdocs/index.php | 2 +-
onyx/include/common/Exercice.class.php | 9 ++--
onyx/include/common/Team.class.php | 61 +++++++++++------------
onyx/include/common/Theme.class.php | 16 +++---
onyx/include/public/home.php | 2 +-
onyx/include/public/score.php | 2 +-
onyx/include/team/summary.php | 5 +-
onyx/tpl/bootstrap/admin/export_theme.tpl | 4 +-
onyx/tpl/bootstrap/admin/layout.tpl | 2 +-
onyx/tpl/bootstrap/admin/themes.tpl | 2 +-
onyx/tpl/bootstrap/summary.tpl | 10 ++--
onyx/tpl/bootstrap/teams/layout.tpl | 4 +-
onyx/tpl/bootstrap/teams/theme.tpl | 2 +-
13 files changed, 58 insertions(+), 63 deletions(-)
diff --git a/htdocs/index.php b/htdocs/index.php
index afbc718d..6d82dcdb 100644
--- a/htdocs/index.php
+++ b/htdocs/index.php
@@ -132,7 +132,7 @@ else if ($n && $p[0] == SALT_USER)
$id_exo = $p[3];
else if ($n == 3)
{
- foreach($THEME->get_exercicesOrdered() as $exo)
+ foreach($THEME->get_exercices_ordered() as $exo)
{
if (! $exo->has_solved($TEAM))
break;
diff --git a/onyx/include/common/Exercice.class.php b/onyx/include/common/Exercice.class.php
index ba648405..8d8bf053 100644
--- a/onyx/include/common/Exercice.class.php
+++ b/onyx/include/common/Exercice.class.php
@@ -19,8 +19,10 @@ class Exercice
if (!empty($id))
{
$db = new BDD();
- // TODO escape id ?
- $res = $db->unique_query("SELECT id, id_theme, `require`, level, points, statement
+
+ $db->escape($id);
+ $res = $db->unique_query("SELECT `id`, `id_theme`, `require`, `level`,
+ `points`, `statement`
FROM exercices WHERE id = '$id'");
if (!empty($res))
@@ -81,7 +83,6 @@ class Exercice
{
$db = new BDD();
- // TODO rename time by date in db ?
$res = $db->query("SELECT `id_team`, `time` FROM solved
WHERE id_exercice = '$this->id'
ORDER BY time");
@@ -256,7 +257,7 @@ class Exercice
);
}
- public static function get_nbExoMax()
+ public static function get_nb_exo_max()
{
$db = new BDD();
$res = $db->unique_query("SELECT count(id) AS max FROM exercices
diff --git a/onyx/include/common/Team.class.php b/onyx/include/common/Team.class.php
index 3ad00c13..7494898a 100644
--- a/onyx/include/common/Team.class.php
+++ b/onyx/include/common/Team.class.php
@@ -28,8 +28,8 @@ class Team
if (!empty($id))
{
$db = new BDD();
- $res = $db->unique_query("SELECT id, team_name, key_hash, slogan, auth_level
- FROM teams WHERE id=" . intval($id)) or die($db->erreur());
+ $res = $db->unique_query("SELECT `id`, `team_name`, `key_hash`, `slogan`, `auth_level`
+ FROM teams WHERE id = ".intval($id)) or die($db->erreur());
if (!empty($res))
{
@@ -97,8 +97,8 @@ class Team
{
$db = new BDD();
- $res = $db->query("SELECT id FROM team_members
- WHERE id_team = " . intval($this->id));
+ $res = $db->query("SELECT `id` FROM team_members
+ WHERE id_team = ".intval($this->id));
$db->deconnexion();
@@ -115,11 +115,11 @@ class Team
{
$db = new BDD();
- $res = $db->unique_query("SELECT e.id, s.id_team, SUM(e.points) as sum_points
- FROM exercices e
- LEFT OUTER JOIN solved s ON e.id = s.id_exercice
- WHERE s.id_team = " . $this->id . "
- GROUP BY s.id_team");
+ $res = $db->unique_query("SELECT E.id, S.id_team, SUM(E.points) as sum_points
+ FROM exercices E
+ LEFT OUTER JOIN solved S ON E.id = S.id_exercice
+ WHERE S.id_team = ".$this->id."
+ GROUP BY S.id_team");
$db->deconnexion();
@@ -132,7 +132,7 @@ class Team
return $this->points;
}
- function get_groupIds()
+ function get_group_ids()
{
$db = new BDD();
@@ -154,42 +154,40 @@ class Team
return 0;
}
- function get_nbResExercisesByTheme($id_theme)
+ function get_nb_res_exercises_by_theme($id_theme)
{
$db = new BDD();
- $res = $db->unique_query("SELECT e.id_theme AS theme, count( s.id ) AS solved
- FROM solved AS s
- RIGHT OUTER JOIN exercices AS e ON e.id = s.id_exercice
- AND s.id_team = ".$this->id."
- AND e.id_theme = ".$id_theme);
-
+ $res = $db->unique_query("SELECT E.id_theme AS theme, count(S.id) AS solved
+ FROM solved S
+ RIGHT OUTER JOIN exercices E ON E.id = S.id_exercice
+ AND S.id_team = ".$this->id."
+ AND E.id_theme = ".$id_theme);
$db->deconnexion();
return $res['solved'];
}
- function get_solvedExercices($id_theme=-1)
+ function get_solved_exercices($id_theme=-1)
{
if ($id_theme != -1)
{
$db = new BDD();
- $ids = $db->query("SELECT id_theme, id_exercice
- FROM `solved`
- LEFT OUTER JOIN exercices ON `solved`.id_exercice = `exercices`.id
+ $ids = $db->query("SELECT `id_theme`, `id_exercice`
+ FROM solved S
+ LEFT OUTER JOIN exercices E ON S.id_exercice = E.id
WHERE id_team =".$this->id." AND id_theme =".$id_theme);
$db->deconnexion();
- $array = array();
- $i = 0;
- if ($ids)
- {
- foreach ($ids as $id){
- $array[] = new Exercice($id['id_exercice']);
+ $array = array();
+ $i = 0;
+ if ($ids)
+ {
+ foreach ($ids as $id){
+ $array[] = new Exercice($id['id_exercice']);
+ }
}
- }
-
- return $array;
+ return $array;
}
return NULL;
}
@@ -226,7 +224,7 @@ class Team
return $teams;
}
- public static function get_nbTeams()
+ public static function get_nb_teams()
{
$db = new BDD();
$res = $db->unique_query("SELECT COUNT(id) as count_teams FROM teams");
@@ -234,5 +232,4 @@ class Team
return $res['count_teams'];
}
-
}
diff --git a/onyx/include/common/Theme.class.php b/onyx/include/common/Theme.class.php
index a8faa3fc..1c470bc1 100644
--- a/onyx/include/common/Theme.class.php
+++ b/onyx/include/common/Theme.class.php
@@ -12,7 +12,7 @@ class Theme
if (!empty($id))
{
$db = new BDD();
- $res = $db->unique_query("SELECT id, name
+ $res = $db->unique_query("SELECT `id`, `name`
FROM themes WHERE id=" . intval($id));
if (!empty($res))
@@ -41,8 +41,8 @@ class Theme
else
{
$db->query("UPDATE themes
- SET name = '".$name."'
- WHERE id = ".intval($this->id));
+ SET name = '".$name."'
+ WHERE id = ".intval($this->id));
$aff = $db->affected();
}
$db->deconnexion();
@@ -60,12 +60,12 @@ class Theme
return $this->id;
}
- function get_nbExercices()
+ function get_nb_exercices()
{
$db = new BDD();
- $res = $db->unique_query("SELECT count( id ) as nb_exercices FROM exercices
- WHERE id_theme = ".$this->id."
- GROUP BY id_theme");
+ $res = $db->unique_query("SELECT count(id) as nb_exercices FROM exercices
+ WHERE id_theme = ".$this->id."
+ GROUP BY id_theme");
$db->deconnexion();
return $res['nb_exercices'];
@@ -81,7 +81,7 @@ class Theme
return false;
}
- function get_exercicesOrdered()
+ function get_exercices_ordered()
{
$db = new BDD();
$res = $db->query("SELECT E.id, E.require FROM exercices E
diff --git a/onyx/include/public/home.php b/onyx/include/public/home.php
index 28d73005..9eb09a20 100644
--- a/onyx/include/public/home.php
+++ b/onyx/include/public/home.php
@@ -5,6 +5,6 @@ if(!defined('ONYX')) exit;
$template->assign("teams", Team::get_teams());
$template->assign("top", Team::get_top(10));
$template->assign("themes", Theme::get_themes());
-$template->assign("nbExoMax", Exercice::get_nbExoMax());
+$template->assign("nbExoMax", Exercice::get_nb_exo_max());
return "public/home";
diff --git a/onyx/include/public/score.php b/onyx/include/public/score.php
index 8de656dd..3a435ef8 100644
--- a/onyx/include/public/score.php
+++ b/onyx/include/public/score.php
@@ -3,7 +3,7 @@
if(!defined('ONYX')) exit;
$template->assign("themes", Theme::get_themes());
-$template->assign("nbExoMax", Exercice::get_nbExoMax());
+$template->assign("nbExoMax", Exercice::get_nb_exo_max());
$template->assign("my_team", new TEAM($TEAM));
diff --git a/onyx/include/team/summary.php b/onyx/include/team/summary.php
index b978ddcb..4403c9ca 100644
--- a/onyx/include/team/summary.php
+++ b/onyx/include/team/summary.php
@@ -2,10 +2,7 @@
if(!defined('ONYX')) exit;
-//$solvedExercices = $TEAM->get_solvedExercices();
-
$template->assign("themes", Theme::get_themes());
-$template->assign("nbExoMax", Exercice::get_nbExoMax());
-//$template->assign("solvedExercices", $solvedExercices);
+$template->assign("nbExoMax", Exercice::get_nb_exo_max());
return "teams/summary";
diff --git a/onyx/tpl/bootstrap/admin/export_theme.tpl b/onyx/tpl/bootstrap/admin/export_theme.tpl
index b05e988f..208ac16a 100644
--- a/onyx/tpl/bootstrap/admin/export_theme.tpl
+++ b/onyx/tpl/bootstrap/admin/export_theme.tpl
@@ -1,8 +1,8 @@
{$theme->get_name()}
- {if $theme->get_exercicesOrdered()}
- {foreach from=$theme->get_exercicesOrdered() item=e}
+ {if $theme->get_exercices_ordered()}
+ {foreach from=$theme->get_exercices_ordered() item=e}
require} depends="{$e->require}"{/if}>
{$e->get_name()}
{$e->points}
diff --git a/onyx/tpl/bootstrap/admin/layout.tpl b/onyx/tpl/bootstrap/admin/layout.tpl
index e0bf8cbf..f8192f72 100644
--- a/onyx/tpl/bootstrap/admin/layout.tpl
+++ b/onyx/tpl/bootstrap/admin/layout.tpl
@@ -20,7 +20,7 @@
{$my_team->get_pts()} pointsSynthèse
- {$my_team->get_rank()}e sur {Team::get_nbTeams()}
+ {$my_team->get_rank()}e sur {Team::get_nb_teams()}