Skip to content
Snippets Groups Projects
Commit 97f03895 authored by Taddeüs Kroes's avatar Taddeüs Kroes
Browse files

Added link to othe user's matches to admin view

parent 21d75827
No related branches found
No related tags found
No related merge requests found
......@@ -45,8 +45,11 @@ $view = new Slim\Latte\LatteView(array(
'cache' => __DIR__ . '/.cache/latte',
'configure_engine' => function ($engine) {
// support for {_'...'} syntax in latte templates
$engine->addFilter('translate', function($s) {
return gettext($s);
$engine->addFilter('translate', function() {
$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
......
......@@ -216,6 +216,12 @@ msgstr "administrator"
msgid "member"
msgstr "gebruiker"
msgid "View matches"
msgstr "Bekijk scores"
msgid "%s's matches"
msgstr "Scores van %s"
msgid ""
"Responsive (mobile and desktop) website for saving archery scores, e.g. from "
"training or competitions."
......
......@@ -10,7 +10,7 @@ function render_match_action($action) {
};
}
function filter_form($matches) {
function filter_form($matches, $user_id=null) {
global $db;
$match_ids = array_unique($matches->fetchPairs(null, 'id'));
......@@ -26,7 +26,7 @@ function filter_form($matches) {
$form = new Form;
$form->setRenderer(new BootstrapRenderer);
$form->setAction('matches#results');
$form->setAction(($user_id ? 'user/' . $user_id . '/' : '') . 'matches#results');
$form->setMethod('get');
$form->addSelect('distance', _('Distance'), $distances)
......@@ -129,12 +129,14 @@ function create_tag($match, $tagname) {
} 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')
->where(array('user_id' => $user->getId()))
->where(array('user_id' => $user_id))
->order('created_at DESC');
$filter_form = filter_form($matches);
$filter_form = filter_form($matches, $admin_view ? $user_id : null);
if ($filter_form->isSubmitted()) {
$values = $filter_form->getValues();
......@@ -151,7 +153,12 @@ $app->get('/matches', function ($filter=null) use ($app, $db, $user) {
$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/scores', render_match_action('scores'));
......
......@@ -45,6 +45,10 @@ $app->get('/user/:id', function ($id) use ($app, $db) {
$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) {
$dbuser = find_user($id);
$form = edit_user_form($dbuser);
......
......@@ -2,7 +2,11 @@
{block content}
<h2 class="page-header">
{_'Matches'}
{if $dbuser}
{_'%s\'s matches', $dbuser->username}
{else}
{_'Matches'}
{/if}
<div class="btn-group">
<a href="match" class="btn btn-sm btn-default" title="{_'Add new match'}">
<span class="glyphicon glyphicon-plus"></span>
......
......@@ -10,6 +10,7 @@
<th>{_'Username'}</th>
<th>{_'Role'}</th>
<th>{_'Matches'}</th>
<th></th>
</tr>
</thead>
<tbody>
......@@ -19,6 +20,7 @@
<td>{$user->username}</td>
<td>{_$user->role}</td>
<td>{$h->numberOfMatches()}</td>
<td><a href="user/{$user->id}/matches">{_'View matches'}</a></td>
</tr>
</tbody>
</table>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment