Steps to add your own report.
Customizing php form:Consider the following "civicrm_contact" table for example:
Case I: Use shortcut method to build a Report to just display the content of the above table Step A: Copy essentials over from an existing report. These statements are conditional on the kind of data you want to report on, so start off with a report that is similar to what you want (Step 1, above). For instance, a template on Contact Relationships starts with the following code. Note the open ellipsis after the class statement, you'll need a closing ellipsis after the postProcess function. Step B: Assuming you don't have any input criteria initialize $this->_columns as Step C: Define postProcess() method: Step D: Make sure the tpl has {include file="CRM/Report/Form.tpl"} as content. Step E: Add the template to CiviCRM per Step 6 above. And you're done! Case II: Use standard method and make report work based on display columns selected. 1. Now since we want user to decide which columns to display: 2. Build select clause based on columns selected: Please note: below method may need not be written for v3.3 or later, as select clause is built by parent class. 3. Build from clause: 4. You are done. But if postProcess() was supposed to be implemented, this is how it would be: Done. Information about the structure and parameters in the .php file
function __construct()This is where you put the field and filter definitions. $this->_columnsAssign $this->_columns to an array of table definitions. The key is any name you want, but it makes sense to use the table name unless you need to use the same table twice in the query. || Parameter || Value || Description ||
fieldsfields is the list of fields that the user can select to display or not.
Then beyond that it seems that as long as you make what you use in select() and other functions match what you did here, it will work. Basically you use whatever combination of the array key, name, alias, and dbAlias so that you have enough uniqueness and that it generates valid SQL. filtersfilters is a list of filters related to the table that the user can use to filter the results.
group_bysgroup_bys is a list of fields from the table that the user can select to group the results.
|| Parameter || Value || Description ||
order_bysorder_bys is a list of fields from the table the user can select to affect the ordering of the results. For each array element, the array key should be equal to the field being exposed for sorting.
|| Parameter || Value || Description ||
adding custom fieldsAs of 3.1 (earlier?) you can add custom fields to a report by adding / modifying the 'extends' line If this line is in the php file then all searchable (check: Is this Field Searchable?) custom data fields that relate to Contact, Individual, Household, or Organisation will be available in the report. Note that 'Contact' ONLY refers to the custom data groups that extend all contacts and does not also include those that extend Individual. This functionality is not limited to 'contact' related fields and activity, relationship etc fields can be added. All searchable fields of that type will be added. There is not currently a simple option to only select some. auto-including custom fields as order_bysIf the property $this->_autoIncludeIndexedFieldsAsOrderBys is set to TRUE, the report will automatically create order_by options for the custom fields added in $this->_customGroupExtends. Since all custom fields are indexed, this does not negatively affect performance. functions select() and where()Most of the time you can probably copy these as is. But see note about group_bys. function from()This is where you define the tables and joins by setting $this->_from to an SQL string. function groupBy()This is where you define the grouping clauses by setting $this->_groupBy to an SQL string. function alter_display()This is where you can reformat column values to be links and such. It also seems to be where you replace values with labels, as opposed to doing it in the SQL? (Can someone confirm if this is the "right" way?) function statistics()This is where you set and execute the query to compute aggregates. As noted above you may need to customize if using grouping. function formRule()Return an array of strings listing any errors you wish to display to the user based on their selections. |
Skip to end of metadata
Go to start of metadata
Labels: