Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Sort the printable list on name_surname by default. Sort argument fro…

…m the query string is also supported.
  • Loading branch information...
commit be07208cf5a46d8b7354fbce1776e5073bc053ac 1 parent c2a89a4
@arjan arjan authored
View
15 modules/mod_survey/models/m_survey.erl
@@ -64,6 +64,8 @@ m_find_value(Id, #m{value=questions}, Context) ->
end;
m_find_value(Id, #m{value=results}, Context) ->
prepare_results(Id, Context);
+m_find_value([Id, SortColumn], #m{value=all_results}, Context) ->
+ survey_results_sorted(Id, SortColumn, Context);
m_find_value(Id, #m{value=all_results}, Context) ->
survey_results(Id, Context);
m_find_value(Id, #m{value=captions}, Context) ->
@@ -230,6 +232,19 @@ survey_stats(SurveyId, Context) ->
group_values(N, [{V,C}], Rs, [{Name,Values}|Acc]).
+survey_results_sorted(SurveyId, SortColumn, Context) ->
+ [Headers|Data] = survey_results(SurveyId, Context),
+ case string:str(Headers, [list_to_binary(SortColumn)]) of
+ 0 ->
+ %% column not found, do not sort
+ [Headers|Data];
+ N ->
+ %% Sort on nth row
+ Data1 = [{lists:nth(N, Row), Row} || Row <- Data],
+ Data2 = [Row1 || {_, Row1} <- lists:sort(Data1)],
+ [Headers|Data2]
+ end.
+
%% @doc Return all results of a survey
survey_results(SurveyId, Context) ->
case m_rsc:p(SurveyId, survey, Context) of
View
6 modules/mod_survey/templates/survey_results_printable.tpl
@@ -1,5 +1,5 @@
{% with q.id|default:id as id %}
-{% with m.survey.all_results[id] as r %}
+{% with m.survey.all_results[[id, q.sort|default:"name_surname"]] as r %}
{% with r|first as columns %}
{% with r|tail as results %}
@@ -11,7 +11,7 @@
<table width="100%">
<tr>
<th>&nbsp;</th>
- {% for name in columns|tail|tail %}
+ {% for name in columns|tail|tail|tail %}
<th align="left">{{ captions[name] }}</th>
{% endfor %}
</tr>
@@ -19,7 +19,7 @@
{% for r in results %}
<tr id="survey-result-{{ r[1] }}-{{ r[2] }}">
<td align="right">{{ forloop.counter }}.&nbsp;&nbsp;</td>
- {% for value in r|tail|tail %}
+ {% for value in r|tail|tail|tail %}
<td>{{ value }}</td>
{% endfor %}
</tr>
Please sign in to comment.
Something went wrong with that request. Please try again.