Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
archery
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
3
Issues
3
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
archery
Commits
88c11fe3
Commit
88c11fe3
authored
Nov 12, 2014
by
Taddeus Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added pagination to match list
parent
b3986358
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
78 additions
and
11 deletions
+78
-11
app.php
app.php
+1
-1
config.json
config.json
+2
-1
locale/nl_NL/LC_MESSAGES/archery.po
locale/nl_NL/LC_MESSAGES/archery.po
+12
-0
routes/match.php
routes/match.php
+16
-5
routes/user.php
routes/user.php
+2
-2
templates/layout.latte
templates/layout.latte
+1
-1
templates/match/list.latte
templates/match/list.latte
+21
-1
util.php
util.php
+23
-0
No files found.
app.php
View file @
88c11fe3
...
@@ -49,7 +49,7 @@ $view = new Slim\Latte\LatteView(array(
...
@@ -49,7 +49,7 @@ $view = new Slim\Latte\LatteView(array(
$args
=
func_get_args
();
$args
=
func_get_args
();
assert
(
count
(
$args
)
>
0
);
assert
(
count
(
$args
)
>
0
);
$fmt
=
gettext
(
array_shift
(
$args
));
$fmt
=
gettext
(
array_shift
(
$args
));
return
strpos
(
$fmt
,
'%
s
'
)
!==
false
?
vsprintf
(
$fmt
,
$args
)
:
$fmt
;
return
strpos
(
$fmt
,
'%'
)
!==
false
?
vsprintf
(
$fmt
,
$args
)
:
$fmt
;
});
});
// install {form} macro's from Bootstrap form renderer
// install {form} macro's from Bootstrap form renderer
...
...
config.json
View file @
88c11fe3
...
@@ -4,5 +4,6 @@
...
@@ -4,5 +4,6 @@
},
},
"max_session_lifetime"
:
"2 weeks"
,
"max_session_lifetime"
:
"2 weeks"
,
"log.enable"
:
true
,
"log.enable"
:
true
,
"debug"
:
false
"debug"
:
false
,
"max_list_items"
:
20
}
}
locale/nl_NL/LC_MESSAGES/archery.po
View file @
88c11fe3
...
@@ -225,3 +225,15 @@ msgid ""
...
@@ -225,3 +225,15 @@ msgid ""
msgstr ""
msgstr ""
"Responsieve website (voor mobiel en desktop) voor het opslaan van scores "
"Responsieve website (voor mobiel en desktop) voor het opslaan van scores "
"behaald tijdens het boogschieten, bijv. training en wedstrijden."
"behaald tijdens het boogschieten, bijv. training en wedstrijden."
msgid "No search results."
msgstr ""
msgid "No results"
msgstr "Geen resultaten"
msgid "1 result"
msgstr "1 resultaat"
msgid "%d results"
msgstr "%d resultaten"
routes/match.php
View file @
88c11fe3
...
@@ -129,13 +129,14 @@ function create_tag($match, $tagname) {
...
@@ -129,13 +129,14 @@ function create_tag($match, $tagname) {
}
catch
(
PDOException
$e
)
{}
}
catch
(
PDOException
$e
)
{}
}
}
function
user_matches
(
$user_id
,
$admin_view
)
{
function
user_matches
(
$user_id
,
$admin_view
,
$page
)
{
global
$app
,
$db
;
global
$
config
,
$
app
,
$db
;
$matches
=
$db
->
table
(
'match'
)
$matches
=
$db
->
table
(
'match'
)
->
where
(
array
(
'user_id'
=>
$user_id
))
->
where
(
array
(
'user_id'
=>
$user_id
))
->
order
(
'created_at DESC'
);
->
order
(
'created_at DESC'
);
// Filtering
$filter_form
=
filter_form
(
$matches
,
$admin_view
?
$user_id
:
null
);
$filter_form
=
filter_form
(
$matches
,
$admin_view
?
$user_id
:
null
);
if
(
$filter_form
->
isSubmitted
())
{
if
(
$filter_form
->
isSubmitted
())
{
...
@@ -153,12 +154,22 @@ function user_matches($user_id, $admin_view) {
...
@@ -153,12 +154,22 @@ function user_matches($user_id, $admin_view) {
$matches
->
where
(
'name LIKE ?'
,
"%
$values->name
%"
);
$matches
->
where
(
'name LIKE ?'
,
"%
$values->name
%"
);
}
}
// Pagination
$pagesize
=
$config
[
'max_list_items'
];
$nresults
=
$matches
->
count
();
$npages
=
intval
(
ceil
(
$nresults
/
floatval
(
$pagesize
)));
$matches
->
limit
(
$pagesize
,
(
$page
-
1
)
*
$pagesize
);
$dbuser
=
$admin_view
?
find_user
(
$user_id
)
:
null
;
$dbuser
=
$admin_view
?
find_user
(
$user_id
)
:
null
;
$app
->
render
(
'match/list'
,
compact
(
'matches'
,
'filter_form'
,
'dbuser'
));
$base_uri
=
$admin_view
?
"user/
$user_id
/matches"
:
'matches'
;
$app
->
render
(
'match/list'
,
compact
(
'matches'
,
'filter_form'
,
'dbuser'
,
'page'
,
'npages'
,
'nresults'
,
'base_uri'
));
}
}
$app
->
get
(
'/matches
'
,
function
(
)
use
(
$user
)
{
$app
->
get
(
'/matches
(/:page)'
,
function
(
$page
=
1
)
use
(
$user
)
{
return
user_matches
(
$user
->
getId
(),
false
);
return
user_matches
(
$user
->
getId
(),
false
,
max
(
1
,
intval
(
$page
))
);
});
});
$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'
));
...
...
routes/user.php
View file @
88c11fe3
...
@@ -45,8 +45,8 @@ $app->get('/user/:id', function ($id) use ($app, $db) {
...
@@ -45,8 +45,8 @@ $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
)
{
$app
->
get
(
'/user/:id/matches
(/:page)'
,
function
(
$id
,
$page
=
1
)
{
return
user_matches
(
$id
,
true
);
return
user_matches
(
$id
,
true
,
max
(
1
,
intval
(
$page
))
);
});
});
$app
->
get
(
'/user/:id/edit'
,
function
(
$id
)
use
(
$app
)
{
$app
->
get
(
'/user/:id/edit'
,
function
(
$id
)
use
(
$app
)
{
...
...
templates/layout.latte
View file @
88c11fe3
...
@@ -36,7 +36,7 @@
...
@@ -36,7 +36,7 @@
<div
class=
"collapse navbar-collapse"
>
<div
class=
"collapse navbar-collapse"
>
<ul
class=
"nav navbar-nav"
>
<ul
class=
"nav navbar-nav"
>
<li
n:foreach=
"$menu as $m"
n:if=
"$m"
<li
n:foreach=
"$menu as $m"
n:if=
"$m"
n:class=
"
'/'.$m[0] == $app->request()->getPathInfo()
? active"
>
n:class=
"
strpos($app->request()->getPathInfo(), '/'.$m[0]) === 0
? active"
>
<a
href=
"{$m[0]}"
>
{$m[1]}
</a>
<a
href=
"{$m[0]}"
>
{$m[1]}
</a>
</li>
</li>
</ul>
</ul>
...
...
templates/match/list.latte
View file @
88c11fe3
...
@@ -2,7 +2,15 @@
...
@@ -2,7 +2,15 @@
{block content}
{block content}
<h2 class="page-header">
<h2 class="page-header">
{if $dbuser}
{if $filter_form->isSubmitted()}
{if $nresults == 0}
{_'No results'}
{elseif $nresults == 1}
{_'1 result'}
{else}
{_'%d results', $nresults}
{/if}
{elseif $dbuser}
{_'%s\'s matches', $dbuser->username}
{_'%s\'s matches', $dbuser->username}
{else}
{else}
{_'Matches'}
{_'Matches'}
...
@@ -66,4 +74,16 @@
...
@@ -66,4 +74,16 @@
</tr>
</tr>
</tbody>
</tbody>
</table>
</table>
{var $query_string = ($q = $_SERVER['QUERY_STRING']) ? '?' . $q}
<nav n:if="$npages > 1">
<ul class="pagination">
<li n:foreach="pagination_range($npages, $page) as $p"
class="{$p == $page ? 'active'} {$p == 0 ? 'disabled'}">
<a n:if="$p" href="{$base_uri}/{$p}{$query_string}">{$p}</a>
<a n:if="!$p" href="javascript:void(0)">…</a>
</li>
</ul>
</nav>
{/block}
{/block}
util.php
View file @
88c11fe3
...
@@ -142,3 +142,26 @@ class UserHelper {
...
@@ -142,3 +142,26 @@ class UserHelper {
return
$score
/
$matches
->
count
();
return
$score
/
$matches
->
count
();
}
}
}
}
// Create pagination buttons (0 means a "..." entry)
function
pagination_range
(
$numpages
,
$curpage
,
$numaround
=
2
)
{
$pages
=
array
();
if
(
$curpage
>
$numaround
+
1
)
{
$pages
[]
=
1
;
if
(
$curpage
>
$numaround
+
2
)
$pages
[]
=
0
;
}
for
(
$i
=
max
(
1
,
$curpage
-
$numaround
);
$i
<=
min
(
$curpage
+
$numaround
,
$numpages
);
$i
++
)
$pages
[]
=
$i
;
if
(
$curpage
<=
$numpages
-
$numaround
-
1
)
{
if
(
$curpage
<=
$numpages
-
$numaround
-
2
)
$pages
[]
=
0
;
$pages
[]
=
$numpages
;
}
return
$pages
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment