Skip to content
This repository was archived by the owner on Dec 11, 2018. It is now read-only.

Commit 73eb855

Browse files
committed
Search
1 parent d1ba555 commit 73eb855

File tree

6 files changed

+104
-66
lines changed

6 files changed

+104
-66
lines changed

data/i18n/en.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,16 @@
143143
"form-yes": "Yes",
144144
"form-no": "No",
145145

146-
"queue-th-proposal": "Proposal",
147-
"queue-th-reviews": "Reviews"
146+
"proposals-search-title": "Title",
147+
"proposals-search-theme": "Theme",
148+
"proposals-search-theme-empty": "Select theme",
149+
"proposals-search-go": "Search",
150+
151+
"proposals-list-id": "Id",
152+
"proposals-list-title": "Title",
153+
"proposals-list-url": "URL",
154+
"proposals-list-theme": "Theme",
155+
"proposals-list-amount": "Amount",
156+
"proposals-list-reviews": "Reviews",
157+
"proposals-list-myreviews": "Reviewed?"
148158
}

data/i18n/qqq.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,17 @@
119119

120120
"form-yes": "Radio button label.",
121121
"form-no": "Radio button label.",
122+
123+
"proposals-search-title": "Input label, followed by text box.",
124+
"proposals-search-theme": "Input label, followed by select list.",
125+
"proposals-search-theme-empty": "Select list usage prompt.",
126+
"proposals-search-go": "Form submit button label",
127+
128+
"proposals-list-id": "Table column header",
129+
"proposals-list-title": "Table column header",
130+
"proposals-list-url": "Table column header",
131+
"proposals-list-theme": "Table column header",
132+
"proposals-list-amount": "Table column header",
133+
"proposals-list-reviews": "Table column header",
134+
"proposals-list-myreviews": "Table column header"
122135
}

data/templates/proposals/queue.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010

1111
<table class="table table-striped table-hover table-condensed table-responsive">
1212
<tr>
13-
<th>{{ 'queue-th-proposal'|message }}</th>
14-
<th>{{ 'queue-th-reviews'|message }}</th>
13+
<th>{{ 'proposals-list-title'|message }}</th>
14+
<th>{{ 'proposals-list-theme'|message }}</th>
15+
<th>{{ 'proposals-list-amount'|message }}</th>
16+
<th>{{ 'proposals-list-reviews'|message }}</th>
1517
</tr>
1618
{% for row in records %}
1719
<tr>
1820
<td><a href="{{ urlFor( 'proposals_view', { 'id': row.id } ) }}">{{ row.title }}</a></td>
19-
<td>{{ row.review_count }}</td>
21+
<td>{{ row.theme }}</td>
22+
<td class="text-right">{{ row.amount|number_format }}</td>
23+
<td class="text-right">{{ row.review_count|number_format }}</td>
2024
</tr>
2125
{% else %}
2226
<tr><td colspan="12">{{ 'no-results'|message }}</td></tr>

data/templates/proposals/search.html

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,24 @@
1111
<form class="form-inline" method="get" action="{{ urlFor( route ) }}" role="form">
1212
<input type="hidden" name="p" value="0">
1313
<div class="form-group">
14-
<label class="sr-only" for="lastname">{{ 'form-lname'|message }}</label>
15-
<input type="text" name="l" id="lastname" placeholder="{{ 'form-lname'|message }}" value="{{ l }}">
14+
<label class="sr-only" for="t">{{ 'proposals-search-title'|message }}</label>
15+
<input type="text" id="t" name="t" class="form-control" placeholder="{{ 'proposals-search-title'|message }}" value="{{ t }}">
1616
</div>
1717
<div class="form-group">
18-
<label class="sr-only" for="firstname">{{ 'form-fname'|message }}</label>
19-
<input type="text" name="f" id="firstname" placeholder="{{ 'form-fname'|message }}" value="{{ f }}">
18+
<label class="sr-only" for="th">{{ 'proposals-search-theme'|message }}</label>
19+
<select id="th" name="th" class="form-control">
20+
<option value="">{{ 'proposals-search-theme-empty'|message }}</option>
21+
{{ forms.select( ctx, 'proposals-edit-theme', 'theme', { 'online':'online', 'offline':'offline', 'tool':'tool', 'research':'research' }, { 'required':true } ) }}
22+
{% for val in [ 'online', 'offline', 'tool', 'research' ] %}
23+
<option value="{{ val }}" {{ val == th ? 'selected="selected"' }}>{{ val }}</option>
24+
{% endfor %}
25+
</select>
2026
</div>
2127
<div class="form-group">
22-
<label class="sr-only" for="residence">{{ 'form-residence'|message }}</label>
23-
<input type="text" name="r" id="residence" placeholder="{{ 'form-residence'|message }}" value="{{ r }}">
24-
</div>
25-
<div class="form-group">
26-
<label class="sr-only" for="region">{{ 'search-region'|message }}</label>
27-
<input type="text" name="rg" id="region" placeholder="{{ 'search-region'|message }}" value="{{ rg }}">
28-
</div>
29-
<div class="form-group">
30-
<input type="submit" class="btn btn-sm btn-primary" value="{{ 'search'|message }}" />
28+
<button type="submit" class="btn btn-sm btn-primary">
29+
<i class="glyphicon glyphicon-search"></i>
30+
{{ 'proposals-search-go'|message }}
31+
</button>
3132
</div>
3233
</form>
3334

@@ -36,23 +37,23 @@
3637
{% if found is not null %}
3738
<table class="table table-striped table-hover table-condensed table-responsive">
3839
<tr>
39-
<th>{{ 'review-list-id'|message }}</th>
40-
<th>{{ 'review-list-name'|message }}</th>
41-
<th>{{ 'review-list-email'|message }}</th>
42-
<th>{{ 'review-list-residence'|message }}</th>
43-
<th>{{ 'review-list-gender'|message }}</th>
44-
<th>{{ 'review-list-age'|message }}</th>
45-
<th>{{ 'review-list-p1-score'|message }}</th>
40+
<th>{{ 'proposals-list-id'|message }}</th>
41+
<th>{{ 'proposals-list-title'|message }}</th>
42+
<th>{{ 'proposals-list-url'|message }}</th>
43+
<th>{{ 'proposals-list-theme'|message }}</th>
44+
<th>{{ 'proposals-list-amount'|message }}</th>
45+
<th>{{ 'proposals-list-reviews'|message }}</th>
46+
<th>{{ 'proposals-list-myreviews'|message }}</th>
4647
</tr>
4748
{% for row in records %}
4849
<tr>
4950
<td>{{ row.id }}</td>
50-
<td><a href="{{ urlFor( 'proposals_view' ) }}?id={{ row.id }}">{{ row.title }}</a></td>
51-
<td>{{ row.email }}</td>
52-
<td>{{ row.country_name }}</td>
53-
<td>{{ row.gender }}</td>
54-
<td>{{ row.age }}</td>
55-
<td>{{ row.p1count ? row.p1score : '-' }}</td>
51+
<td><a href="{{ urlFor( 'proposals_view', { 'id':row.id } ) }}">{{ row.title }}</a></td>
52+
<td><a href="{{ row.url|raw }}" target="_blank">{{ row.url }}</a></td>
53+
<td>{{ row.theme }}</td>
54+
<td class="text-right">{{ row.amount|number_format }}</td>
55+
<td class="text-right">{{ row.review_count|number_format }}</td>
56+
<td class="text-center"><i class="glyphicon glyphicon-{{ row.my_review_count ? 'ok' }}"></i></td>
5657
</tr>
5758
{% else %}
5859
<tr><td colspan="8">{{ 'no-results'|message }}</td></tr>
@@ -64,23 +65,23 @@
6465
<p class="text-right">{{ 'page-of-pages'|message( p + 1, pages ) }}</p>
6566
</div>
6667
<div class="col-md-9">
67-
<ul class="pagination">
68-
{% if p > 0 %}
69-
<li><a href="{{ urlFor( route ) }}?{{ qsMerge( { 'p':(p - 1) } ) }}" id="prev">&laquo;</a></li>
70-
{% else %}
71-
<li class="disabled"><span>&laquo;</span></li>
72-
{% endif %}
73-
{% if left > 0 %}<li class="disabled"><span>&hellip;</span></li>{% endif %}
74-
{% for i in left .. right %}
75-
<li class="{{ i == p ? 'active' }}"><a href="{{ urlFor( route ) }}?{{ qsMerge( { 'p':i } ) }}" id="prev">{{ i + 1 }}</a></li>
76-
{% endfor %}
77-
{% if right < pages - 1 %}<li class="disabled"><span>&hellip;</span></li>{% endif %}
78-
{% if p + 1 < pages %}
79-
<li><a href="{{ urlFor( route ) }}?{{ qsMerge( { 'p':(p + 1) } ) }}" >&raquo;</a></li>
80-
{% else %}
81-
<li class="disabled"><span>&raquo;</span></li>
82-
{% endif %}
83-
</ul>
68+
<ul class="pagination">
69+
{% if p > 0 %}
70+
<li><a href="{{ urlFor( route ) }}?{{ qsMerge( { 'p':(p - 1) } ) }}" id="prev">&laquo;</a></li>
71+
{% else %}
72+
<li class="disabled"><span>&laquo;</span></li>
73+
{% endif %}
74+
{% if left > 0 %}<li class="disabled"><span>&hellip;</span></li>{% endif %}
75+
{% for i in left .. right %}
76+
<li class="{{ i == p ? 'active' }}"><a href="{{ urlFor( route ) }}?{{ qsMerge( { 'p':i } ) }}" id="prev">{{ i + 1 }}</a></li>
77+
{% endfor %}
78+
{% if right < pages - 1 %}<li class="disabled"><span>&hellip;</span></li>{% endif %}
79+
{% if p + 1 < pages %}
80+
<li><a href="{{ urlFor( route ) }}?{{ qsMerge( { 'p':(p + 1) } ) }}" >&raquo;</a></li>
81+
{% else %}
82+
<li class="disabled"><span>&raquo;</span></li>
83+
{% endif %}
84+
</ul>
8485
</div>
8586
</div>
8687
{% endif %}

src/Controllers/Proposals/Search.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,33 +34,32 @@
3434
class Search extends Controller {
3535

3636
protected function handleGet() {
37-
$this->form->expectString( 'l' );
38-
$this->form->expectString( 'f' );
39-
$this->form->expectString( 'r' );
40-
$this->form->expectString( 'rg' );
37+
$this->form->expectString( 't' );
38+
$this->form->expectString( 'th' );
4139
$this->form->expectInt( 'items',
4240
array( 'min_range' => 1, 'max_range' => 250, 'default' => 50 )
4341
);
4442
$this->form->expectInt( 'p', array( 'min_range' => 0, 'default' => 0 ) );
43+
$this->form->expectString( 's', array( 'default' => 'id' ) );
44+
$this->form->expectInArray( 'o', array( 'asc', 'desc' ),
45+
array( 'default' => 'asc' )
46+
);
4547
$this->form->validate( $_GET );
4648

47-
$this->view->set( 'l', $this->form->get( 'l' ) );
48-
$this->view->set( 'f', $this->form->get( 'f' ) );
49-
$this->view->set( 'r', $this->form->get( 'r' ) );
50-
$this->view->set( 'rg', $this->form->get( 'rg' ) );
49+
$this->view->set( 't', $this->form->get( 't' ) );
50+
$this->view->set( 'th', $this->form->get( 'th' ) );
5151
$this->view->set( 'items', $this->form->get( 'items' ) );
5252
$this->view->set( 'p', $this->form->get( 'p' ) );
53+
$this->view->set( 's', $this->form->get( 's' ) );
54+
$this->view->set( 'o', $this->form->get( 'o' ) );
5355
$this->view->set( 'found', null );
5456

55-
if ( $this->form->get( 'l' ) || $this->form->get( 'f' ) ||
56-
$this->form->get( 'r' ) || $this->form->get( 'rg' )
57-
) {
58-
57+
if ( $this->form->get( 't' ) || $this->form->get( 'th' ) ) {
5958
$params = array(
60-
'first' => $this->form->get( 'f' ),
61-
'last' => $this->form->get( 'l' ),
62-
'residence' => $this->form->get( 'r' ),
63-
'region' => $this->form->get( 'rg' ),
59+
'title' => $this->form->get( 't' ),
60+
'theme' => $this->form->get( 'th' ),
61+
'sort' => $this->form->get( 's' ),
62+
'order' => $this->form->get( 'o' ),
6463
'items' => $this->form->get( 'items' ),
6564
'page' => $this->form->get( 'p' ),
6665
);

src/Dao/Proposals.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ public function updateProposal( $id, $data ) {
106106
*/
107107
public function search( array $params ) {
108108
$defaults = array(
109-
'proposals' => '',
109+
'proposals' => null,
110+
'title' => null,
111+
'theme' => null,
110112
'sort' => 'id',
111113
'order' => 'asc',
112114
'items' => 20,
@@ -136,6 +138,15 @@ public function search( array $params ) {
136138
$offset = 'OFFSET :int_offset';
137139
}
138140

141+
if ( $params['title'] !== null ) {
142+
$where[] = 'p.title like :title';
143+
$crit['title'] = $params['title'];
144+
}
145+
if ( $params['theme'] !== null ) {
146+
$where[] = 'p.theme = :theme';
147+
$crit['theme'] = $params['theme'];
148+
}
149+
139150
$fields = array(
140151
'p.id as id',
141152
'p.title as title',
@@ -179,7 +190,7 @@ public function search( array $params ) {
179190
'FROM proposals p',
180191
$joins,
181192
self::buildWhere( $where ),
182-
"ORDER BY {$sortby}, id {$order}",
193+
"ORDER BY {$sortby} {$order}, id {$order}",
183194
$limit, $offset
184195
);
185196
return $this->fetchAllWithFound( $sql, $crit );

0 commit comments

Comments
 (0)