Skip to content
Snippets Groups Projects
Unverified Commit 79015851 authored by Eileen McNaughton's avatar Eileen McNaughton Committed by GitHub
Browse files

Merge pull request #19317 from ahed-compucorp/dev/core#2285

#2285 Fix civicrm_alterReportVar hook for contribute detail r…
parents 214a6b81 7164d1ad
Branches
Tags
No related merge requests found
......@@ -572,6 +572,7 @@ GROUP BY {$this->_aliases['civicrm_contribution']}.currency";
// we inner join with temp1 to restrict soft contributions to those in temp1 table.
// no group by here as we want to display as many soft credit rows as actually exist.
CRM_Utils_Hook::alterReportVar('sql', $this, $this);
$sql = "{$select} {$this->_from} {$this->_where} $this->_groupBy";
$this->createTemporaryTable('civireport_contribution_detail_temp2', $sql);
......
......@@ -253,4 +253,83 @@ class CRM_Report_Form_Contribute_DetailTest extends CiviReportTestCase {
}
/**
* Make sure the civicrm_alterReportVar hook for contribute detail report work well.
*/
public function testContributeDetailReportWithNewColumnFromCustomTable() {
$this->quickCleanup($this->_tablesToTruncate);
$solParams = [
'first_name' => 'Solicitor 1',
'last_name' => 'User ' . rand(),
'contact_type' => 'Individual',
];
$solicitor1Id = $this->individualCreate($solParams);
$solParams['first_name'] = 'Solicitor 2';
$solicitor2Id = $this->individualCreate($solParams);
$solParams['first_name'] = 'Donor';
$donorId = $this->individualCreate($solParams);
$contribParams = [
'total_amount' => 150,
'contact_id' => $donorId,
// TODO: We're getting a "DB Error: already exists" when inserting a line
// item, but that's beside the point for this test, so skipping.
'skipLineItem' => 1,
];
$contribId = $this->contributionCreate($contribParams);
$config = CRM_Core_Config::singleton();
CRM_Utils_File::sourceSQLFile($config->dsn, dirname(__FILE__) . "/fixtures/value_extension_tng55_table.sql");
CRM_Core_DAO::executeQuery("INSERT INTO civicrm_value_extension_tng55 (`entity_id`, `title`) VALUES (%1, 'some_title')", [1 => [$contribId, 'Positive']]);
CRM_Utils_Hook::singleton()->setHook('civicrm_alterReportVar', function ($varType, &$var, &$reportForm) {
if ($varType === 'columns') {
$var['civicrm_value_extension_tng55'] = [
'fields' => [
'extension_tng55_title' => [
'title' => ts('Extension Title'),
'dbAlias' => "civicrm_value_extension_tng55.title",
],
],
'filters' => [
'extension_tng55_title' => [
'title' => ts('Extension Title'),
'dbAlias' => "civicrm_value_extension_tng55.title",
'type' => CRM_Utils_Type::T_INT,
'operatorType' => CRM_Report_Form::OP_MULTISELECT,
'options' => [],
],
],
];
}
if ($varType === 'sql') {
$from = $var->getVar('_from');
$from .= "
LEFT JOIN civicrm_value_extension_tng55
ON (civicrm_value_extension_tng55.entity_id = contribution_civireport.id)
";
$var->setVar('_from', $from);
}
});
$input = [
'extension_tng55_title_op' => 'nnll',
'fields' => [
'sort_name' => 1,
'contribution_id' => 1,
'total_amount' => 1,
'extension_tng55_title' => 1,
],
];
$params = array_merge([
'report_id' => 'contribute/detail',
], $input);
$rows = $this->callAPISuccess('ReportTemplate', 'getrows', $params)['values'];
$this->assertCount(1, $rows);
$this->assertEquals('some_title', $rows[0]['civicrm_value_extension_tng55_extension_tng55_title']);
}
}
-- phpMyAdmin SQL Dump
-- version 4.9.7
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Jan 04, 2021 at 06:30 AM
-- Server version: 5.7.32
-- PHP Version: 7.4.3
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET FOREIGN_KEY_CHECKS=0;
--
-- Database: `civicrm_tests_dev`
--
--
-- Dumping data for table `civicrm_value_extension_tng55`
--
CREATE TABLE `civicrm_value_extension_tng55` (
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Default MySQL primary key',
`entity_id` int(10) UNSIGNED NOT NULL,
`title` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment