/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
/**
*
*/
- function __construct() {
+ public function __construct() {
$this->_columns = array(
- 'civicrm_contact' =>
- array(
+ 'civicrm_contact' => array(
'dao' => 'CRM_Contact_DAO_Contact',
'grouping' => 'contact-fields',
- 'fields' =>
- array(
- 'sort_name' =>
- array(
+ 'fields' => array(
+ 'sort_name' => array(
'title' => ts('Contact Name'),
'no_repeat' => TRUE,
'default' => TRUE,
),
- 'display_name' =>
- array(
+ 'display_name' => array(
'title' => ts('Display Name'),
'no_repeat' => TRUE,
),
- 'addressee_display' =>
- array(
+ 'addressee_display' => array(
'title' => ts('Addressee Name'),
'no_repeat' => TRUE,
),
- 'id' =>
- array(
+ 'id' => array(
'no_display' => TRUE,
'required' => TRUE,
),
- 'contact_type' =>
- array(
+ 'contact_type' => array(
'title' => ts('Contact Type'),
'no_repeat' => TRUE,
),
- 'contact_sub_type' =>
- array(
- 'title' => ts('Contact SubType'),
+ 'contact_sub_type' => array(
+ 'title' => ts('Contact Subtype'),
'no_repeat' => TRUE,
),
),
- 'filters' =>
- array(
- 'percentage_change' =>
- array(
+ 'filters' => array(
+ 'percentage_change' => array(
'title' => ts('Percentage Change'),
'type' => CRM_Utils_Type::T_INT,
'operatorType' => CRM_Report_Form::OP_INT,
'dbAlias' => '( ( contribution_civireport2.total_amount_sum - contribution_civireport1.total_amount_sum ) * 100 / contribution_civireport1.total_amount_sum )',
),
),
- 'group_bys' =>
- array(
- 'id' =>
- array(
+ 'group_bys' => array(
+ 'id' => array(
'title' => ts('Contact'),
'default' => TRUE,
),
),
),
- 'civicrm_email' =>
- array(
+ 'civicrm_email' => array(
'dao' => 'CRM_Core_DAO_Email',
- 'fields' =>
- array(
- 'email' =>
- array(
+ 'fields' => array(
+ 'email' => array(
'title' => ts('Email'),
'no_repeat' => TRUE,
),
),
'grouping' => 'contact-fields',
),
- 'civicrm_phone' =>
- array(
+ 'civicrm_phone' => array(
'dao' => 'CRM_Core_DAO_Phone',
- 'fields' =>
- array(
- 'phone' =>
- array(
+ 'fields' => array(
+ 'phone' => array(
'title' => ts('Phone'),
'no_repeat' => TRUE,
),
),
'grouping' => 'contact-fields',
),
- 'civicrm_address' =>
- array(
+ 'civicrm_address' => array(
'dao' => 'CRM_Core_DAO_Address',
'grouping' => 'contact-fields',
- 'fields' =>
- array(
+ 'fields' => array(
'street_address' => array('title' => ts('Street Address')),
'supplemental_address_1' => array('title' => ts('Supplemental Address 1')),
'city' => array('title' => ts('City')),
'state_province_id' => array('title' => ts('State/Province')),
'postal_code' => array('title' => ts('Postal Code')),
),
- 'group_bys' =>
- array(
+ 'group_bys' => array(
'country_id' => array('title' => ts('Country')),
- 'state_province_id' => array('title' => ts('State/Province'),
+ 'state_province_id' => array(
+ 'title' => ts('State/Province'),
),
),
),
- 'civicrm_financial_type' =>
- array(
+ 'civicrm_financial_type' => array(
'dao' => 'CRM_Financial_DAO_FinancialType',
'fields' => array('financial_type' => array('title' => ts('Financial Type'))),
- 'grouping' => 'contri-fields',
- 'group_bys' =>
- array('financial_type' =>
- array(
- 'name' => 'id',
- 'title' => ts('Financial Type'),
- ),
+ 'grouping' => 'contri-fields',
+ 'group_bys' => array(
+ 'financial_type' => array(
+ 'name' => 'id',
+ 'title' => ts('Financial Type'),
+ ),
),
),
- 'civicrm_contribution' =>
- array(
+ 'civicrm_contribution' => array(
'dao' => 'CRM_Contribute_DAO_Contribution',
- 'fields' =>
- array(
+ 'fields' => array(
'contribution_source' => NULL,
- 'total_amount1' =>
- array(
+ 'total_amount1' => array(
'name' => 'total_amount',
'alias' => 'contribution1',
'title' => ts('Range One Stat'),
contribution_civireport1.total_amount_count as contribution1_total_amount_count,
contribution_civireport1.total_amount_sum as contribution1_total_amount_sum',
),
- 'total_amount2' =>
- array(
+ 'total_amount2' => array(
'name' => 'total_amount',
'alias' => 'contribution2',
'title' => ts('Range Two Stat'),
),
),
'grouping' => 'contri-fields',
- 'filters' =>
- array(
- 'receive_date1' =>
- array(
+ 'filters' => array(
+ 'receive_date1' => array(
'title' => ts('Initial Date Range'),
'default' => 'previous.year',
'type' => CRM_Utils_Type::T_DATE,
'operatorType' => CRM_Report_Form::OP_DATE,
'name' => 'receive_date',
),
- 'receive_date2' =>
- array(
+ 'receive_date2' => array(
'title' => ts('Second Date Range'),
'default' => 'this.year',
'type' => CRM_Utils_Type::T_DATE,
'operatorType' => CRM_Report_Form::OP_DATE,
'name' => 'receive_date',
),
- 'total_amount1' =>
- array(
+ 'total_amount1' => array(
'title' => ts('Range One Amount'),
'type' => CRM_Utils_Type::T_INT,
'operatorType' => CRM_Report_Form::OP_INT,
'name' => 'total_amount',
),
- 'total_amount2' =>
- array(
+ 'total_amount2' => array(
'title' => ts('Range Two Amount'),
'type' => CRM_Utils_Type::T_INT,
'operatorType' => CRM_Report_Form::OP_INT,
'name' => 'total_amount',
),
- 'financial_type_id' =>
- array(
+ 'financial_type_id' => array(
'title' => ts('Financial Type'),
'operatorType' => CRM_Report_Form::OP_MULTISELECT,
'options' => CRM_Contribute_PseudoConstant::financialType(),
),
- 'contribution_status_id' =>
- array(
+ 'contribution_status_id' => array(
'title' => ts('Contribution Status'),
'operatorType' => CRM_Report_Form::OP_MULTISELECT,
'options' => CRM_Contribute_PseudoConstant::contributionStatus(),
parent::__construct();
}
- function preProcess() {
+ public function preProcess() {
parent::preProcess();
}
*
* @return array
*/
- function setDefaultValues($freeze = TRUE) {
+ public function setDefaultValues($freeze = TRUE) {
return parent::setDefaultValues($freeze);
}
- function select() {
+ public function select() {
$select = array();
$append = NULL;
// since contact fields not related to financial type
foreach ($this->_columns as $tableName => $table) {
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 (isset($field['clause'])) {
$select[] = $field['clause'];
/**
* @param bool $tableCol
*/
- function groupBy($tableCol = FALSE) {
+ public function groupBy($tableCol = FALSE) {
$this->_groupBy = "";
- if (!empty($this->_params['group_bys']) && is_array($this->_params['group_bys'])) {
+ if (!empty($this->_params['group_bys']) &&
+ is_array($this->_params['group_bys'])
+ ) {
foreach ($this->_columns as $tableName => $table) {
if (array_key_exists('group_bys', $table)) {
foreach ($table['group_bys'] as $fieldName => $field) {
}
}
- function from() {
+ public function from() {
list($fromTable, $fromAlias, $fromCol) = $this->groupBy(TRUE);
$from = "$fromTable $fromAlias";
ON {$this->_aliases['civicrm_contact']}.id = {$this->_aliases['civicrm_phone']}.contact_id AND {$this->_aliases['civicrm_phone']}.is_primary = 1";
}
- else if ($fromTable == 'civicrm_financial_type') {
+ elseif ($fromTable == 'civicrm_financial_type') {
$contriCol = "financial_type_id";
}
elseif ($fromTable == 'civicrm_contribution') {
$from .= "
INNER JOIN civicrm_contact {$this->_aliases['civicrm_contact']} ON {$this->_aliases['civicrm_address']}.contact_id = {$this->_aliases['civicrm_contact']}.id";
$fromAlias = $this->_aliases['civicrm_contact'];
- $fromCol = "id";
+ $fromCol = "id";
$contriCol = "contact_id";
}
*
* @return mixed|string
*/
- function whereContribution($replaceAliasWith = 'contribution1') {
+ public function whereContribution($replaceAliasWith = 'contribution1') {
$clauses = array("is_test" => "{$this->_aliases['civicrm_contribution']}.is_test = 0");
foreach ($this->_columns['civicrm_contribution']['filters'] as $fieldName => $field) {
$clause = NULL;
if (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['dbAlias'], $relative, $from, $to, $field['type']);
}
return $whereClause;
}
- function where() {
+ public function where() {
if (!$this->_amountClauseWithAND) {
$this->_amountClauseWithAND =
"!({$this->_aliases['civicrm_contribution']}1.total_amount_count IS NULL AND {$this->_aliases['civicrm_contribution']}2.total_amount_count IS NULL)";
$clauses = array("atleast_one_amount" => $this->_amountClauseWithAND);
foreach ($this->_columns as $tableName => $table) {
- if (array_key_exists('filters', $table) && $tableName != 'civicrm_contribution') {
+ if (array_key_exists('filters', $table) &&
+ $tableName != 'civicrm_contribution'
+ ) {
foreach ($table['filters'] as $fieldName => $field) {
$clause = NULL;
$op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
*
* @return array
*/
- function formRule($fields, $files, $self) {
+ public static function formRule($fields, $files, $self) {
$errors = $checkDate = $errorCount = array();
$idMapping = array(
'id' => ts('Contact'),
+ 'exposed_id' => ts('Contact'),
'country_id' => ts('Country'),
'state_province_id' => ts('State/Province'),
'contribution_source' => ts('Contribution Source'),
$errors['fields'] = ts('Please select at least one Group by field.');
}
elseif ((array_key_exists('contribution_source', $fields['group_bys']) ||
- array_key_exists('contribution_type', $fields['group_bys'])
- ) &&
+ array_key_exists('contribution_type', $fields['group_bys'])
+ ) &&
(count($fields['group_bys']) > 1)
) {
$errors['fields'] = ts('You can not use other Group by with Financial type or Contribution source.');
}
if (!$found) {
$erorrGrps = implode(',', $invlidGroups);
- $tempErrors[] = ts("Do not select field %1 with Group by %2.", array(1 => $idMapping[$fld_id], 2 => $erorrGrps));
+ $tempErrors[] = ts("Do not select field %1 with Group by %2.", array(
+ 1 => $idMapping[$fld_id],
+ 2 => $erorrGrps
+ ));
}
}
}
*
* @return array
*/
- function statistics(&$rows) {
+ public function statistics(&$rows) {
$statistics = parent::statistics($rows);
//fetch contributions for both date ranges from pre-existing temp tables
$number_lapsed = 0;
foreach ($contact_sums as $uid => $row) {
- if ($row['contribution1_total_amount_sum'] && $row['contribution2_total_amount_sum']) {
- $change = ($row['contribution1_total_amount_sum'] - $row['contribution2_total_amount_sum']);
- if($change == 0)
+ if ($row['contribution1_total_amount_sum'] &&
+ $row['contribution2_total_amount_sum']
+ ) {
+ $change = ($row['contribution1_total_amount_sum'] -
+ $row['contribution2_total_amount_sum']);
+ if ($change == 0) {
$number_maintained += 1;
- elseif($change > 0)
+ }
+ elseif ($change > 0) {
$number_upgraded += 1;
- elseif($change < 0)
+ }
+ elseif ($change < 0) {
$number_downgraded += 1;
+ }
}
elseif ($row['contribution1_total_amount_sum']) {
- $number_new +=1;
+ $number_new += 1;
}
elseif ($row['contribution2_total_amount_sum']) {
- $number_lapsed +=1;
+ $number_lapsed += 1;
}
}
$count = $count2 = 0;
while ($dao->fetch()) {
if ($dao->amount) {
- $amount[] = CRM_Utils_Money::format($dao->amount, $dao->currency)."(".$dao->count.")";
- $average[] = CRM_Utils_Money::format($dao->avg, $dao->currency);
+ $amount[] =
+ CRM_Utils_Money::format($dao->amount, $dao->currency) . "(" .
+ $dao->count . ")";
+ $average[] = CRM_Utils_Money::format($dao->avg, $dao->currency);
}
$count += $dao->count;
if ($dao->amount2) {
- $amount2[] = CRM_Utils_Money::format($dao->amount2, $dao->currency)."(".$dao->count.")";
- $average2[] = CRM_Utils_Money::format($dao->avg2, $dao->currency);
+ $amount2[] =
+ CRM_Utils_Money::format($dao->amount2, $dao->currency) . "(" .
+ $dao->count . ")";
+ $average2[] = CRM_Utils_Money::format($dao->avg2, $dao->currency);
}
$count2 += $dao->count2;
}
return $statistics;
}
- function postProcess() {
+ public function postProcess() {
$this->beginPostProcess();
$create = $subSelect1 = $subSelect2 = NULL;
list($fromTable, $fromAlias, $fromCol) = $this->groupBy(TRUE);
$this->limit();
$count = 0;
- $sql = "{$this->_select} {$this->_from} {$this->_where} {$this->_groupBy} {$this->_limit}";
- $dao = CRM_Core_DAO::executeQuery($sql);
- $rows = array();
+ $sql = "{$this->_select} {$this->_from} {$this->_where} {$this->_groupBy} {$this->_limit}";
+ $dao = CRM_Core_DAO::executeQuery($sql);
+ $rows = array();
while ($dao->fetch()) {
foreach ($this->_columnHeaders as $key => $value) {
$rows[$count][$key] = $dao->$key;
// FIXME: calculate % using query
foreach ($rows as $uid => $row) {
- if ($row['contribution1_total_amount_sum'] && $row['contribution2_total_amount_sum']) {
+ if ($row['contribution1_total_amount_sum'] &&
+ $row['contribution2_total_amount_sum']
+ ) {
$rows[$uid]['change'] = number_format((($row['contribution2_total_amount_sum'] -
- $row['contribution1_total_amount_sum']
- ) * 100) /
- ($row['contribution1_total_amount_sum']), 2
+ $row['contribution1_total_amount_sum']
+ ) * 100) /
+ ($row['contribution1_total_amount_sum']), 2
);
}
elseif ($row['contribution1_total_amount_sum']) {
$rows[$uid]['change'] = ts('New Donor');
}
if ($row['contribution1_total_amount_count']) {
- $rows[$uid]['contribution1_total_amount_sum'] = $row['contribution1_total_amount_sum'] . " ({$row['contribution1_total_amount_count']})";
+ $rows[$uid]['contribution1_total_amount_sum'] =
+ $row['contribution1_total_amount_sum'] .
+ " ({$row['contribution1_total_amount_count']})";
}
if ($row['contribution2_total_amount_count']) {
- $rows[$uid]['contribution2_total_amount_sum'] = $row['contribution2_total_amount_sum'] . " ({$row['contribution2_total_amount_count']})";
+ $rows[$uid]['contribution2_total_amount_sum'] =
+ $row['contribution2_total_amount_sum'] .
+ " ({$row['contribution2_total_amount_count']})";
}
}
$this->_columnHeaders['change'] = array(
$this->_columnHeaders['contribution1_total_amount_sum']['title'] = "$from1 -<br/> $to1";
$this->_columnHeaders['contribution2_total_amount_sum']['title'] = "$from2 -<br/> $to2";
unset($this->_columnHeaders['contribution1_total_amount_count'],
- $this->_columnHeaders['contribution2_total_amount_count']
+ $this->_columnHeaders['contribution2_total_amount_count']
);
$this->formatDisplay($rows);
/**
* @param $rows
*/
- function alterDisplay(&$rows) {
+ public function alterDisplay(&$rows) {
// custom code to alter rows
list($from1, $to1) = $this->getFromTo(CRM_Utils_Array::value("receive_date1_relative", $this->_params),
CRM_Utils_Array::value("receive_date1_from", $this->_params),
$url = CRM_Report_Utils_Report::getNextUrl('contribute/detail',
"reset=1&force=1&" .
- "country_id_op=in&country_id_value={$value}&" .
- "$dateUrl",
+ "country_id_op=in&country_id_value={$value}&" .
+ "$dateUrl",
$this->_absoluteUrl, $this->_id, $this->_drilldownReport
);
$url = CRM_Report_Utils_Report::getNextUrl('contribute/detail',
"reset=1&force=1&" .
- "state_province_id_op=in&state_province_id_value={$value}&" .
- "$dateUrl",
+ "state_province_id_op=in&state_province_id_value={$value}&" .
+ "$dateUrl",
$this->_absoluteUrl, $this->_id, $this->_drilldownReport
);
// foreach ends
}
}
-