Store exercice title XML in DB

This commit is contained in:
nemunaire 2014-12-14 11:04:17 +01:00 committed by Némunaire
parent 3f773dffb0
commit b81af5aa90
10 changed files with 69 additions and 55 deletions

View File

@ -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` ,

View File

@ -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;

View File

@ -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"]);

View File

@ -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();

View File

@ -3,6 +3,10 @@
{if isset($ex)}
<h2>{$theme->name} <small>{$ex->id}</small></h2>
<form role="form" method="post" action="/{$SALT_ADMIN}/ex/{$theme->id}-{$theme->name}/{$ex->id}">
<div class="form-group">
<label for="title">Titre</label>
<input type="text" class="form-control" value="{$ex->title|escape}" name="title" id="title">
</div>
<div class="form-group">
<label for="desc">Description</label>
<textarea class="form-control" name="desc" id="desc">{$ex->statement|escape}</textarea>
@ -85,7 +89,7 @@
<p>
<ul>
{foreach from=$theme->get_exercices_ordered() item=ex}
<li><a href="/{$SALT_ADMIN}/ex/{$theme->id}-{$theme->name}/{$ex->id}">{$ex->get_name()}</a></li>
<li><a href="/{$SALT_ADMIN}/ex/{$theme->id}-{$theme->name}/{$ex->id}">{$ex->get_title()}</a></li>
{/foreach}
</ul>
</p>

View File

@ -4,7 +4,7 @@
{if $theme->get_exercices_ordered()}
{foreach from=$theme->get_exercices_ordered() item=e}
<exercice id="{$e->id}" level="{$e->level}"{if $e->require} depends="{$e->require}"{/if}>
<title>{$e->get_name()}</title>
<title>{$e->get_title()}</title>
<points>{$e->points}</points>
<statement>{$e->statement}</statement>
{if $e->keys}

View File

@ -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()} <b class=\"caret\"></b>"}
<ul class="dropdown-menu">
{foreach from=$t->get_exercices_ordered() item=e}
<li>{link href_prefix="/{$SALT_ADMIN}/" href="ex/{$t->get_id()}-{$t->get_name()}/{$e->get_id()}" label="{$e->get_name()}"}</li>
<li>{link href_prefix="/{$SALT_ADMIN}/" href="ex/{$t->get_id()}-{$t->get_name()}/{$e->get_id()}" label="{$e->get_title(true)}"}</li>
{/foreach}
</ul>
</li>

View File

@ -22,7 +22,7 @@
<td><a href="/{$SALT_ADMIN}/ex/{$t->id}-{$t->name}">{$t->name}</a></td>
<td><ul>
{foreach from=$t->get_exercices_ordered() item=e}
<li><a href="/{$SALT_ADMIN}/ex/{$t->id}-{$t->name}/{$e->id}">{$e->get_name()}</a></li>
<li><a href="/{$SALT_ADMIN}/ex/{$t->id}-{$t->name}/{$e->id}">{$e->get_title()}</a></li>
{/foreach}
</ul></td>
<td>

View File

@ -3,7 +3,7 @@
{block name=exercices}
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">Exercice {$cur_exercice->number} <small>{$solved} équipe{if $solved > 1}s ont{else} a{/if} résolu cet exercice</small></h3>
<h3 class="panel-title">{$cur_exercice->get_title()} <small>{$solved} équipe{if $solved > 1}s ont{else} a{/if} résolu cet exercice</small></h3>
</div>
<div class="panel-body">
<ul>

View File

@ -6,11 +6,11 @@
<p>
{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}
<a class="btn btn-danger" disabled="disabled">{$exercice->get_name()}</a>
<a class="btn btn-danger" disabled="disabled">{$exercice->get_title(true)}</a>
{/if}
{/foreach}
</p>