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
f58723c6
Commit
f58723c6
authored
Oct 07, 2014
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added filter form
parent
2febdf14
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
8 deletions
+88
-8
routes/match.php
routes/match.php
+61
-6
templates/match/list.latte
templates/match/list.latte
+27
-2
No files found.
routes/match.php
View file @
f58723c6
<?php
use
Nette\Forms\Form
;
use
Instante\Bootstrap3Renderer\BootstrapRenderer
;
function
pack_scores
(
$scores
)
{
$blob
=
''
;
foreach
(
$scores
as
$score
)
...
...
@@ -43,16 +46,68 @@ function render_match_action($action) {
};
}
$app
->
get
(
'/match'
,
function
()
use
(
$app
,
$db
,
$user
)
{
function
filter_form
(
$matches
)
{
global
$db
;
$form
=
new
Form
;
$form
->
setRenderer
(
new
BootstrapRenderer
);
$form
->
setAction
(
'match#results'
);
$form
->
setMethod
(
'get'
);
$match_ids
=
array_unique
(
$matches
->
fetchPairs
(
null
,
'id'
));
$tags
=
$db
->
table
(
'tag'
)
->
select
(
'DISTINCT name AS name'
)
->
where
(
array
(
'match_id'
=>
$match_ids
))
->
fetchPairs
(
'name'
,
'name'
);
asort
(
$tags
);
$distances
=
$matches
->
fetchPairs
(
'distance'
,
'distance'
);
asort
(
$distances
);
$form
->
addSelect
(
'distance'
,
'Distance'
,
$distances
)
->
setPrompt
(
'Select a distance'
);
$form
->
addSelect
(
'tag'
,
'Tag'
,
$tags
)
->
setPrompt
(
'Select a tag'
);
$form
->
addText
(
'name'
,
'Name'
);
$form
->
addSubmit
(
'send'
,
'Filter'
);
return
$form
;
}
$app
->
get
(
'/match'
,
function
(
$filter
=
null
)
use
(
$app
,
$db
,
$user
)
{
$user_id
=
$user
->
getId
();
$matches
=
$db
->
table
(
'match'
)
->
where
(
compact
(
'user_id'
))
->
order
(
'created_at'
,
'desc'
);
$app
->
render
(
'match/list'
,
compact
(
'matches'
));
$matches
=
$db
->
table
(
'match'
)
->
where
(
compact
(
'user_id'
))
->
order
(
'created_at DESC'
);
$filter_form
=
filter_form
(
$matches
);
if
(
$filter_form
->
isSubmitted
())
{
$values
=
$filter_form
->
getValues
();
if
(
$values
->
tag
)
{
$ids
=
$db
->
table
(
'tag'
)
->
select
(
'match_id'
)
->
where
(
'name'
,
$values
->
tag
);
$matches
->
where
(
'id'
,
$ids
);
}
if
(
$values
->
distance
)
$matches
->
where
(
'distance'
,
$values
->
distance
);
if
(
$values
->
name
)
$matches
->
where
(
'name LIKE ?'
,
"%
$values->name
%"
);
//foreach ($filter_form->getValues() as $prop => $value) {
//$matches = $matches->where($filter_form->getValues();
}
$app
->
render
(
'match/list'
,
compact
(
'matches'
,
'filter_form'
));
});
$app
->
get
(
'/match/:id'
,
render_match_action
(
'view'
));
$app
->
get
(
'/match/:id/edit'
,
render_match_action
(
'edit'
));
$app
->
get
(
'/match/:id/delete'
,
render_match_action
(
'delete'
));
$app
->
delete
(
'/match/:id'
,
function
(
$id
)
use
(
$app
,
$db
)
{
$db
->
table
(
'user'
)
->
delete
();
//find_match($id)->delete();
$app
->
delete
(
'/match/:id'
,
function
(
$id
)
{
find_match
(
$id
)
->
delete
();
});
$app
->
put
(
'/match/:id'
,
function
(
$id
)
{
// TODO
});
templates/match/list.latte
View file @
f58723c6
{extends '../layout.latte'}
{block content}
<table class="table table-hover matches">
<h3 class="page-header">
<a data-toggle="collapse" href="#filter">
Filter matches <span class="caret"></span>
</a>
</h3>
<div id="filter" class="collapse {$filter_form->isSubmitted() ? in}">
{form $filter_form}
{form errors}
{form controls}
<div class="form-group">
<div class="form-actions col-sm-offset-2 col-sm-10">
<button type="submit" name="send" class="btn btn-primary">Filter</button>
<a href="match" class="btn btn-default">Clear filters</a>
</div>
</div>
{/form}
<h3>Results</h3>
</div>
<table id="results" class="table table-hover matches">
<thead>
<tr>
<th>Name</th>
...
...
@@ -25,7 +44,13 @@
<td>{match_score($match)} (~{match_avg_score($match)|number:1})</td>
</tr>
<tr n:if="!$matches->count()">
<td colspan="5">You have not saved any matches yet.</td>
<td colspan="5">
{if $filter_form->isSubmitted()}
No search results.
{else}
You have not saved any matches yet.
{/if}
</td>
</tr>
</tbody>
</table>
...
...
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