Below is a step by step process for how we created custom reports. Please see the attached php code sample as well as an example screen shot of what the code sample returns.
* The file paths below assume a default system installation *
{include file="CRM/Report/Form.tpl"} |
* Note: When entering a value in the "class" field, it is very important you follow the format suggested for that field (e.g., CRM_Report_Form_Contribute_[yourClassName]). This gets translated into the actual path to your custom .tpl file (i.e., civicrm_custom/CRM/Report/Form/Contribute/yourClassName.tpl).
SELECT cov.value FROM civicrm_option_value_en_oo cov WHERE cov.option_group_id=27 ORDER BY cov.value |
SELECT cov.label FROM civicrm_option_value_en_oo cov WHERE cov.option_group_id=2 ORDER BY cov.label |
CREATE TEMPORARY TABLE IF NOT EXISTS ywcaHealthMembershipDemographics1 (id INT not null auto_increment, case varchar(50) not null, total int not null, membership varchar(50) not null, gender varchar(12) not null, PRIMARY KEY(id)) |
select * from ywcaHealthMembershipDemographics1 |
INSERT INTO membershipDemographics1 (program, total, membership, gender) SELECT cov.label AS program, Count( DISTINCT contact.id ) AS total, cvyi.ywca_member_746 AS membership, dd.gender_616 AS gender FROM civicrm_case cc, civicrm_contact contact, civicrm_value_demographic_data_20 dd, civicrm_option_value_en_oo cov, civicrm_value_ywca_involvment_15 cvyi, civicrm_case_contact ccc WHERE cc.case_type_id LIKE '%".$value."%' AND cc.id = ccc.case_id AND contact.id = ccc.contact_id AND contact.id = cvyi.entity_id AND contact.id = dd.entity_id AND cov.option_group_id=27 AND cov.value =".$value." AND cc.is_deleted = 0 AND (substring(cc.start_date,6,2) +0)<='$userMonth' AND (substring(cc.start_date,0,4) +0)<='$userYear' GROUP BY cvyi.ywca_member_746, dd.gender_616 |
Note that when you have set a filter in a report using the $_columns you can filter through the URL - e.g for gender_id=1 url would be sth like => http://drupal.demo.civicrm.org/civicrm/report/instance/X?reset=1&force=1&gender_id_op=eq&gender_id_value=1 for multiselect fields _op could also be set to "in" and u could provide multiple values separated by + or , signs (need to check code) |