Skip to content

Commit

Permalink
Merge pull request civicrm#9751 from eileenmcnaughton/report
Browse files Browse the repository at this point in the history
Minor comment fixes & function extraction.
  • Loading branch information
eileenmcnaughton authored Mar 18, 2017
2 parents edfa753 + 2369196 commit 7f37140
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 65 deletions.
4 changes: 2 additions & 2 deletions CRM/Contact/BAO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -3371,8 +3371,8 @@ public static function buildOptions($fieldName, $context = NULL, $props = array(
* Ensures that is_primary gets assigned to another object if available
* Also calls pre/post hooks
*
* @var object $type
* @var int $id
* @param string $type
* @param int $id
* @return bool
*/
public static function deleteObjectWithPrimary($type, $id) {
Expand Down
4 changes: 3 additions & 1 deletion CRM/Core/BAO/Phone.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ public static function allPhones($id, $updateBlankLocInfo = FALSE, $type = NULL,
}

/**
* Get all the phone numbers for a specified location_block id, with the primary phone being first
* Get all the phone numbers for a specified location_block id, with the primary phone being first.
*
* This is called from CRM_Core_BAO_Block as a calculated function.
*
* @param array $entityElements
* The array containing entity_id and.
Expand Down
33 changes: 20 additions & 13 deletions CRM/Core/BAO/PrevNextCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/

/**
* BAO object for civicrm_prevnext_cache table
* BAO object for civicrm_prevnext_cache table.
*/
class CRM_Core_BAO_PrevNextCache extends CRM_Core_DAO_PrevNextCache {

/**
* @param $cacheKey
* @param $id1
* @param $id2
* Get the previous and next keys.
*
* @param string $cacheKey
* @param int $id1
* @param int $id2
* @param int $mergeId
* @param NULL $join
* @param NULL $where
* @param string $join
* @param string $where
* @param bool $flip
*
* @return array
Expand Down Expand Up @@ -113,8 +113,10 @@ public static function getPositions($cacheKey, $id1, $id2, &$mergeId = NULL, $jo
}

/**
* Delete an item from the prevnext cache table based on the entity.
*
* @param int $id
* @param NULL $cacheKey
* @param string $cacheKey
* @param string $entityTable
*/
public static function deleteItem($id = NULL, $cacheKey = NULL, $entityTable = 'civicrm_contact') {
Expand All @@ -136,9 +138,11 @@ public static function deleteItem($id = NULL, $cacheKey = NULL, $entityTable = '
}

/**
* @param $id1
* @param $id2
* @param NULL $cacheKey
* Delete from the previous next cache table for a pair of ids.
*
* @param int $id1
* @param int $id2
* @param string $cacheKey
* @param bool $isViceVersa
* @param string $entityTable
*/
Expand Down Expand Up @@ -224,6 +228,7 @@ public static function markConflict($id1, $id2, $cacheKey, $conflicts) {
* @param bool $includeConflicts
* Should we return rows that have already been idenfified as having a conflict.
* When this is TRUE you should be careful you do not set up a loop.
* @param array $params
*
* @return array
*/
Expand Down Expand Up @@ -321,7 +326,9 @@ public static function setItem($values) {
}

/**
* @param $cacheKey
* Get count of matching rows.
*
* @param string $cacheKey
* @param string $join
* @param string $where
* @param string $op
Expand Down
19 changes: 14 additions & 5 deletions CRM/Core/BAO/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {

/**
* @var array
*/
protected $tree;

/**
* Class constructor.
*/
Expand Down Expand Up @@ -63,7 +66,9 @@ public static function retrieve(&$params, &$defaults) {
}

/**
* @param null $usedFor
* Get tag tree.
*
* @param string $usedFor
* @param bool $excludeHidden
*
* @return mixed
Expand All @@ -76,7 +81,9 @@ public function getTree($usedFor = NULL, $excludeHidden = FALSE) {
}

/**
* Build a nested array from hierarchical tags. Supports infinite levels of nesting.
* Build a nested array from hierarchical tags.
*
* Supports infinite levels of nesting.
* @param null $usedFor
* @param bool $excludeHidden
*/
Expand All @@ -97,7 +104,7 @@ public function buildTree($usedFor = NULL, $excludeHidden = FALSE) {

$sql .= " ORDER BY parent_id,name";

$dao = CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray, TRUE, NULL, FALSE, FALSE);
$dao = CRM_Core_DAO::executeQuery($sql, array(), TRUE, NULL, FALSE, FALSE);

$refs = array();
$this->tree = array();
Expand All @@ -119,6 +126,8 @@ public function buildTree($usedFor = NULL, $excludeHidden = FALSE) {
}

/**
* Get tags used for the given entity/entities.
*
* @param array $usedFor
* @param bool $buildSelect
* @param bool $all
Expand Down
122 changes: 78 additions & 44 deletions CRM/Report/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -2316,50 +2316,10 @@ public function select() {

// include statistics columns only if set
if (!empty($field['statistics'])) {
foreach ($field['statistics'] as $stat => $label) {
$alias = "{$tableName}_{$fieldName}_{$stat}";
switch (strtolower($stat)) {
case 'max':
case 'sum':
$select[] = "$stat({$field['dbAlias']}) as $alias";
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = $field['type'];
$this->_statFields[$label] = $alias;
$this->_selectAliases[] = $alias;
break;

case 'count':
$select[] = "COUNT({$field['dbAlias']}) as $alias";
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = CRM_Utils_Type::T_INT;
$this->_statFields[$label] = $alias;
$this->_selectAliases[] = $alias;
break;

case 'count_distinct':
$select[] = "COUNT(DISTINCT {$field['dbAlias']}) as $alias";
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = CRM_Utils_Type::T_INT;
$this->_statFields[$label] = $alias;
$this->_selectAliases[] = $alias;
break;

case 'avg':
$select[] = "ROUND(AVG({$field['dbAlias']}),2) as $alias";
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = $field['type'];
$this->_statFields[$label] = $alias;
$this->_selectAliases[] = $alias;
break;
}
}
$select = $this->addStatisticsToSelect($field, $tableName, $fieldName, $select);
}
else {
$alias = "{$tableName}_{$fieldName}";
$select[] = "{$field['dbAlias']} as $alias";
$this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array::value('title', $field);
$this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
$this->_selectAliases[] = $alias;
$select = $this->addBasicFieldToSelect($tableName, $fieldName, $field, $select);
}
}
}
Expand Down Expand Up @@ -4308,7 +4268,7 @@ public function alterDisplayContactFields(&$row, &$rows, &$rowNum, $baseUrl, $li
$rowLabels = array();
foreach ($rowValues as $rowValue) {
if ($rowValue) {
$rowLabels[] = CRM_Core_Pseudoconstant::getLabel('CRM_Contact_BAO_Contact', $fieldName, $rowValue);
$rowLabels[] = CRM_Core_PseudoConstant::getLabel('CRM_Contact_BAO_Contact', $fieldName, $rowValue);
}
}
$rows[$rowNum]['civicrm_contact_' . $fieldName] = implode(', ', $rowLabels);
Expand Down Expand Up @@ -4707,7 +4667,7 @@ public function getPermissionedFTQuery(&$query, $alias = NULL, $return = FALSE)
CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes);
if (empty($financialTypes)) {
$contFTs = "0";
$liFTs = implode(',', array_keys(CRM_Contribute_Pseudoconstant::financialType()));
$liFTs = implode(',', array_keys(CRM_Contribute_PseudoConstant::financialType()));
}
else {
$contFTs = $liFTs = implode(',', array_keys($financialTypes));
Expand Down Expand Up @@ -4914,4 +4874,78 @@ public function getLabels($options, $baoName, $fieldName) {
return implode(', ', array_filter($labels));
}

/**
* Add statistics columns.
*
* If a group by is in play then add columns for the statistics fields.
*
* This would lead to a new field in the $row such as $fieldName_sum and a new, matching
* column header field.
*
* @param array $field
* @param string $tableName
* @param string $fieldName
* @param array $select
*
* @return array
*/
protected function addStatisticsToSelect($field, $tableName, $fieldName, $select) {
foreach ($field['statistics'] as $stat => $label) {
$alias = "{$tableName}_{$fieldName}_{$stat}";
switch (strtolower($stat)) {
case 'max':
case 'sum':
$select[] = "$stat({$field['dbAlias']}) as $alias";
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = $field['type'];
$this->_statFields[$label] = $alias;
$this->_selectAliases[] = $alias;
break;

case 'count':
$select[] = "COUNT({$field['dbAlias']}) as $alias";
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = CRM_Utils_Type::T_INT;
$this->_statFields[$label] = $alias;
$this->_selectAliases[] = $alias;
break;

case 'count_distinct':
$select[] = "COUNT(DISTINCT {$field['dbAlias']}) as $alias";
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = CRM_Utils_Type::T_INT;
$this->_statFields[$label] = $alias;
$this->_selectAliases[] = $alias;
break;

case 'avg':
$select[] = "ROUND(AVG({$field['dbAlias']}),2) as $alias";
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['title'] = $label;
$this->_columnHeaders["{$tableName}_{$fieldName}_{$stat}"]['type'] = $field['type'];
$this->_statFields[$label] = $alias;
$this->_selectAliases[] = $alias;
break;
}
}
return $select;
}

/**
* Add a basic field to the select clause.
*
* @param string $tableName
* @param string $fieldName
* @param array $field
* @param string $select
* @return array
*/
protected function addBasicFieldToSelect($tableName, $fieldName, $field, $select) {
$alias = "{$tableName}_{$fieldName}";
$select[] = "{$field['dbAlias']} as $alias";
$this->_columnHeaders["{$tableName}_{$fieldName}"]['title'] = CRM_Utils_Array::value('title', $field);
$this->_columnHeaders["{$tableName}_{$fieldName}"]['type'] = CRM_Utils_Array::value('type', $field);
$this->_selectAliases[] = $alias;
return $select;
}

}

0 comments on commit 7f37140

Please sign in to comment.