Skip to content

Commit

Permalink
Merge pull request #272 from compucorp/CIWEMB-254-fix-wrong-cf-fetching
Browse files Browse the repository at this point in the history
CIWEMB-254: Fetch custom fields correctly
  • Loading branch information
omarabuhussein authored Apr 5, 2023
2 parents 7d1efaf + 40cce23 commit 4f2040e
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ private static function getIsNotificationSentCustomFieldId() {
return civicrm_api3('CustomField', 'getvalue', [
'return' => 'id',
'name' => 'is_notification_sent',
'custom_group_id' => 'direct_debit_collection_reminder_sendflag',
]);
}
catch (CRM_Core_Exception $e) {
Expand Down
6 changes: 4 additions & 2 deletions CRM/ManualDirectDebit/Common/DirectDebitDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,16 @@ public static function getGroupIDByName($customGroupName) {
/**
* Gets id of custom field by name
*
* @param $customFieldName
* @param string $customFieldName
* @param string $customGroupName
*
* @return int
*/
public static function getCustomFieldIdByName($customFieldName) {
public static function getCustomFieldIdByName($customFieldName, $customGroupName) {
return civicrm_api3('CustomField', 'getvalue', [
'return' => "id",
'name' => $customFieldName,
'custom_group_id' => $customGroupName,
]);
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/ManualDirectDebit/Common/MandateStorageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CRM_ManualDirectDebit_Common_MandateStorageManager {
*
*/
public function assignContributionMandate($contributionId, $mandateID) {
$mandateIdCustomFieldId = CRM_ManualDirectDebit_Common_DirectDebitDataProvider::getCustomFieldIdByName("mandate_id");
$mandateIdCustomFieldId = CRM_ManualDirectDebit_Common_DirectDebitDataProvider::getCustomFieldIdByName('mandate_id', 'direct_debit_information');

civicrm_api3('Contribution', 'create', [
'id' => $contributionId,
Expand Down
2 changes: 1 addition & 1 deletion CRM/ManualDirectDebit/Hook/BuildForm/CustomData.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private function isAddOperation() {
* Hides 'DD ref' custom field
*/
private function hideDdRef() {
$customFieldId = CRM_ManualDirectDebit_Common_DirectDebitDataProvider::getCustomFieldIdByName("dd_ref");
$customFieldId = CRM_ManualDirectDebit_Common_DirectDebitDataProvider::getCustomFieldIdByName('dd_ref', 'direct_debit_mandate');
$ddRefElementNameId = $this->form->_groupTree[$this->directDebitMandateId]['fields'][$customFieldId]['element_name'];
unset($this->form->_groupTree[$this->directDebitMandateId]['fields'][$customFieldId]);
foreach ($this->form->_required as $requiredFieldsId => $requiredFieldsName) {
Expand Down
2 changes: 1 addition & 1 deletion CRM/ManualDirectDebit/Hook/BuildForm/CustomDataByType.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private function checkIfDirectDebitInformationInGroupTree() {
* Hides Direct Debit Information if it`s empty
*/
private function hideDirectDebitInformationIfEmpty() {
$customFieldId = CRM_ManualDirectDebit_Common_DirectDebitDataProvider::getCustomFieldIdByName("mandate_id");
$customFieldId = CRM_ManualDirectDebit_Common_DirectDebitDataProvider::getCustomFieldIdByName('mandate_id', 'direct_debit_information');
$mandateIdValue = $this->customGroupTree[$this->directDebitInformationId]['fields'][$customFieldId]['element_value'];

if (!isset($mandateIdValue) || empty($mandateIdValue)) {
Expand Down
5 changes: 3 additions & 2 deletions CRM/ManualDirectDebit/Hook/PageRun/TabPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ public function hideDirectDebitFields() {
*/
private function isCustomFieldNeedToHide($contributionId) {
$customFieldId = civicrm_api3('CustomField', 'getvalue', [
'return' => "id",
'name' => "mandate_id",
'return' => 'id',
'name' => 'mandate_id',
'custom_group_id' => 'direct_debit_information',
]);

$mandateId = civicrm_api3('Contribution', 'getvalue', [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CRM_ManualDirectDebit_Common_DirectDebitDataProviderTest extends BaseHeadl
* Tests getCustomFieldIdbyName function
*/
public function testGetCustomFieldIdByName() {
$customFieldId = DirectDebitDataProvider::getCustomFieldIdByName('mandate_id');
$customFieldId = DirectDebitDataProvider::getCustomFieldIdByName('mandate_id', 'direct_debit_information');
$this->assertNotNull($customFieldId);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function testAssignContributionMandate() {
$this->assertNotEmpty($contribution['values']);

$mandateIdCustomFieldId =
CRM_ManualDirectDebit_Common_DirectDebitDataProvider::getCustomFieldIdByName("mandate_id");
CRM_ManualDirectDebit_Common_DirectDebitDataProvider::getCustomFieldIdByName('mandate_id', 'direct_debit_information');
$this->assertEquals($contribution['values'][0]['custom_' . $mandateIdCustomFieldId], $mandate->id);
}

Expand All @@ -148,7 +148,7 @@ public function testChangeMandateForContribution() {
$fabricatedContribution = $fabricatedContributionWithMandate['contribution'];

$mandateIdCustomFieldId =
CRM_ManualDirectDebit_Common_DirectDebitDataProvider::getCustomFieldIdByName("mandate_id");
CRM_ManualDirectDebit_Common_DirectDebitDataProvider::getCustomFieldIdByName('mandate_id', 'direct_debit_information');

$contribution = civicrm_api3('Contribution', 'get', [
'sequential' => 1,
Expand Down Expand Up @@ -192,7 +192,7 @@ public function testDeleteMandate() {
$fabricatedContribution = $fabricatedContributionWithMandate['contribution'];

$mandateIdCustomFieldId =
CRM_ManualDirectDebit_Common_DirectDebitDataProvider::getCustomFieldIdByName("mandate_id");
CRM_ManualDirectDebit_Common_DirectDebitDataProvider::getCustomFieldIdByName('mandate_id', 'direct_debit_information');

$contribution = civicrm_api3('Contribution', 'get', [
'sequential' => 1,
Expand Down

0 comments on commit 4f2040e

Please sign in to comment.