Created
October 12, 2012 16:09
-
-
Save jbroadway/3879993 to your computer and use it in GitHub Desktop.
Elefant CMS - Browse form submissions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p><a href="/form/new=entry">{" All forms "}</a> | <a href="/form/export?id={{ id }}">{" Export results (CSV) "}</a></p> | |
{% if offset > 0 %} | |
<p class="previous"><a href="/form/results?id={{ id }}&offset={{ prev }}">« {"Previous"}</a></p> | |
{% end %} | |
<p> | |
<table width="100%"> | |
<tr> | |
<th width="10%">{" Submitted "}</th> | |
<th width="10%">{" IP Address "}</th> | |
{% foreach labels %} | |
<th width="10%">{{ loop_value }}</th> | |
{% end %} | |
<th width="10%"> </th> | |
</tr> | |
{% for row in results %} | |
<tr> | |
<td>{{ row->ts|date ('F j, Y - g:ia', strtotime (%s)) }}</td> | |
<td>{{ row->ip }}</td> | |
{% for field, name in labels %} | |
<td>{{ row->{$data->field} }}</td> | |
{% end %} | |
<td><a href="/form/result?id={{ row->id }}" title="{" Show all details "}">{" Details "}</a></td> | |
</tr> | |
{% end %} | |
</table> | |
</p> | |
{% if more %} | |
<p class="next"><a href="/form/results?id={{ id }}&offset={{ next }}">{"Next"} »</a></p> | |
{% end %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Browse a list of results for a specific form. | |
*/ | |
// Set this to the ID of the form | |
$form_id = 1; | |
// Set this to the number of results per page | |
$limit = 20; | |
// The offset of results | |
$_GET['offset'] = (isset ($_GET['offset'])) ? $_GET['offset'] : 0; | |
// Fetch the form info | |
$form = new form\Form ($form_id); | |
// Fetch the results | |
$res = form\Results::query () | |
->where ('form_id', $form_id) | |
->order ('ts desc') | |
->fetch ($limit, $_GET['offset']); | |
// Check if there are any results | |
if (! $res) { | |
$page->title = i18n_get ('No results found.'); | |
printf ('<p><a href="/">%s</a></p>', i18n_get ('Home')); | |
return; | |
} | |
// Count all the results | |
$count = form\Results::query () | |
->where ('form_id', $form_id) | |
->count (); | |
// Set the page title | |
$page->title = i18n_get ('Browsing Results') . ': ' . $form->title; | |
// Get the form labels | |
$labels = $form->labels (); | |
// Normalize the fields for output | |
$fields = array_keys ($labels); | |
foreach ($res as $key => $row) { | |
// Unserialize the form data | |
$result = $row->results; | |
// Loop through fields and normalize | |
foreach ($fields as $field) { | |
if (! isset ($result->{$field})) { | |
$result->{$field} = ''; | |
} elseif (is_array ($result->{$field})) { | |
$result->{$field} = join (', ', $result->{$field}); | |
} | |
} | |
// Add the ID, IP and submission date back in | |
$result->id = $row->id; | |
$result->ip = $row->ip; | |
$result->submitted = $row->ts; | |
// Replace the original result | |
$res[$key] = $result; | |
} | |
// Render the output | |
echo $tpl->render ('form/listresults', array ( | |
'id' => $form_id, | |
'results' => $res, | |
'labels' => $labels, | |
// These are for the pager | |
'count' => $count, | |
'offset' => $_GET['offset'], | |
'more' => ($count > $_GET['offset'] + $limit) ? true : false, | |
'prev' => $_GET['offset'] - $limit, | |
'next' => $_GET['offset'] + $limit | |
)); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment