/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
/**
*
*/
- function __construct() {
+ public function __construct() {
$yearsInPast = 4;
- $date = CRM_Core_SelectValues::date('custom', NULL, $yearsInPast, 0);
- $count = $date['maxYear'];
- $optionYear = array('' => ts('-- select --'));
+ $date = CRM_Core_SelectValues::date('custom', NULL, $yearsInPast, 0);
+ $count = $date['maxYear'];
+ $optionYear = array('' => ts('- select -'));
$this->_yearStatisticsFrom = $date['minYear'];
$this->_yearStatisticsTo = $date['maxYear'];
}
$this->_columns = array(
- 'civicrm_contact' =>
- array(
- 'dao' => 'CRM_Contact_DAO_Contact',
- 'fields' =>
- array(
- 'sort_name' =>
- array('title' => ts('Contact Name'),
- 'default' => TRUE,
- 'required' => TRUE,
- 'no_repeat' => TRUE,
+ 'civicrm_contact' => array(
+ 'dao' => 'CRM_Contact_DAO_Contact',
+ 'fields' => array(
+ 'sort_name' => array(
+ 'title' => ts('Contact Name'),
+ 'default' => TRUE,
+ 'required' => TRUE,
+ 'no_repeat' => TRUE,
+ ),
+ 'id' => array(
+ 'no_display' => TRUE,
+ 'default' => TRUE,
+ 'required' => TRUE,
+ ),
+ 'contact_type' => array(
+ 'title' => ts('Contact Type'),
+ ),
+ 'contact_sub_type' => array(
+ 'title' => ts('Contact Subtype'),
+ ),
),
- 'id' =>
- array(
- 'no_display' => TRUE,
- 'default' => TRUE,
- 'required' => TRUE,
- ),
- 'contact_type' =>
- array(
- 'title' => ts('Contact Type'),
- ),
- 'contact_sub_type' =>
- array(
- 'title' => ts('Contact SubType'),
+ 'grouping' => 'contact-fields',
+ 'filters' => array(
+ 'sort_name' => array('title' => ts('Contact Name')),
+ 'id' => array(
+ 'title' => ts('Contact ID'),
+ 'no_display' => TRUE,
+ ),
),
),
- 'grouping' => 'contact-fields',
- 'filters' =>
- array(
- 'sort_name' =>
- array('title' => ts('Contact Name')),
- 'id' =>
- array('title' => ts('Contact ID'),
- 'no_display' => TRUE,
+ 'civicrm_email' => array(
+ 'dao' => 'CRM_Core_DAO_Email',
+ 'fields' => array(
+ 'email' => array(
+ 'title' => ts('Email'),
+ 'no_repeat' => TRUE,
+ ),
),
+ 'grouping' => 'contact-fields',
),
- ),
- 'civicrm_email' =>
- array(
- 'dao' => 'CRM_Core_DAO_Email',
- 'fields' =>
- array(
- 'email' =>
- array('title' => ts('Email'),
- 'no_repeat' => TRUE,
+ 'civicrm_phone' => array(
+ 'dao' => 'CRM_Core_DAO_Phone',
+ 'fields' => array(
+ 'phone' => array(
+ 'title' => ts('Phone'),
+ 'no_repeat' => TRUE,
+ ),
),
+ 'grouping' => 'contact-fields',
),
- 'grouping' => 'contact-fields',
- ),
- 'civicrm_phone' =>
- array(
- 'dao' => 'CRM_Core_DAO_Phone',
- 'fields' =>
- array(
- 'phone' =>
- array('title' => ts('Phone'),
- 'no_repeat' => TRUE,
+ ) + $this->addAddressFields(FALSE, FALSE, FALSE, array()) + array(
+ 'civicrm_relationship' => array(
+ 'dao' => 'CRM_Contact_DAO_Relationship',
+ 'fields' => array(
+ 'relationship_type_id' => array(
+ 'title' => ts('Relationship Type'),
+ 'default' => TRUE,
+ ),
+ 'contact_id_a' => array('no_display' => TRUE),
+ 'contact_id_b' => array('no_display' => TRUE),
),
- ),
- 'grouping' => 'contact-fields',
- ),
- ) + $this->addAddressFields(FALSE, FALSE, FALSE, array(
- )) + array('civicrm_relationship' =>
- array(
- 'dao' => 'CRM_Contact_DAO_Relationship',
- 'fields' =>
- array(
- 'relationship_type_id' =>
- array('title' => ts('Relationship Type'),
- 'default' => TRUE,
- ),
- 'contact_id_a' =>
- array('no_display' => TRUE),
- 'contact_id_b' =>
- array('no_display' => TRUE),
- ),
- 'filters' =>
- array(
- 'relationship_type_id' =>
- array('title' => ts('Relationship Type'),
- 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
- 'options' => $relationTypeOp,
- 'type' => CRM_Utils_Type::T_STRING,
+ 'filters' => array(
+ 'relationship_type_id' => array(
+ 'title' => ts('Relationship Type'),
+ 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
+ 'options' => $relationTypeOp,
+ 'type' => CRM_Utils_Type::T_STRING,
+ ),
),
),
- ),
- ) + array(
- 'civicrm_contribution' =>
- array(
- 'dao' => 'CRM_Contribute_DAO_Contribution',
- 'fields' =>
- array(
- 'total_amount' =>
- array('title' => ts('Amount Statistics'),
- 'default' => TRUE,
- 'required' => TRUE,
- 'no_display' => TRUE,
- 'statistics' =>
- array('sum' => ts('Aggregate Amount')),
+ ) + array(
+ 'civicrm_contribution' => array(
+ 'dao' => 'CRM_Contribute_DAO_Contribution',
+ 'fields' => array(
+ 'total_amount' => array(
+ 'title' => ts('Amount Statistics'),
+ 'default' => TRUE,
+ 'required' => TRUE,
+ 'no_display' => TRUE,
+ 'statistics' => array('sum' => ts('Aggregate Amount')),
+ ),
+ 'receive_date' => array(
+ 'required' => TRUE,
+ 'default' => TRUE,
+ 'no_display' => TRUE,
+ ),
),
- 'receive_date' =>
- array(
- 'required' => TRUE,
- 'default' => TRUE,
- 'no_display' => TRUE,
+ 'grouping' => 'contri-fields',
+ 'filters' => array(
+ 'this_year' => array(
+ 'title' => ts('This Year'),
+ 'operatorType' => CRM_Report_Form::OP_SELECT,
+ 'options' => $optionYear,
+ 'default' => '',
+ ),
+ 'other_year' => array(
+ 'title' => ts('Other Years'),
+ 'operatorType' => CRM_Report_Form::OP_SELECT,
+ 'options' => $optionYear,
+ 'default' => '',
+ ),
+ 'receive_date' => array('operatorType' => CRM_Report_Form::OP_DATE),
+ 'contribution_status_id' => array(
+ 'title' => ts('Contribution Status'),
+ 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
+ 'options' => CRM_Contribute_PseudoConstant::contributionStatus(),
+ 'default' => array(1),
+ ),
+ 'financial_type_id' => array(
+ 'title' => ts('Financial Type'),
+ 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
+ 'options' => CRM_Contribute_PseudoConstant::financialType(),
+ ),
+ 'total_amount' => array(
+ 'title' => ts('Contribution Amount'),
+ ),
+ 'total_sum' => array(
+ 'title' => ts('Aggregate Amount'),
+ 'type' => CRM_Report_Form::OP_INT,
+ 'dbAlias' => 'civicrm_contribution_total_amount_sum',
+ 'having' => TRUE,
+ ),
),
),
- 'grouping' => 'contri-fields',
- 'filters' =>
- array(
- 'this_year' =>
- array(
- 'title' => ts('This Year'),
- 'operatorType' => CRM_Report_Form::OP_SELECT,
- 'options' => $optionYear,
- 'default' => '',
- ),
- 'other_year' =>
- array(
- 'title' => ts('Other Years'),
- 'operatorType' => CRM_Report_Form::OP_SELECT,
- 'options' => $optionYear,
- 'default' => '',
- ),
- 'receive_date' =>
- array('operatorType' => CRM_Report_Form::OP_DATE),
- 'contribution_status_id' =>
- array('title' => ts('Donation Status'),
- 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
- 'options' => CRM_Contribute_PseudoConstant::contributionStatus(),
- 'default' => array(1),
- ),
- 'financial_type_id' => array(
- 'title' => ts('Financial Type'),
- 'operatorType' => CRM_Report_Form::OP_MULTISELECT,
- 'options' => CRM_Contribute_PseudoConstant::financialType(),
- ),
- 'total_amount' =>
- array('title' => ts('Donation Amount'),
- ),
- 'total_sum' =>
- array('title' => ts('Aggregate Amount'),
- 'type' => CRM_Report_Form::OP_INT,
- 'dbAlias' => 'civicrm_contribution_total_amount_sum',
- 'having' => TRUE,
- ),
- ),
- ),
- );
+ );
- $this->_columns['civicrm_contribution']['fields']['civicrm_upto_' . $this->_yearStatisticsFrom] = array('title' => ts('Up To %1 Donation', array(1 => $this->_yearStatisticsFrom)),
+ $this->_columns['civicrm_contribution']['fields']['civicrm_upto_' .
+ $this->_yearStatisticsFrom] = array(
+ 'title' => ts('Up To %1 Donation', array(1 => $this->_yearStatisticsFrom)),
'default' => TRUE,
'type' => CRM_Utils_Type::T_MONEY,
'is_statistics' => TRUE,
$yearConter = $this->_yearStatisticsFrom;
$yearConter++;
while ($yearConter <= $this->_yearStatisticsTo) {
- $this->_columns['civicrm_contribution']['fields'][$yearConter] = array('title' => ts('%1 Donation', array(1 => $yearConter)),
+ $this->_columns['civicrm_contribution']['fields'][$yearConter] = array(
+ 'title' => ts('%1 Donation', array(1 => $yearConter)),
'default' => TRUE,
'type' => CRM_Utils_Type::T_MONEY,
'is_statistics' => TRUE,
$yearConter++;
}
- $this->_columns['civicrm_contribution']['fields']['aggregate_amount'] = array('title' => ts('Aggregate Amount'),
+ $this->_columns['civicrm_contribution']['fields']['aggregate_amount'] = array(
+ 'title' => ts('Aggregate Amount'),
'type' => CRM_Utils_Type::T_MONEY,
'is_statistics' => TRUE,
);
parent::__construct();
}
- function preProcess() {
+ public function preProcess() {
parent::preProcess();
}
- function select() {
+ public function select() {
$select = array();
$this->_columnHeaders = array();
if (array_key_exists('fields', $table)) {
foreach ($table['fields'] as $fieldName => $field) {
- if (!empty($field['required']) || !empty($this->_params['fields'][$fieldName])) {
+ if (!empty($field['required']) ||
+ !empty($this->_params['fields'][$fieldName])
+ ) {
if ($tableName == 'civicrm_address') {
$this->_addressField = TRUE;
}
continue;
}
elseif ($fieldName == 'receive_date') {
- if ((CRM_Utils_Array::value('this_year_op', $this->_params) == 'fiscal' && !empty($this->_params['this_year_value'])) ||
- (CRM_Utils_Array::value('other_year_op', $this->_params == 'fiscal') && !empty($this->_params['other_year_value']))){
- $select[] = self::fiscalYearOffset($field['dbAlias']) . " as {$tableName}_{$fieldName}";
- }else{
- $select[] = " YEAR(".$field['dbAlias'].")" . " as {$tableName}_{$fieldName}";
- }
+ if ((CRM_Utils_Array::value('this_year_op', $this->_params) ==
+ 'fiscal' && !empty($this->_params['this_year_value'])) ||
+ (CRM_Utils_Array::value('other_year_op', $this->_params ==
+ 'fiscal') && !empty($this->_params['other_year_value']))
+ ) {
+ $select[] = self::fiscalYearOffset($field['dbAlias']) .
+ " as {$tableName}_{$fieldName}";
+ }
+ else {
+ $select[] = " YEAR(" . $field['dbAlias'] . ")" .
+ " as {$tableName}_{$fieldName}";
+ }
}
elseif ($fieldName == 'total_amount') {
$select[] = "SUM({$field['dbAlias']}) as {$tableName}_{$fieldName}";
$this->_select = "SELECT " . implode(', ', $select) . " ";
}
- function from() {
+ public function from() {
$this->_from = "
FROM civicrm_contact {$this->_aliases['civicrm_contact']}
INNER JOIN civicrm_contribution {$this->_aliases['civicrm_contribution']}
}
}
- function where() {
+ public function where() {
$whereClauses = $havingClauses = $relationshipWhere = array();
$this->_relationshipWhere = '';
$this->_statusClause = '';
$clause = NULL;
if ($fieldName == 'this_year' || $fieldName == 'other_year') {
continue;
- }elseif (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) {
+ }
+ elseif (CRM_Utils_Array::value('type', $field) &
+ CRM_Utils_Type::T_DATE
+ ) {
$relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params);
- $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params);
- $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params);
+ $from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params);
+ $to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params);
$clause = $this->dateClause($field['name'], $relative, $from, $to, $field['type']);
}
}
if (!empty($relationshipWhere)) {
- $this->_relationshipWhere = ' AND ' . implode(' AND ', $relationshipWhere);
+ $this->_relationshipWhere = ' AND ' .
+ implode(' AND ', $relationshipWhere);
}
}
- function groupBy() {
+ public function groupBy() {
$this->_groupBy = "GROUP BY {$this->_aliases['civicrm_contribution']}.contact_id, YEAR({$this->_aliases['civicrm_contribution']}.receive_date)";
}
/**
* @param int $rowCount
*/
- function limit($rowCount = self::ROW_COUNT_LIMIT) {
+ public function limit($rowCount = self::ROW_COUNT_LIMIT) {
parent::limit($rowCount);
}
/**
* @param int $rowCount
*/
- function setPager($rowCount = self::ROW_COUNT_LIMIT) {
+ public function setPager($rowCount = self::ROW_COUNT_LIMIT) {
parent::setPager($rowCount);
}
*
* @return array
*/
- function statistics(&$rows) {
+ public function statistics(&$rows) {
$statistics = parent::statistics($rows);
$count = 0;
foreach ($rows as $rownum => $row) {
$count++;
}
}
- $statistics['counts']['rowCount'] = array('title' => ts('Primary Contact(s) Listed'),
+ $statistics['counts']['rowCount'] = array(
+ 'title' => ts('Primary Contact(s) Listed'),
'value' => $count,
);
if ($this->_rowsFound && ($this->_rowsFound > $count)) {
- $statistics['counts']['rowsFound'] = array('title' => ts('Total Primary Contact(s)'),
+ $statistics['counts']['rowsFound'] = array(
+ 'title' => ts('Total Primary Contact(s)'),
'value' => $this->_rowsFound,
);
}
*
* @return array
*/
- static function formRule($fields, $files, $self) {
+ public static function formRule($fields, $files, $self) {
$errors = array();
- if (!empty($fields['this_year_value']) && !empty($fields['other_year_value']) &&
+ if (!empty($fields['this_year_value']) &&
+ !empty($fields['other_year_value']) &&
($fields['this_year_value'] == $fields['other_year_value'])
) {
$errors['other_year_value'] = ts("Value for filters 'This Year' and 'Other Years' can not be same.");
return $errors;
}
- function postProcess() {
+ public function postProcess() {
// get ready with post process params
$this->beginPostProcess();
$this->fixReportParams();
$this->endPostProcess($rows);
}
- function fixReportParams() {
+ public function fixReportParams() {
if (!empty($this->_params['this_year_value'])) {
$this->_referenceYear['this_year'] = $this->_params['this_year_value'];
}
/**
* @param $rows
*/
- function buildRows($sql, &$rows) {
+ public function buildRows($sql, &$rows) {
$contactIds = array();
$addWhere = '';
if (!empty($this->_referenceYear['other_year'])) {
- (CRM_Utils_Array::value('other_year_op', $this->_params) == 'calendar') ? $other_receive_date = 'YEAR (contri.receive_date)' : $other_receive_date = self::fiscalYearOffset('contri.receive_date');
- $addWhere .= " AND {$this->_aliases['civicrm_contact']}.id NOT IN ( SELECT DISTINCT cont.id FROM civicrm_contact cont, civicrm_contribution contri WHERE cont.id = contri.contact_id AND {$other_receive_date} = {$this->_referenceYear['other_year']} AND contri.is_test = 0 ) ";
+ (CRM_Utils_Array::value('other_year_op', $this->_params) ==
+ 'calendar') ? $other_receive_date = 'YEAR (contri.receive_date)' : $other_receive_date = self::fiscalYearOffset('contri.receive_date');
+ $addWhere .= " AND {$this->_aliases['civicrm_contact']}.id NOT IN ( SELECT DISTINCT cont.id FROM civicrm_contact cont, civicrm_contribution contri WHERE cont.id = contri.contact_id AND {$other_receive_date} = {$this->_referenceYear['other_year']} AND contri.is_test = 0 ) ";
}
if (!empty($this->_referenceYear['this_year'])) {
- (CRM_Utils_Array::value('this_year_op', $this->_params) == 'calendar') ? $receive_date = 'YEAR (contri.receive_date)' : $receive_date = self::fiscalYearOffset('contri.receive_date');
- $addWhere .= " AND {$this->_aliases['civicrm_contact']}.id IN ( SELECT DISTINCT cont.id FROM civicrm_contact cont, civicrm_contribution contri WHERE cont.id = contri.contact_id AND {$receive_date} = {$this->_referenceYear['this_year']} AND contri.is_test = 0 ) ";
+ (CRM_Utils_Array::value('this_year_op', $this->_params) ==
+ 'calendar') ? $receive_date = 'YEAR (contri.receive_date)' : $receive_date = self::fiscalYearOffset('contri.receive_date');
+ $addWhere .= " AND {$this->_aliases['civicrm_contact']}.id IN ( SELECT DISTINCT cont.id FROM civicrm_contact cont, civicrm_contribution contri WHERE cont.id = contri.contact_id AND {$receive_date} = {$this->_referenceYear['this_year']} AND contri.is_test = 0 ) ";
}
$this->limit();
$getContacts = "SELECT SQL_CALC_FOUND_ROWS {$this->_aliases['civicrm_contact']}.id as cid, SUM({$this->_aliases['civicrm_contribution']}.total_amount) as civicrm_contribution_total_amount_sum {$this->_from} {$this->_where} {$addWhere} GROUP BY {$this->_aliases['civicrm_contact']}.id {$this->_having} {$this->_limit}";
$relatedContributions = $this->buildContributionRows($relatedContactIds);
- $summaryYears = array();
+ $summaryYears = array();
$summaryYears[] = "civicrm_upto_{$this->_yearStatisticsFrom}";
- $yearConter = $this->_yearStatisticsFrom;
+ $yearConter = $this->_yearStatisticsFrom;
$yearConter++;
while ($yearConter <= $this->_yearStatisticsTo) {
$summaryYears[] = $yearConter;
*
* @return array
*/
- function buildContributionRows($contactIds) {
+ public function buildContributionRows($contactIds) {
$rows = array();
if (empty($contactIds)) {
return $rows;
}
- $sqlContribution = "{$this->_select} {$this->_from} WHERE {$this->_aliases['civicrm_contact']}.id IN (" . implode(',', $contactIds) . ") AND {$this->_aliases['civicrm_contribution']}.is_test = 0 {$this->_statusClause} {$this->_groupBy} ";
+ $sqlContribution =
+ "{$this->_select} {$this->_from} WHERE {$this->_aliases['civicrm_contact']}.id IN (" .
+ implode(',', $contactIds) .
+ ") AND {$this->_aliases['civicrm_contribution']}.is_test = 0 {$this->_statusClause} {$this->_groupBy} ";
- $dao = CRM_Core_DAO::executeQuery($sqlContribution);
+ $dao = CRM_Core_DAO::executeQuery($sqlContribution);
$contributionSum = 0;
- $yearcal = array();
+ $yearcal = array();
while ($dao->fetch()) {
if (!$dao->civicrm_contact_id) {
continue;
}
}
if ($dao->civicrm_contribution_receive_date) {
- if ($dao->civicrm_contribution_receive_date > $this->_yearStatisticsFrom) {
+ if ($dao->civicrm_contribution_receive_date >
+ $this->_yearStatisticsFrom
+ ) {
$rows[$dao->civicrm_contact_id][$dao->civicrm_contribution_receive_date] = $dao->civicrm_contribution_total_amount;
}
else {
*
* @return array
*/
- function buildRelationshipRows($contactIds) {
+ public function buildRelationshipRows($contactIds) {
$relationshipRows = $relatedContactIds = array();
if (empty($contactIds)) {
return array($relationshipRows, $relatedContactIds);
if (!empty($this->_relationshipColumns)) {
$addRelSelect = ', ' . implode(', ', $this->_relationshipColumns);
}
- $sqlRelationship = "SELECT {$this->_aliases['civicrm_relationship']}.relationship_type_id as relationship_type_id, {$this->_aliases['civicrm_relationship']}.contact_id_a as contact_id_a, {$this->_aliases['civicrm_relationship']}.contact_id_b as contact_id_b {$addRelSelect} FROM civicrm_contact {$relContactAlias} {$this->_relationshipFrom} WHERE {$relContactAlias}.id IN (" . implode(',', $contactIds) . ") AND {$this->_aliases['civicrm_relationship']}.is_active = 1 {$this->_relationshipWhere} GROUP BY {$this->_aliases['civicrm_relationship']}.contact_id_a, {$this->_aliases['civicrm_relationship']}.contact_id_b";
+ $sqlRelationship =
+ "SELECT {$this->_aliases['civicrm_relationship']}.relationship_type_id as relationship_type_id, {$this->_aliases['civicrm_relationship']}.contact_id_a as contact_id_a, {$this->_aliases['civicrm_relationship']}.contact_id_b as contact_id_b {$addRelSelect} FROM civicrm_contact {$relContactAlias} {$this->_relationshipFrom} WHERE {$relContactAlias}.id IN (" .
+ implode(',', $contactIds) .
+ ") AND {$this->_aliases['civicrm_relationship']}.is_active = 1 {$this->_relationshipWhere} GROUP BY {$this->_aliases['civicrm_relationship']}.contact_id_a, {$this->_aliases['civicrm_relationship']}.contact_id_b";
$relationshipTypes = CRM_Core_PseudoConstant::relationshipType();
$dao = CRM_Core_DAO::executeQuery($sqlRelationship);
*
* @return array
*/
- function getOperationPair($type = "string", $fieldName = NULL) {
+ public function getOperationPair($type = "string", $fieldName = NULL) {
if ($fieldName == 'this_year' || $fieldName == 'other_year') {
- return array('calendar' => ts('Is Calendar Year'), 'fiscal' => ts('Fiscal Year Starting'));
+ return array(
+ 'calendar' => ts('Is Calendar Year'),
+ 'fiscal' => ts('Fiscal Year Starting')
+ );
}
return parent::getOperationPair($type, $fieldName);
}
/**
* @param $rows
*/
- function alterDisplay(&$rows) {
+ public function alterDisplay(&$rows) {
if (empty($rows)) {
return;
}
}
// Convert Display name into link
- if (!empty($row['civicrm_contact_sort_name']) && !empty($row['civicrm_contact_id'])) {
+ if (!empty($row['civicrm_contact_sort_name']) &&
+ !empty($row['civicrm_contact_id'])
+ ) {
$url = CRM_Report_Utils_Report::getNextUrl('contribute/detail',
'reset=1&force=1&id_op=eq&id_value=' . $row['civicrm_contact_id'],
$this->_absoluteUrl, $this->_id
}
}
}
- }
-
+}