mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 15:05:42 +00:00
BUGFIX: Submissions could not be paginated.
This commit is contained in:
parent
e2a5fb5ecf
commit
0bbfb720ca
@ -18,23 +18,20 @@ class SubmittedFormReportField extends FormField {
|
||||
*
|
||||
* @return PaginatedList
|
||||
*/
|
||||
public function getSubmissions($start = 0) {
|
||||
public function getSubmissions($page = 1) {
|
||||
$record = $this->form->getRecord();
|
||||
$submissions = $record->getComponents('Submissions', null, "\"Created\" DESC");
|
||||
|
||||
$query = DB::query(sprintf("
|
||||
SELECT COUNT(*) AS \"CountRows\"
|
||||
FROM \"SubmittedForm\"
|
||||
WHERE \"ParentID\" = '%d'", $record->ID
|
||||
));
|
||||
|
||||
foreach($query as $r) $totalCount = $r['CountRows'];
|
||||
$query = DB::query(sprintf("SELECT COUNT(*) AS \"CountRows\" FROM \"SubmittedForm\" WHERE \"ParentID\" = '%d'", $record->ID));
|
||||
$totalCount = 0;
|
||||
foreach($query as $r) {
|
||||
$totalCount = $r['CountRows'];
|
||||
}
|
||||
|
||||
$list = new PaginatedList($submissions);
|
||||
$list->setPageStart($start);
|
||||
$list->setCurrentPage($page);
|
||||
$list->setPageLength(10);
|
||||
$list->setTotalItems($totalCount);
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
@ -42,10 +39,9 @@ class SubmittedFormReportField extends FormField {
|
||||
* @return string
|
||||
*/
|
||||
public function getMoreSubmissions() {
|
||||
$start = ($start = $this->request->getVar('start')) ? (int) $start : 0;
|
||||
|
||||
$page = ($page = $this->request->getVar('page')) ? (int)$page : 1;
|
||||
return $this->customise(new ArrayData(array(
|
||||
'Submissions' => $this->getSubmissions($start)
|
||||
'Submissions' => $this->getSubmissions($page)
|
||||
)))->renderWith(array('SubmittedFormReportField'));
|
||||
}
|
||||
|
||||
|
@ -357,6 +357,16 @@
|
||||
currentRules.append(newRule);
|
||||
}
|
||||
});
|
||||
|
||||
$('.userforms-submissions-pagination a').entwine({
|
||||
onclick: function(e) {
|
||||
e.preventDefault();
|
||||
$.get($(this).attr('href'), function(data) {
|
||||
$('#userforms-submissions').replaceWith(data);
|
||||
});
|
||||
this._super();
|
||||
}
|
||||
})
|
||||
});
|
||||
});
|
||||
})(jQuery);
|
@ -21,20 +21,23 @@
|
||||
</div>
|
||||
<% end_loop %>
|
||||
|
||||
<% if Submissions.MoreThanOnePage %>
|
||||
<div class="userforms-submissions-pagination">
|
||||
|
||||
<% if Submissions.NotFirstPage %>
|
||||
<a class="prev" href="javascript:void(0)" onclick="jQuery('#userforms-submissions').parent().load(jQuery('base').get(0).href+'/{$Top.Link}/getMoreSubmissions/?start={$Submissions.PrevStart}');" title="View the previous page">Previous page</a>
|
||||
<% end_if %>
|
||||
|
||||
<span>Viewing rows $Submissions.Start - $Submissions.StartPlusOffset of $Submissions.TotalCount rows</span>
|
||||
|
||||
<% if Submissions.NotLastPage %>
|
||||
<a class="next" href="javascript:void(0)" onclick="jQuery('#userforms-submissions').parent().load(jQuery('base').get(0).href+'/{$Top.Link}/getMoreSubmissions/?start={$Submissions.NextStart}');" title="View the next page">Next page</a>
|
||||
<% end_if %>
|
||||
</div>
|
||||
<% end_if %>
|
||||
<% if Submissions.MoreThanOnePage %>
|
||||
<div class="userforms-submissions-pagination">
|
||||
<span>Pages: </span>
|
||||
<% loop Submissions.Pages() %>
|
||||
<% if CurrentBool %>
|
||||
$PageNum
|
||||
<% else %>
|
||||
<% if Link %>
|
||||
<a href="{$Top.Link(getMoreSubmissions)}?page=$PageNum">$PageNum</a>
|
||||
<% else %>
|
||||
...
|
||||
<% end_if %>
|
||||
<% end_if %>
|
||||
<% end_loop %>
|
||||
</div>
|
||||
<% end_if %>
|
||||
|
||||
<% else %>
|
||||
<p class="userforms-nosubmissions" <% if Submissions %>style="display: none"<% end_if %>><% _t('NOSUBMISSIONS', 'No Submissions') %></p>
|
||||
<% end_if %>
|
||||
|
Loading…
x
Reference in New Issue
Block a user