Commit 97f03895 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Added link to othe user's matches to admin view

parent 21d75827
...@@ -45,8 +45,11 @@ $view = new Slim\Latte\LatteView(array( ...@@ -45,8 +45,11 @@ $view = new Slim\Latte\LatteView(array(
'cache' => __DIR__ . '/.cache/latte', 'cache' => __DIR__ . '/.cache/latte',
'configure_engine' => function ($engine) { 'configure_engine' => function ($engine) {
// support for {_'...'} syntax in latte templates // support for {_'...'} syntax in latte templates
$engine->addFilter('translate', function($s) { $engine->addFilter('translate', function() {
return gettext($s); $args = func_get_args();
assert(count($args) > 0);
$fmt = gettext(array_shift($args));
return strpos($fmt, '%s') !== false ? vsprintf($fmt, $args) : $fmt;
}); });
// install {form} macro's from Bootstrap form renderer // install {form} macro's from Bootstrap form renderer
......
...@@ -216,6 +216,12 @@ msgstr "administrator" ...@@ -216,6 +216,12 @@ msgstr "administrator"
msgid "member" msgid "member"
msgstr "gebruiker" msgstr "gebruiker"
msgid "View matches"
msgstr "Bekijk scores"
msgid "%s's matches"
msgstr "Scores van %s"
msgid "" msgid ""
"Responsive (mobile and desktop) website for saving archery scores, e.g. from " "Responsive (mobile and desktop) website for saving archery scores, e.g. from "
"training or competitions." "training or competitions."
......
...@@ -10,7 +10,7 @@ function render_match_action($action) { ...@@ -10,7 +10,7 @@ function render_match_action($action) {
}; };
} }
function filter_form($matches) { function filter_form($matches, $user_id=null) {
global $db; global $db;
$match_ids = array_unique($matches->fetchPairs(null, 'id')); $match_ids = array_unique($matches->fetchPairs(null, 'id'));
...@@ -26,7 +26,7 @@ function filter_form($matches) { ...@@ -26,7 +26,7 @@ function filter_form($matches) {
$form = new Form; $form = new Form;
$form->setRenderer(new BootstrapRenderer); $form->setRenderer(new BootstrapRenderer);
$form->setAction('matches#results'); $form->setAction(($user_id ? 'user/' . $user_id . '/' : '') . 'matches#results');
$form->setMethod('get'); $form->setMethod('get');
$form->addSelect('distance', _('Distance'), $distances) $form->addSelect('distance', _('Distance'), $distances)
...@@ -129,12 +129,14 @@ function create_tag($match, $tagname) { ...@@ -129,12 +129,14 @@ function create_tag($match, $tagname) {
} catch(PDOException $e) {} } catch(PDOException $e) {}
} }
$app->get('/matches', function ($filter=null) use ($app, $db, $user) { function user_matches($user_id, $admin_view) {
global $app, $db;
$matches = $db->table('match') $matches = $db->table('match')
->where(array('user_id' => $user->getId())) ->where(array('user_id' => $user_id))
->order('created_at DESC'); ->order('created_at DESC');
$filter_form = filter_form($matches); $filter_form = filter_form($matches, $admin_view ? $user_id : null);
if ($filter_form->isSubmitted()) { if ($filter_form->isSubmitted()) {
$values = $filter_form->getValues(); $values = $filter_form->getValues();
...@@ -151,7 +153,12 @@ $app->get('/matches', function ($filter=null) use ($app, $db, $user) { ...@@ -151,7 +153,12 @@ $app->get('/matches', function ($filter=null) use ($app, $db, $user) {
$matches->where('name LIKE ?', "%$values->name%"); $matches->where('name LIKE ?', "%$values->name%");
} }
$app->render('match/list', compact('matches', 'filter_form')); $dbuser = $admin_view ? find_user($user_id) : null;
$app->render('match/list', compact('matches', 'filter_form', 'dbuser'));
}
$app->get('/matches', function () use ($user) {
return user_matches($user->getId(), false);
}); });
$app->get('/match/:id', render_match_action('view')); $app->get('/match/:id', render_match_action('view'));
$app->get('/match/:id/scores', render_match_action('scores')); $app->get('/match/:id/scores', render_match_action('scores'));
......
...@@ -45,6 +45,10 @@ $app->get('/user/:id', function ($id) use ($app, $db) { ...@@ -45,6 +45,10 @@ $app->get('/user/:id', function ($id) use ($app, $db) {
$app->render('user/view', array('dbuser' => find_user($id))); $app->render('user/view', array('dbuser' => find_user($id)));
}); });
$app->get('/user/:id/matches', function ($id) {
return user_matches($id, true);
});
$app->get('/user/:id/edit', function ($id) use ($app) { $app->get('/user/:id/edit', function ($id) use ($app) {
$dbuser = find_user($id); $dbuser = find_user($id);
$form = edit_user_form($dbuser); $form = edit_user_form($dbuser);
......
...@@ -2,7 +2,11 @@ ...@@ -2,7 +2,11 @@
{block content} {block content}
<h2 class="page-header"> <h2 class="page-header">
{if $dbuser}
{_'%s\'s matches', $dbuser->username}
{else}
{_'Matches'} {_'Matches'}
{/if}
<div class="btn-group"> <div class="btn-group">
<a href="match" class="btn btn-sm btn-default" title="{_'Add new match'}"> <a href="match" class="btn btn-sm btn-default" title="{_'Add new match'}">
<span class="glyphicon glyphicon-plus"></span> <span class="glyphicon glyphicon-plus"></span>
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
<th>{_'Username'}</th> <th>{_'Username'}</th>
<th>{_'Role'}</th> <th>{_'Role'}</th>
<th>{_'Matches'}</th> <th>{_'Matches'}</th>
<th></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
...@@ -19,6 +20,7 @@ ...@@ -19,6 +20,7 @@
<td>{$user->username}</td> <td>{$user->username}</td>
<td>{_$user->role}</td> <td>{_$user->role}</td>
<td>{$h->numberOfMatches()}</td> <td>{$h->numberOfMatches()}</td>
<td><a href="user/{$user->id}/matches">{_'View matches'}</a></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
......
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