You are here

README.txt in Views Aggregator Plus 7

Same filename and directory in other branches
  1. 8 README.txt
VIEWS AGGREGATOR PLUS
=====================
Because the Views and ViewsCalc modules rely on the database to perform
aggregation, you only have limited options at your disposal. That is where this
module comes in. Unlike Views and ViewsCalc, this module:
o enumerates group members (see https://drupal.org/node/1300900)
o produces tallies (textual histograms, see http://drupal.org/node/1256716)
o can aggregate on ViewsPHP code-snippets
o can filter out rows on regular expressions (regexp)
o can aggregate across entire columns (e.g show column data range at the top)
o lets you add your own custom aggregation functions to the existing set
o aggregation functions can take parameters, as currently employed by "Filter
  rows", "Count" and "Label"
o on Views of type "Webform submissions" the module supports the field "Webform
  submission data: Value" (requires Webform 7.x-4.x)

Basics Recap: what is aggregation again?
----------------------------------------
In the context of Views and this module, aggregation is the process of grouping
and collapsing result rows on the identical values of ONE column, while at the
same time applying "summary" functions on other columns. For example you can
group the result set on a taxonomy term, so that all rows sharing the same
value of the taxonomy column are represented as single rows, with aggregation
functions, like TALLY, SUM, or ENUMERATE applied to the remaining columns.

Example
-------
Say the original View based on raw database results looks like below.

Industry|Company Name |     Turnover |
--------|-------------|--------------|
IT      |       AquiB |  $25,000,000 |
Clothing|    Cenneton |  $99,000,000 |
Food    |       Heiny |  $66,000,000 |
IT      |PreviousBest |  $ 5,000,000 |
Food    |   McRonalds | $500,000,000 |

Then with the grouping taking place on, say Industry, and aggregation functions
COUNT and SUM applied on Company Name and Turnover respectively, the final
result will display like below. A descending sort was applied to
Turnover and the display name of "Company Name" was changed to "Comp. Count".

Industry| Comp. Count |     Turnover |
--------|-------------|--------------|
Food    |           2 | $566,000,000 |
Clothing|           1 |  $99,000,000 |
IT      |           2 |  $30,000,000 |

That's the basics and you can do the above with Views. But with Views
Aggregator Plus (VAgg+) you can also aggregate like below, using its TALLY and
ENUMERATE group aggregation functions, as well as LABEL, COUNT and SUM for the
added bottom row.

Industry    |Companies           |     Turnover |
------------|--------------------|--------------|
Food (2)    |Heiny, McRonalds    | $566,000,000 |
Clothing (1)|Cenneton            |  $99,000,000 |
IT (2)      |AcquiB, PreviousBest|  $30,000,000 |
------------|--------------------|--------------|
Totals      |                  5 | $695,000,000 |
------------------------------------------------

But that's just the beginning. Remember, you can aggregate on ViewsPHP
expressions, so the possibilities are endless! Say you have a content type
"event" that has a date range field on it with both start and end components
active. Let's say its machine name is "field_duration". The code snippet below
entered in the "Output code" area of a Views PHP field will output in Views for
each event whether it is in progress, closed or not started yet.

<?php
  $start_date = strtotime($data->field_field_duration[0]['raw']['value']);
  $end_date   = strtotime($data->field_field_duration[0]['raw']['value2']);
  echo time() < $start_date ? 'not started' : (time() < $end_date ? 'underway' : 'closed');
?>

Next you can use VAgg+ to group on the expression and count or enumerate the
event titles in each of these categories.

HOW TO USE
----------
On the main Views UI page, admin/structure/views/view/YOUR-VIEW/edit/page,
under Format, click and select "Table with aggregation options". Having arrived
at the Settings page, follow the hints under the header "Style Options".
All group aggregation functions, except "Filter rows" require exactly one field
to be assigned the "Group and compress" function.
Column aggregation functions may be used independently of group aggregation
functions. If a column aggregation function requires an argument, it may take
it from the corresponding group aggregation function, if also enabled.

There are no permissions or global module configurations.

Views Aggregator Plus does not combine well with Views' native aggregation.
So in the Advanced section (upper right) set "Use aggregation: No".

Keep in mind that the process of grouping and aggregation as performed by this
module is different from the Grouping option in Views. With Grouping in Views
the total number of rows remains the same, but the rows are grouped in separate
tables. With this module, the number of rows is reduced as they are grouped and
collapsed, but the end result is always a single table.

FUNCTION PARAMETERS
-------------------
Functions marked with an asterisk take an optional parameter.

"Group and Compress" takes an optional keyword 'case-insensitive' (in English or
in the translated language on your site) to perform grouping in a
case-insensitive manner. The default is case-sensitive.

"Average" takes an optional precision: the number of decimals to round to after
calculating the average.

"Range", "Tally members" and the two "Enumerate" functions use their parameter
to specify the separator. The default is an HTML line-break, <br/>, for "Tally"
and "Enumerate" and ' - ' for "Range".

"Filter rows" and "Count" take a regular expression. This is explained below.

REGEXPS
-------
Some aggregation functions, like "Filter rows" and "Count" take a regular
expression as a parameter. In its simplest form a regular expression is a word
or part of a word you want to filter on. If you use regexps in this way, you may
omit the special delimiters around the parameter, most commonly a pair of
forward slashes. So "red" and "/red/" are equivalent.
Here are some more regexps:

/RED/i         targets rows that contain the word "red" in the field specified,
               case-insensitive
/red|blue/     rows with either the word "red" or "blue" in the field
/^(Red|Blue)/  rows where the specified field begins with "Red" or "Blue"
/Z[0-9]+/      the letter Z followed by one or more digits

Ref: http://work.lauralemay.com/samples/perl.html (for PERL, but quite good)

LIMITATIONS
-----------
o If an aggregation function result does not display correctly, try changing the
  field formatter. For example use "Plain text", rather than "Default".
o Views-style table grouping, whereby the original table is split into smaller
  ones, interferes with this plugin, so is not available.
o When you have an aggregated View AND a normal View attachment on the same
  page AND you click-sort on Global:Math Expression the normal View attachment
  will temporarily disappear. This is because the sort is passed to BOTH
  displays and normal Views do not support sorting on Math Expressions.
o When you apply two aggregation functions on the same field, the 2nd function
  gets applied on the results of the first -- not always what you want.
o Grouping, tallying and other functions may not work correctly when you have
  the "Theme Developer" module enabled.

TIPS FOR USING VIEWS PHP MODULE
-------------------------------
Use "Output code", not "Value code", as in the "Value code" area few Views
results are available. Here are some examples of the syntax to use for various
field types for access in the "Output code" text area. Note that to display
these values you need to put "echo" in front of the expression and place the
<?php and ?> "brackets" around everything.

// General fields, say a field named "Total", machine name: "field_total"
Raw value: $data->field_field_total[0]['raw']['value'] // 1000
Rendered value (i.e. marked-up for display):
$data->field_field_total[0]['rendered']['#markup'] // $ 1,000.00

// Dates, machine name "field_duration" (start & end dates),
Raw start: $data->field_field_duration[0]['raw']['value']// 2013-06-02 00:00:00
Raw end: $data->field_field_duration[0]['raw']['value2'] // 2013-06-04 00:00:00
Rendered: $data->field_field_duration[0]['rendered']['#markup'];  //"Sun
 02-Jun-2013 to Wed 04-Jun-2013"

// Taxonomy terms, machine name: "field_industry"
Raw: $data->field_field_industry[0]['raw']['tid']
Rendered: $data->field_field_industry[0]['rendered']['#title']

ACKNOWLEDGMENT
--------------
The UI of this module borrows heavily from Views Calc and the work by the
authors and contributors done on that module is gratefully acknowledged.

REFs
----
https://drupal.org/node/1219356#comment-4782582
https://drupal.org/node/1219356#comment-6909160
https://drupal.org/node/1300900
https://drupal.org/node/1791796
https://drupal.org/node/1140896#comment-7657061

File

README.txt
View source
  1. VIEWS AGGREGATOR PLUS
  2. =====================
  3. Because the Views and ViewsCalc modules rely on the database to perform
  4. aggregation, you only have limited options at your disposal. That is where this
  5. module comes in. Unlike Views and ViewsCalc, this module:
  6. o enumerates group members (see https://drupal.org/node/1300900)
  7. o produces tallies (textual histograms, see http://drupal.org/node/1256716)
  8. o can aggregate on ViewsPHP code-snippets
  9. o can filter out rows on regular expressions (regexp)
  10. o can aggregate across entire columns (e.g show column data range at the top)
  11. o lets you add your own custom aggregation functions to the existing set
  12. o aggregation functions can take parameters, as currently employed by "Filter
  13. rows", "Count" and "Label"
  14. o on Views of type "Webform submissions" the module supports the field "Webform
  15. submission data: Value" (requires Webform 7.x-4.x)
  16. Basics Recap: what is aggregation again?
  17. ----------------------------------------
  18. In the context of Views and this module, aggregation is the process of grouping
  19. and collapsing result rows on the identical values of ONE column, while at the
  20. same time applying "summary" functions on other columns. For example you can
  21. group the result set on a taxonomy term, so that all rows sharing the same
  22. value of the taxonomy column are represented as single rows, with aggregation
  23. functions, like TALLY, SUM, or ENUMERATE applied to the remaining columns.
  24. Example
  25. -------
  26. Say the original View based on raw database results looks like below.
  27. Industry|Company Name | Turnover |
  28. --------|-------------|--------------|
  29. IT | AquiB | $25,000,000 |
  30. Clothing| Cenneton | $99,000,000 |
  31. Food | Heiny | $66,000,000 |
  32. IT |PreviousBest | $ 5,000,000 |
  33. Food | McRonalds | $500,000,000 |
  34. Then with the grouping taking place on, say Industry, and aggregation functions
  35. COUNT and SUM applied on Company Name and Turnover respectively, the final
  36. result will display like below. A descending sort was applied to
  37. Turnover and the display name of "Company Name" was changed to "Comp. Count".
  38. Industry| Comp. Count | Turnover |
  39. --------|-------------|--------------|
  40. Food | 2 | $566,000,000 |
  41. Clothing| 1 | $99,000,000 |
  42. IT | 2 | $30,000,000 |
  43. That's the basics and you can do the above with Views. But with Views
  44. Aggregator Plus (VAgg+) you can also aggregate like below, using its TALLY and
  45. ENUMERATE group aggregation functions, as well as LABEL, COUNT and SUM for the
  46. added bottom row.
  47. Industry |Companies | Turnover |
  48. ------------|--------------------|--------------|
  49. Food (2) |Heiny, McRonalds | $566,000,000 |
  50. Clothing (1)|Cenneton | $99,000,000 |
  51. IT (2) |AcquiB, PreviousBest| $30,000,000 |
  52. ------------|--------------------|--------------|
  53. Totals | 5 | $695,000,000 |
  54. ------------------------------------------------
  55. But that's just the beginning. Remember, you can aggregate on ViewsPHP
  56. expressions, so the possibilities are endless! Say you have a content type
  57. "event" that has a date range field on it with both start and end components
  58. active. Let's say its machine name is "field_duration". The code snippet below
  59. entered in the "Output code" area of a Views PHP field will output in Views for
  60. each event whether it is in progress, closed or not started yet.
  61. $start_date = strtotime($data->field_field_duration[0]['raw']['value']);
  62. $end_date = strtotime($data->field_field_duration[0]['raw']['value2']);
  63. echo time() < $start_date ? 'not started' : (time() < $end_date ? 'underway' : 'closed');
  64. ?>
  65. Next you can use VAgg+ to group on the expression and count or enumerate the
  66. event titles in each of these categories.
  67. HOW TO USE
  68. ----------
  69. On the main Views UI page, admin/structure/views/view/YOUR-VIEW/edit/page,
  70. under Format, click and select "Table with aggregation options". Having arrived
  71. at the Settings page, follow the hints under the header "Style Options".
  72. All group aggregation functions, except "Filter rows" require exactly one field
  73. to be assigned the "Group and compress" function.
  74. Column aggregation functions may be used independently of group aggregation
  75. functions. If a column aggregation function requires an argument, it may take
  76. it from the corresponding group aggregation function, if also enabled.
  77. There are no permissions or global module configurations.
  78. Views Aggregator Plus does not combine well with Views' native aggregation.
  79. So in the Advanced section (upper right) set "Use aggregation: No".
  80. Keep in mind that the process of grouping and aggregation as performed by this
  81. module is different from the Grouping option in Views. With Grouping in Views
  82. the total number of rows remains the same, but the rows are grouped in separate
  83. tables. With this module, the number of rows is reduced as they are grouped and
  84. collapsed, but the end result is always a single table.
  85. FUNCTION PARAMETERS
  86. -------------------
  87. Functions marked with an asterisk take an optional parameter.
  88. "Group and Compress" takes an optional keyword 'case-insensitive' (in English or
  89. in the translated language on your site) to perform grouping in a
  90. case-insensitive manner. The default is case-sensitive.
  91. "Average" takes an optional precision: the number of decimals to round to after
  92. calculating the average.
  93. "Range", "Tally members" and the two "Enumerate" functions use their parameter
  94. to specify the separator. The default is an HTML line-break,
    , for "Tally"
  95. and "Enumerate" and ' - ' for "Range".
  96. "Filter rows" and "Count" take a regular expression. This is explained below.
  97. REGEXPS
  98. -------
  99. Some aggregation functions, like "Filter rows" and "Count" take a regular
  100. expression as a parameter. In its simplest form a regular expression is a word
  101. or part of a word you want to filter on. If you use regexps in this way, you may
  102. omit the special delimiters around the parameter, most commonly a pair of
  103. forward slashes. So "red" and "/red/" are equivalent.
  104. Here are some more regexps:
  105. /RED/i targets rows that contain the word "red" in the field specified,
  106. case-insensitive
  107. /red|blue/ rows with either the word "red" or "blue" in the field
  108. /^(Red|Blue)/ rows where the specified field begins with "Red" or "Blue"
  109. /Z[0-9]+/ the letter Z followed by one or more digits
  110. Ref: http://work.lauralemay.com/samples/perl.html (for PERL, but quite good)
  111. LIMITATIONS
  112. -----------
  113. o If an aggregation function result does not display correctly, try changing the
  114. field formatter. For example use "Plain text", rather than "Default".
  115. o Views-style table grouping, whereby the original table is split into smaller
  116. ones, interferes with this plugin, so is not available.
  117. o When you have an aggregated View AND a normal View attachment on the same
  118. page AND you click-sort on Global:Math Expression the normal View attachment
  119. will temporarily disappear. This is because the sort is passed to BOTH
  120. displays and normal Views do not support sorting on Math Expressions.
  121. o When you apply two aggregation functions on the same field, the 2nd function
  122. gets applied on the results of the first -- not always what you want.
  123. o Grouping, tallying and other functions may not work correctly when you have
  124. the "Theme Developer" module enabled.
  125. TIPS FOR USING VIEWS PHP MODULE
  126. -------------------------------
  127. Use "Output code", not "Value code", as in the "Value code" area few Views
  128. results are available. Here are some examples of the syntax to use for various
  129. field types for access in the "Output code" text area. Note that to display
  130. these values you need to put "echo" in front of the expression and place the
  131. "brackets" around everything.
  132. // General fields, say a field named "Total", machine name: "field_total"
  133. Raw value: $data->field_field_total[0]['raw']['value'] // 1000
  134. Rendered value (i.e. marked-up for display):
  135. $data->field_field_total[0]['rendered']['#markup'] // $ 1,000.00
  136. // Dates, machine name "field_duration" (start & end dates),
  137. Raw start: $data->field_field_duration[0]['raw']['value']// 2013-06-02 00:00:00
  138. Raw end: $data->field_field_duration[0]['raw']['value2'] // 2013-06-04 00:00:00
  139. Rendered: $data->field_field_duration[0]['rendered']['#markup']; //"Sun
  140. 02-Jun-2013 to Wed 04-Jun-2013"
  141. // Taxonomy terms, machine name: "field_industry"
  142. Raw: $data->field_field_industry[0]['raw']['tid']
  143. Rendered: $data->field_field_industry[0]['rendered']['#title']
  144. ACKNOWLEDGMENT
  145. --------------
  146. The UI of this module borrows heavily from Views Calc and the work by the
  147. authors and contributors done on that module is gratefully acknowledged.
  148. REFs
  149. ----
  150. https://drupal.org/node/1219356#comment-4782582
  151. https://drupal.org/node/1219356#comment-6909160
  152. https://drupal.org/node/1300900
  153. https://drupal.org/node/1791796
  154. https://drupal.org/node/1140896#comment-7657061