From b81af5aa9072df0669c52d4fe906b60bca603a72 Mon Sep 17 00:00:00 2001 From: nemunaire Date: Sun, 14 Dec 2014 11:04:17 +0100 Subject: [PATCH] Store exercice title XML in DB --- db/feed.sql | 81 ++++++++++++----------- db/fic2014.sql | 1 + onyx/include/admin/exercice.php | 1 + onyx/include/common/Exercice.class.php | 21 ++++-- onyx/tpl/bootstrap/admin/exercice.tpl | 6 +- onyx/tpl/bootstrap/admin/export_theme.tpl | 2 +- onyx/tpl/bootstrap/admin/layout.tpl | 2 +- onyx/tpl/bootstrap/admin/themes.tpl | 2 +- onyx/tpl/bootstrap/teams/exercice.tpl | 2 +- onyx/tpl/bootstrap/teams/theme.tpl | 6 +- 10 files changed, 69 insertions(+), 55 deletions(-) diff --git a/db/feed.sql b/db/feed.sql index bb064b01..a76b5e18 100644 --- a/db/feed.sql +++ b/db/feed.sql @@ -128,49 +128,50 @@ INSERT INTO `exercices` ( `require` , `level` , `points` , +`title`, `statement` ) VALUES -('1', '1', '', '1', '1', 'Description 1'), -('2', '1', '1', '2', '5', 'Description 2'), -('3', '1', '2', '3', '10', 'Description 3'), -('4', '1', '3', '4', '20', 'Description 4'), -('5', '1', '4', '5', '40', 'Description 5'), -('6', '2', '', '1', '1', 'Description 6'), -('7', '2', '6', '2', '5', 'Description 7'), -('8', '2', '7', '3', '10', 'Description 8'), -('9', '2', '8', '4', '20', 'Description 9'), -('10', '2', '9', '5', '40', 'Description 10'), -('11', '3', '', '1', '1', 'Description 11'), -('12', '3', '11', '2', '5', 'Description 12'), -('13', '3', '12', '3', '10', 'Description 13'), -('14', '3', '13', '4', '20', 'Description 14'), -('15', '3', '14', '5', '40', 'Description 15'), -('16', '4', '', '1', '1', 'Description 16'), -('17', '4', '16', '2', '5', 'Description 17'), -('18', '4', '17', '3', '10', 'Description 18'), -('19', '4', '18', '4', '20', 'Description 19'), -('20', '4', '19', '5', '40', 'Description 20'), -('21', '5', '', '1', '1', 'Description 21'), -('22', '5', '23', '2', '5', 'Description 22'), -('23', '5', '25', '3', '10', 'Description 23'), -('24', '5', '21', '4', '20', 'Description 24'), -('25', '5', '24', '5', '40', 'Description 25'), -('26', '6', '', '1', '1', 'Description 26'), -('27', '6', '26', '2', '5', 'Description 27'), -('28', '6', '28', '3', '10', 'Description 28'), -('29', '6', '27', '4', '20', 'Description 29'), -('30', '6', '29', '5', '40', 'Description 30'), -('31', '7', '', '1', '1', 'Description 31'), -('32', '7', '35', '2', '5', 'Description 32'), -('33', '7', '31', '3', '10', 'Description 33'), -('34', '7', '32', '4', '20', 'Description 34'), -('35', '7', '33', '5', '40', 'Description 35'), -('36', '8', '', '1', '1', 'Description 36'), -('37', '8', '40', '2', '5', 'Description 37'), -('38', '8', '36', '3', '10', 'Description 38'), -('39', '8', '37', '4', '20', 'Description 39'), -('40', '8', '38', '5', '40', 'Description 40'); +('1', '1', '', '1', '1', 'Title X', 'Description 1'), +('2', '1', '1', '2', '5', 'Title X', 'Description 2'), +('3', '1', '2', '3', '10', 'Title X', 'Description 3'), +('4', '1', '3', '4', '20', 'Title X', 'Description 4'), +('5', '1', '4', '5', '40', 'Title X', 'Description 5'), +('6', '2', '', '1', '1', 'Title X', 'Description 6'), +('7', '2', '6', '2', '5', 'Title X', 'Description 7'), +('8', '2', '7', '3', '10', 'Title X', 'Description 8'), +('9', '2', '8', '4', '20', 'Title X', 'Description 9'), +('10', '2', '9', '5', '40', 'Title X', 'Description 10'), +('11', '3', '', '1', '1', 'Title X', 'Description 11'), +('12', '3', '11', '2', '5', 'Title X', 'Description 12'), +('13', '3', '12', '3', '10', 'Title X', 'Description 13'), +('14', '3', '13', '4', '20', 'Title X', 'Description 14'), +('15', '3', '14', '5', '40', 'Title X', 'Description 15'), +('16', '4', '', '1', '1', 'Title X', 'Description 16'), +('17', '4', '16', '2', '5', 'Title X', 'Description 17'), +('18', '4', '17', '3', '10', 'Title X', 'Description 18'), +('19', '4', '18', '4', '20', 'Title X', 'Description 19'), +('20', '4', '19', '5', '40', 'Title X', 'Description 20'), +('21', '5', '', '1', '1', 'Title X', 'Description 21'), +('22', '5', '23', '2', '5', 'Title X', 'Description 22'), +('23', '5', '25', '3', '10', 'Title X', 'Description 23'), +('24', '5', '21', '4', '20', 'Title X', 'Description 24'), +('25', '5', '24', '5', '40', 'Title X', 'Description 25'), +('26', '6', '', '1', '1', 'Title X', 'Description 26'), +('27', '6', '26', '2', '5', 'Title X', 'Description 27'), +('28', '6', '28', '3', '10', 'Title X', 'Description 28'), +('29', '6', '27', '4', '20', 'Title X', 'Description 29'), +('30', '6', '29', '5', '40', 'Title X', 'Description 30'), +('31', '7', '', '1', '1', 'Title X', 'Description 31'), +('32', '7', '35', '2', '5', 'Title X', 'Description 32'), +('33', '7', '31', '3', '10', 'Title X', 'Description 33'), +('34', '7', '32', '4', '20', 'Title X', 'Description 34'), +('35', '7', '33', '5', '40', 'Title X', 'Description 35'), +('36', '8', '', '1', '1', 'Title X', 'Description 36'), +('37', '8', '40', '2', '5', 'Title X', 'Description 37'), +('38', '8', '36', '3', '10', 'Title X', 'Description 38'), +('39', '8', '37', '4', '20', 'Title X', 'Description 39'), +('40', '8', '38', '5', '40', 'Title X', 'Description 40'); INSERT INTO `solved` ( `id` , diff --git a/db/fic2014.sql b/db/fic2014.sql index ea48d5c5..fc5713ac 100644 --- a/db/fic2014.sql +++ b/db/fic2014.sql @@ -26,6 +26,7 @@ CREATE TABLE IF NOT EXISTS `exercices` ( `require` varchar(100) COLLATE utf8_unicode_ci NULL, `level` tinyint(4) NOT NULL, `points` smallint(6) NOT NULL, + `title` varchar(255) COLLATE utf8_unicode_ci NULL, `statement` text COLLATE utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; diff --git a/onyx/include/admin/exercice.php b/onyx/include/admin/exercice.php index 1259b9f5..e87e894b 100644 --- a/onyx/include/admin/exercice.php +++ b/onyx/include/admin/exercice.php @@ -26,6 +26,7 @@ try if (!empty($_POST)) { $exercice->points = intval($_POST["points"]); + $exercice->title = $_POST["title"]; $exercice->statement = $_POST["desc"]; $exercice->require = $_POST["require"]; $exercice->level = intval($_POST["level"]); diff --git a/onyx/include/common/Exercice.class.php b/onyx/include/common/Exercice.class.php index eef3827b..e924968e 100644 --- a/onyx/include/common/Exercice.class.php +++ b/onyx/include/common/Exercice.class.php @@ -10,6 +10,7 @@ class Exercice var $require; var $level; var $points; + var $title; var $statement; var $files = array(); var $keys = array(); @@ -24,7 +25,7 @@ class Exercice $db->escape($id); $res = $db->unique_query("SELECT `id`, `id_theme`, `require`, `level`, - `points`, `statement` + `points`, `title`, `statement` FROM exercices WHERE id = '$id'"); if (!empty($res)) @@ -64,6 +65,7 @@ class Exercice $this->require = $res['require']; $this->level = $res['level']; $this->points = $res['points']; + $this->title = $res['title']; $this->statement = $res['statement']; $this->set_number(); @@ -86,6 +88,7 @@ class Exercice $tmp->require = $array["require"]; $tmp->level = $array["level"]; $tmp->points = $array["points"]; + $tmp->title = $array["title"]; $tmp->statement = $array["statement"]; $tmp->files = $array["files"]; $tmp->keys = $array["keys"]; @@ -98,9 +101,12 @@ class Exercice return $this->id; } - function get_name() + function get_title($menu=false) { - return "Exercice ".$this->number; + if ($menu || empty($this->title)) + return "Exercice ".$this->number; + else + return $this->title; } function get_statement() @@ -108,8 +114,7 @@ class Exercice return $this->statement; } - // retourne le nombre d'equipes qui ont résolues l'exercice - // trié par date + // retourne les équipes qui ont résolues l'exercice triées par date function get_solved() { $id = $this->id; @@ -209,6 +214,7 @@ class Exercice $require = $this->require; $level = intval($this->level); $points = intval($this->points); + $title = $this->title; $statement = $this->statement; $files = $this->files; $keys = $this->keys; @@ -217,17 +223,18 @@ class Exercice $db->escape($id); $db->escape($theme); $db->escape($require); + $db->escape($title); $db->escape($statement); if ($create) { $db->query("INSERT INTO exercices - VALUES ('".$id."', '".$theme."', '".$require."', '".$level."', '".$points."','".$statement."');"); + VALUES ('".$id."', '".$theme."', '".$require."', '".$level."', '".$points."','".$title."','".$statement."');"); } else { $db->query("UPDATE exercices - SET `id_theme` = '".$theme."', `require` = '".$require."', `level` = '".$level."', `points` = '".$points."', `statement` = '".$statement."' + SET `id_theme` = '".$theme."', `require` = '".$require."', `level` = '".$level."', `points` = '".$points."', `title` = '".$title."', `statement` = '".$statement."' WHERE id = '$id'"); $aff = $db->affected(); diff --git a/onyx/tpl/bootstrap/admin/exercice.tpl b/onyx/tpl/bootstrap/admin/exercice.tpl index affd82af..cb11fcbe 100644 --- a/onyx/tpl/bootstrap/admin/exercice.tpl +++ b/onyx/tpl/bootstrap/admin/exercice.tpl @@ -3,6 +3,10 @@ {if isset($ex)}

{$theme->name} {$ex->id}

+
+ + +
@@ -85,7 +89,7 @@

diff --git a/onyx/tpl/bootstrap/admin/export_theme.tpl b/onyx/tpl/bootstrap/admin/export_theme.tpl index 208ac16a..5e86eaaa 100644 --- a/onyx/tpl/bootstrap/admin/export_theme.tpl +++ b/onyx/tpl/bootstrap/admin/export_theme.tpl @@ -4,7 +4,7 @@ {if $theme->get_exercices_ordered()} {foreach from=$theme->get_exercices_ordered() item=e} require} depends="{$e->require}"{/if}> - {$e->get_name()} + {$e->get_title()} {$e->points} {$e->statement} {if $e->keys} diff --git a/onyx/tpl/bootstrap/admin/layout.tpl b/onyx/tpl/bootstrap/admin/layout.tpl index db385e5d..d56229cd 100644 --- a/onyx/tpl/bootstrap/admin/layout.tpl +++ b/onyx/tpl/bootstrap/admin/layout.tpl @@ -39,7 +39,7 @@ {link href_prefix="/{$SALT_ADMIN}/" href="ex/{$t->get_id()}-{$t->get_name()}" class="dropdown-toggle" data-toggle="dropdown" label="{$t->get_name()} "} diff --git a/onyx/tpl/bootstrap/admin/themes.tpl b/onyx/tpl/bootstrap/admin/themes.tpl index 939638d5..be5fa1c7 100644 --- a/onyx/tpl/bootstrap/admin/themes.tpl +++ b/onyx/tpl/bootstrap/admin/themes.tpl @@ -22,7 +22,7 @@ {$t->name} diff --git a/onyx/tpl/bootstrap/teams/exercice.tpl b/onyx/tpl/bootstrap/teams/exercice.tpl index 48ae7f99..078b07d8 100644 --- a/onyx/tpl/bootstrap/teams/exercice.tpl +++ b/onyx/tpl/bootstrap/teams/exercice.tpl @@ -3,7 +3,7 @@ {block name=exercices}
-

Exercice {$cur_exercice->number} {$solved} équipe{if $solved > 1}s ont{else} a{/if} résolu cet exercice

+

{$cur_exercice->get_title()} {$solved} équipe{if $solved > 1}s ont{else} a{/if} résolu cet exercice

    diff --git a/onyx/tpl/bootstrap/teams/theme.tpl b/onyx/tpl/bootstrap/teams/theme.tpl index 0e9c4118..f10dbe0b 100644 --- a/onyx/tpl/bootstrap/teams/theme.tpl +++ b/onyx/tpl/bootstrap/teams/theme.tpl @@ -6,11 +6,11 @@

    {foreach from=$cur_theme->get_exercices_ordered() item=exercice} {if $exercice->has_solved($my_team)} - {link class="btn btn-success" role="button" href_prefix="/{$SALT_USER}/{$my_team->get_id()}/" href="{$cur_theme->get_id()}-{$cur_theme->get_name_url()}/{$exercice->get_id()}/" label="{$exercice->get_name()}"} + {link class="btn btn-success" role="button" href_prefix="/{$SALT_USER}/{$my_team->get_id()}/" href="{$cur_theme->get_id()}-{$cur_theme->get_name_url()}/{$exercice->get_id()}/" label="{$exercice->get_title(true)}"} {elseif $exercice->is_unlocked($my_team)} - {link class="btn btn-primary" role="button" href_prefix="/{$SALT_USER}/{$my_team->get_id()}/" href="{$cur_theme->get_id()}-{$cur_theme->get_name_url()}/{$exercice->get_id()}/" label="{$exercice->get_name()}"} + {link class="btn btn-primary" role="button" href_prefix="/{$SALT_USER}/{$my_team->get_id()}/" href="{$cur_theme->get_id()}-{$cur_theme->get_name_url()}/{$exercice->get_id()}/" label="{$exercice->get_title(true)}"} {else} - {$exercice->get_name()} + {$exercice->get_title(true)} {/if} {/foreach}