From ab32cbbafbbfe7118528cd92be164463a472d796 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak <pradeep.nayak@webaccess.co.in> Date: Wed, 3 Sep 2014 14:37:51 +0530 Subject: [PATCH] -- MRG-2, fixing of for form rule when a profile has only grant fields(no custom fields) and/or contact fields --- CRM/Grant/Form/Task/PickProfile.php | 2 +- CRM/Mrg/BAO/Mrg.php | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CRM/Grant/Form/Task/PickProfile.php b/CRM/Grant/Form/Task/PickProfile.php index 2b375a0..79cfa20 100644 --- a/CRM/Grant/Form/Task/PickProfile.php +++ b/CRM/Grant/Form/Task/PickProfile.php @@ -162,7 +162,7 @@ class CRM_Grant_Form_Task_PickProfile extends CRM_Grant_Form_Task { // Throw error when a profile is used for multiple grant type if (CRM_Mrg_BAO_Mrg::getProfileTypes($fields['uf_group_id'], $form->_grantIds)) { - $errors['uf_group_id'] = ts('Batch update requires that all selected grants be the same basic type (e.g. all Emergency OR all Family Support...) and of the sam contact type. The profile selected for batch update must allow editing of all grant types. Please modify your selection and try again.'); + $errors['uf_group_id'] = ts('Batch update requires that all selected grants be the same basic type (e.g. all Emergency OR all Family Support...) and of the same contact type. The profile selected for batch update must allow editing of all grant types. Please modify your selection and try again.'); } return $errors; } diff --git a/CRM/Mrg/BAO/Mrg.php b/CRM/Mrg/BAO/Mrg.php index 9497e61..90434a8 100755 --- a/CRM/Mrg/BAO/Mrg.php +++ b/CRM/Mrg/BAO/Mrg.php @@ -369,7 +369,24 @@ GROUP BY ccg.id"; return TRUE; } else { - $query = 'SELECT cg.id FROM civicrm_grant cg INNER JOIN civicrm_contact cc ON cc.id = cg.contact_id WHERE cg.id IN (' . implode(',', $grantIds) . ') GROUP BY grant_type_id, contact_type'; + $groupByClause = array(); + if (!empty($grantTypes)) { + $groupByClause[] = 'grant_type_id'; + } + $dao = CRM_Core_DAO::executeQuery("SELECT id FROM civicrm_uf_field WHERE uf_group_id = {$profileId} + AND field_type IN ('Individual', 'Organization', 'Household') AND is_active = 1"); + + if ($dao->N) { + $groupByClause[] = 'contact_type'; + } + + $query = 'SELECT cg.id FROM civicrm_grant cg INNER JOIN civicrm_contact cc ON cc.id = cg.contact_id WHERE cg.id IN (' . implode(',', $grantIds) . ') '; + if (!empty($groupByClause)) { + $query .= ' GROUP BY ' . implode(',', $groupByClause); + } + else { + return FALSE; + } $result = CRM_Core_DAO::executeQuery($query); if ($result->N > 1) { return TRUE; -- GitLab