Skip to content

Commit

Permalink
CRM/Report - Refactor unnecessary uses of CRM_Utils_Array::value
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Oct 14, 2023
1 parent 7eed280 commit 7dfd35a
Show file tree
Hide file tree
Showing 25 changed files with 101 additions and 101 deletions.
2 changes: 1 addition & 1 deletion CRM/Report/BAO/ReportInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function add(&$params) {
}

if (!$instanceID || !isset($params['id'])) {
$params['is_reserved'] = CRM_Utils_Array::value('is_reserved', $params, FALSE);
$params['is_reserved'] = $params['is_reserved'] ?? FALSE;
$params['domain_id'] = CRM_Utils_Array::value('domain_id', $params, CRM_Core_Config::domainID());
// CRM-17256 set created_id on report creation.
$params['created_id'] = $params['created_id'] ?? CRM_Core_Session::getLoggedInContactID();
Expand Down
16 changes: 8 additions & 8 deletions CRM/Report/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ public function setDefaultValues($freeze = TRUE) {
$order_by = [
'column' => $fieldName,
'order' => CRM_Utils_Array::value('default_order', $field, 'ASC'),
'section' => CRM_Utils_Array::value('default_is_section', $field, 0),
'section' => $field['default_is_section'] ?? 0,
];

if (!empty($field['default_weight'])) {
Expand Down Expand Up @@ -3531,17 +3531,17 @@ public function filterStat(&$statistics) {
$val[$key] = $options[$valIds];
}
}
$pair[$op] = (count($val) == 1) ? (($op == 'notin' || $op ==
'mnot') ? ts('Is Not') : ts('Is')) : CRM_Utils_Array::value($op, $pair);
$pair[$op] = (count($val) == 1) ?
(($op == 'notin' || $op == 'mnot') ? ts('Is Not') : ts('Is')) :
($pair[$op] ?? '');
$val = implode(', ', $val);
$value = "{$pair[$op]} " . $val;
}
elseif (!is_array($val) && (!empty($val) || $val == '0') &&
isset($field['options']) &&
is_array($field['options']) && !empty($field['options'])
) {
$value = ($pair[$op] ?? '') . " " .
CRM_Utils_Array::value($val, $field['options'], $val);
$value = ($pair[$op] ?? '') . ' ' . ($field['options'][$val] ?? $val);
}
elseif ($val || $val == '0') {
$value = ($pair[$op] ?? '') . " " . $val;
Expand Down Expand Up @@ -3649,8 +3649,8 @@ public function getTemplateFileName() {
public function compileContent() {
$templateFile = $this->getHookedTemplateFileName();
return ($this->_formValues['report_header'] ?? '') .
CRM_Core_Form::$_template->fetch($templateFile) .
CRM_Utils_Array::value('report_footer', $this->_formValues);
CRM_Core_Form::$_template->fetch($templateFile) .
($this->_formValues['report_footer'] ?? '');
}

/**
Expand Down Expand Up @@ -5038,7 +5038,7 @@ public function getBasicContactFilters($defaults = []) {
'is_deceased' => [
'title' => ts('Deceased'),
'type' => CRM_Utils_Type::T_BOOLEAN,
'default' => CRM_Utils_Array::value('deceased', $defaults, 0),
'default' => $defaults['deceased'] ?? 0,
],
'do_not_email' => [
'title' => ts('Do not email'),
Expand Down
10 changes: 5 additions & 5 deletions CRM/Report/Form/Campaign/SurveyDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ public function where() {
if ($op) {
$clause = $this->whereClause($field,
$op,
CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
$this->_params["{$fieldName}_value"] ?? NULL,
$this->_params["{$fieldName}_min"] ?? NULL,
$this->_params["{$fieldName}_max"] ?? NULL
);
}
}
Expand Down Expand Up @@ -357,11 +357,11 @@ public function where() {

public function compileContent() {
$coverSheet = $this->_surveyCoverSheet() .
"<div style=\"page-break-after: always\"></div>";
"<div style=\"page-break-after: always\"></div>";
$templateFile = $this->getHookedTemplateFileName();
return $coverSheet .
CRM_Core_Form::$_template->fetch($templateFile) .
CRM_Utils_Array::value('report_footer', $this->_formValues);
($this->_formValues['report_footer'] ?? '');
}

/**
Expand Down
6 changes: 3 additions & 3 deletions CRM/Report/Form/Case/Demographics.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,9 @@ public function where() {
else {
$clause = $this->whereClause($field,
$op,
CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
$this->_params["{$fieldName}_value"] ?? NULL,
$this->_params["{$fieldName}_min"] ?? NULL,
$this->_params["{$fieldName}_max"] ?? NULL
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions CRM/Report/Form/Case/Detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,8 @@ public function where() {
if ($op) {
$clause = $this->whereClause($field,
$op,
CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
$this->_params["{$fieldName}_value"] ?? NULL,
$this->_params["{$fieldName}_min"] ?? NULL,
CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
);
}
Expand Down
6 changes: 3 additions & 3 deletions CRM/Report/Form/Case/TimeSpent.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ public function where() {
else {
$clause = $this->whereClause($field,
$op,
CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
$this->_params["{$fieldName}_value"] ?? NULL,
$this->_params["{$fieldName}_min"] ?? NULL,
$this->_params["{$fieldName}_max"] ?? NULL
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions CRM/Report/Form/Contact/CurrentEmployer.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ public function where() {
if ($op) {
$clause = $this->whereClause($field,
$op,
CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
$this->_params["{$fieldName}_value"] ?? NULL,
$this->_params["{$fieldName}_min"] ?? NULL,
$this->_params["{$fieldName}_max"] ?? NULL
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions CRM/Report/Form/Contact/Detail.php
Original file line number Diff line number Diff line change
Expand Up @@ -606,9 +606,9 @@ public function where(): void {
$op = $this->_params["{$fieldName}_op"] ?? NULL;
$clause = $this->whereClause($field,
$op,
CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
$this->_params["{$fieldName}_value"] ?? NULL,
$this->_params["{$fieldName}_min"] ?? NULL,
$this->_params["{$fieldName}_max"] ?? NULL
);
}
if (!empty($clause)) {
Expand Down
6 changes: 3 additions & 3 deletions CRM/Report/Form/Contact/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ public function where() {
if ($op) {
$clause = $this->whereClause($field,
$op,
CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
$this->_params["{$fieldName}_value"] ?? NULL,
$this->_params["{$fieldName}_min"] ?? NULL,
$this->_params["{$fieldName}_max"] ?? NULL
);
}
}
Expand Down
14 changes: 7 additions & 7 deletions CRM/Report/Form/Contact/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,8 @@ public function where() {
$clause = $this->whereClause($field,
$op,
$contactTypes,
CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
$this->_params["{$fieldName}_min"] ?? NULL,
$this->_params["{$fieldName}_max"] ?? NULL
);
}

Expand All @@ -496,8 +496,8 @@ public function where() {
$subTypeClause = $this->whereClause($field,
$op,
$contactSubTypes,
CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
$this->_params["{$fieldName}_min"] ?? NULL,
$this->_params["{$fieldName}_max"] ?? NULL
);
if ($clause) {
$clause = '(' . $clause . ' OR ' . $subTypeClause . ')';
Expand All @@ -514,9 +514,9 @@ public function where() {
else {
$clause = $this->whereClause($field,
$op,
CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
$this->_params["{$fieldName}_value"] ?? NULL,
$this->_params["{$fieldName}_min"] ?? NULL,
$this->_params["{$fieldName}_max"] ?? NULL
);
}
}
Expand Down
10 changes: 5 additions & 5 deletions CRM/Report/Form/Contribute/History.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,9 @@ public function where() {
if ($op) {
$clause = $this->whereClause($field,
$op,
CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
$this->_params["{$fieldName}_value"] ?? NULL,
$this->_params["{$fieldName}_min"] ?? NULL,
$this->_params["{$fieldName}_max"] ?? NULL
);
}
}
Expand Down Expand Up @@ -661,7 +661,7 @@ public function buildRows($sql, &$rows) {
$total = [];
$total['civicrm_contact_sort_name'] = ts('Total');
foreach ($summaryYears as $year) {
$total[$year] = CRM_Utils_Array::value($year, $primaryRow, 0);
$total[$year] = $primaryRow[$year] ?? 0;
}

$relatedContact = FALSE;
Expand All @@ -673,7 +673,7 @@ public function buildRows($sql, &$rows) {
$relatedContact = TRUE;
$relatedRow = $relatedContributions[$relcid];
foreach ($summaryYears as $year) {
$total[$year] += CRM_Utils_Array::value($year, $relatedRow, 0);
$total[$year] += $relatedRow[$year] ?? 0;
}

foreach (array_keys($this->_relationshipColumns) as $col) {
Expand Down
6 changes: 3 additions & 3 deletions CRM/Report/Form/Contribute/HouseholdSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ public function where() {
else {
$clause = $this->whereClause($field,
$op,
CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
$this->_params["{$fieldName}_value"] ?? NULL,
$this->_params["{$fieldName}_min"] ?? NULL,
$this->_params["{$fieldName}_max"] ?? NULL
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions CRM/Report/Form/Contribute/Lybunt.php
Original file line number Diff line number Diff line change
Expand Up @@ -644,9 +644,9 @@ public function buildChart(&$rows) {
foreach ($rows as $key => $row) {
// The final row contains the totals so we don't need to include it here.
if (!empty($row['civicrm_contribution_contact_id'])) {
$display['life_time'] = CRM_Utils_Array::value('life_time', $display) +
$display['life_time'] = ($display['life_time'] ?? 0) +
$row['civicrm_contribution_civicrm_life_time_total'];
$display[$previous_year] = CRM_Utils_Array::value($previous_year, $display) + $row['civicrm_contribution_last_year_total_amount'];
$display[$previous_year] = ($display[$previous_year] ?? 0) + $row['civicrm_contribution_last_year_total_amount'];
}
}

Expand Down
6 changes: 3 additions & 3 deletions CRM/Report/Form/Contribute/OrganizationSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ public function where() {
else {
$clause = $this->whereClause($field,
$op,
CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
$this->_params["{$fieldName}_value"] ?? NULL,
$this->_params["{$fieldName}_min"] ?? NULL,
$this->_params["{$fieldName}_max"] ?? NULL
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions CRM/Report/Form/Contribute/PCP.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ public function where() {
if ($op) {
$clause = $this->whereClause($field,
$op,
CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
$this->_params["{$fieldName}_value"] ?? NULL,
$this->_params["{$fieldName}_min"] ?? NULL,
$this->_params["{$fieldName}_max"] ?? NULL
);
}
}
Expand Down
32 changes: 16 additions & 16 deletions CRM/Report/Form/Contribute/Repeat.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,9 @@ public function whereContribution($replaceAliasWith = 'contribution1') {
if ($op) {
$clause = $this->whereClause($field,
$op,
CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
$this->_params["{$fieldName}_value"] ?? NULL,
$this->_params["{$fieldName}_min"] ?? NULL,
$this->_params["{$fieldName}_max"] ?? NULL
);
}
}
Expand Down Expand Up @@ -464,9 +464,9 @@ public function where() {
if ($op) {
$clause = $this->whereClause($field,
$op,
CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
$this->_params["{$fieldName}_value"] ?? NULL,
$this->_params["{$fieldName}_min"] ?? NULL,
$this->_params["{$fieldName}_max"] ?? NULL
);
}
if (!empty($clause)) {
Expand Down Expand Up @@ -877,15 +877,15 @@ public function postProcess() {

// hack to fix title
list($from1, $to1) = $this->getFromTo(CRM_Utils_Array::value("receive_date1_relative", $this->_params),
CRM_Utils_Array::value("receive_date1_from", $this->_params),
CRM_Utils_Array::value("receive_date1_to", $this->_params)
$this->_params["receive_date1_from"] ?? NULL,
$this->_params["receive_date1_to"] ?? NULL
);
$from1 = CRM_Utils_Date::customFormat($from1, NULL, ['d']);
$to1 = CRM_Utils_Date::customFormat($to1, NULL, ['d']);

list($from2, $to2) = $this->getFromTo(CRM_Utils_Array::value("receive_date2_relative", $this->_params),
CRM_Utils_Array::value("receive_date2_from", $this->_params),
CRM_Utils_Array::value("receive_date2_to", $this->_params)
$this->_params["receive_date2_from"] ?? NULL,
$this->_params["receive_date2_to"] ?? NULL
);
$from2 = CRM_Utils_Date::customFormat($from2, NULL, ['d']);
$to2 = CRM_Utils_Date::customFormat($to2, NULL, ['d']);
Expand Down Expand Up @@ -914,13 +914,13 @@ public function postProcess() {
* Rows generated by SQL, with an array for each row.
*/
public function alterDisplay(&$rows) {
list($from1, $to1) = $this->getFromTo(CRM_Utils_Array::value("receive_date1_relative", $this->_params),
CRM_Utils_Array::value("receive_date1_from", $this->_params),
CRM_Utils_Array::value("receive_date1_to", $this->_params)
[$from1, $to1] = $this->getFromTo(CRM_Utils_Array::value("receive_date1_relative", $this->_params),
$this->_params["receive_date1_from"] ?? NULL,
$this->_params["receive_date1_to"] ?? NULL
);
list($from2, $to2) = $this->getFromTo(CRM_Utils_Array::value("receive_date2_relative", $this->_params),
CRM_Utils_Array::value("receive_date2_from", $this->_params),
CRM_Utils_Array::value("receive_date2_to", $this->_params)
[$from2, $to2] = $this->getFromTo(CRM_Utils_Array::value("receive_date2_relative", $this->_params),
$this->_params["receive_date2_from"] ?? NULL,
$this->_params["receive_date2_to"] ?? NULL
);

$dateUrl = "";
Expand Down
14 changes: 7 additions & 7 deletions CRM/Report/Form/Contribute/Sybunt.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,9 @@ public function where() {
if ($op) {
$clause = $this->whereClause($field,
$op,
CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
$this->_params["{$fieldName}_value"] ?? NULL,
$this->_params["{$fieldName}_min"] ?? NULL,
$this->_params["{$fieldName}_max"] ?? NULL
);
if (($fieldName == 'contribution_status_id' ||
$fieldName == 'financial_type_id') && !empty($clause)
Expand Down Expand Up @@ -526,13 +526,13 @@ public function buildChart(&$rows) {

foreach ($rows as $key => $row) {
$display["upto_{$upto}"]
= CRM_Utils_Array::value("upto_{$upto}", $display) + CRM_Utils_Array::value("civicrm_upto_{$upto}", $row);
= ($display["upto_{$upto}"] ?? 0) + ($row["civicrm_upto_{$upto}"] ?? 0);
$display[$previous_year]
= CRM_Utils_Array::value($previous_year, $display) + CRM_Utils_Array::value($previous_year, $row);
= ($display[$previous_year] ?? 0) + ($row[$previous_year] ?? 0);
$display[$previous_two_year]
= CRM_Utils_Array::value($previous_two_year, $display) + CRM_Utils_Array::value($previous_two_year, $row);
= ($display[$previous_two_year] ?? 0) + ($row[$previous_two_year] ?? 0);
$display[$previous_three_year]
= CRM_Utils_Array::value($previous_three_year, $display) + CRM_Utils_Array::value($previous_three_year, $row);
= ($display[$previous_three_year] ?? 0) + ($row[$previous_three_year] ?? 0);
}

$graphRows['value'] = $display;
Expand Down
6 changes: 3 additions & 3 deletions CRM/Report/Form/Contribute/TopDonor.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ public function where() {
if ($op) {
$clause = $this->whereClause($field,
$op,
CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
$this->_params["{$fieldName}_value"] ?? NULL,
$this->_params["{$fieldName}_min"] ?? NULL,
$this->_params["{$fieldName}_max"] ?? NULL
);
}
}
Expand Down
Loading

0 comments on commit 7dfd35a

Please sign in to comment.