Commit 9cd85a0c authored by Taddeüs Kroes's avatar Taddeüs Kroes

Progress graph now handles default discipline properly

parent d6f6c9c6
......@@ -27,7 +27,7 @@ $app->delete('/user/:id', function ($id) {
echo "delete user $id";
});
function plot_filter_form($dbuser, $matches) {
function plot_filter_form($dbuser, $matches, $default_discipline) {
global $db;
$disciplines = array('barebow', 'recurve', 'compound');
......@@ -61,15 +61,9 @@ function plot_filter_form($dbuser, $matches) {
->setPrompt(_('Select a distance'));
$form->addRadioList('discipline', _('Discipline'), $disciplines)
->setAttribute('data-inline', true)
->setRequired();
->setDefaultValue($default_discipline);
$form->addSubmit('send', _('Filter'));
if ($matches->count()) {
$last_match = $matches->fetch();
$form['discipline']->setDefaultValue($last_match->discipline);
$matches->rewind();
}
return $form;
}
......@@ -81,7 +75,15 @@ $app->get('/user/:id/plot', function ($id) use ($app, $db, $user) {
->where(array('user_id' => $id))
->order('created_at DESC');
$form = plot_filter_form($dbuser, $matches);
if ($matches->count()) {
$last_match = $matches->fetch();
$default_discipline = $last_match->discipline;
$matches->rewind();
} else {
$default_discipline = 'recurve';
}
$form = plot_filter_form($dbuser, $matches, $default_discipline);
if ($form->isSubmitted()) {
$v = $form->getValues();
......@@ -106,6 +108,8 @@ $app->get('/user/:id/plot', function ($id) use ($app, $db, $user) {
if ($v->discipline)
$matches->where('discipline', $v->discipline);
} else {
$matches->where('discipline', $default_discipline);
}
$app->render('user/plot', compact('dbuser', 'form', 'matches'));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment