Compare commits
8 Commits
7e9c5502f4
...
master
Author | SHA1 | Date | |
---|---|---|---|
37bc03a58f | |||
a24c24e846 | |||
a035142540 | |||
bdfc89f904 | |||
20c8985954 | |||
7d15dd1c4d | |||
54ab2b53bb | |||
6175e0623f |
83
CRM/SoftCredit/SoftCreditQueryObject.php
Normal file
83
CRM/SoftCredit/SoftCreditQueryObject.php
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class CRM_SoftCredit_SoftCreditQueryObject extends CRM_Contact_BAO_Query_Interface {
|
||||||
|
|
||||||
|
static $_networkFields = array();
|
||||||
|
|
||||||
|
public function &getFields() {
|
||||||
|
return self::$_networkFields;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $query
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function select(&$query) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $query
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function where(&$query) {
|
||||||
|
if (!empty($query->_paramLookup['soft_credit_name'])) {
|
||||||
|
list($name, $op, $value, $grouping, $wildcard) = reset($query->_paramLookup['soft_credit_name']);
|
||||||
|
if ($value) {
|
||||||
|
$query->_where[$grouping][] = "civicrm_contact_creditee.sort_name LIKE '%{$value}%'";
|
||||||
|
$query->_whereTables['civicrm_contribution_soft_creditee_contact'] = 1;
|
||||||
|
$query->_tables['civicrm_contribution_soft_creditee_contact'] = 1;
|
||||||
|
$query->_whereTables['civicrm_contribution_soft'] = 1;
|
||||||
|
$query->_tables['civicrm_contribution_soft'] = 1;
|
||||||
|
$query->_qill[$grouping][] = ts("%1 %2 - '%3'", [1 => 'Soft Creditee\'s name', 2 => 'LIKE', 3 => $value]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $name
|
||||||
|
* @param $mode
|
||||||
|
* @param $side
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function from($name, $mode, $side) {
|
||||||
|
if ($name == 'civicrm_contribution_soft_creditee_contact') {
|
||||||
|
return " $side JOIN civicrm_contact civicrm_contact_creditee
|
||||||
|
ON (civicrm_contribution_soft.contact_id = civicrm_contact_creditee.id)
|
||||||
|
";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $tables
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function setTableDependency(&$tables) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPanesMapper(&$panes) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $panes
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function registerAdvancedSearchPane(&$panes) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param CRM_Core_Form $form
|
||||||
|
* @param $type
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function buildAdvancedSearchPaneForm(&$form, $type) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $paneTemplatePathArray
|
||||||
|
* @param $type
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function setAdvancedSearchPaneTemplatePath(&$paneTemplatePathArray, $type) {
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -149,12 +149,36 @@ function softcreditcustomfields_civicrm_entityTypes(&$entityTypes) {
|
|||||||
_softcreditcustomfields_civix_civicrm_entityTypes($entityTypes);
|
_softcreditcustomfields_civix_civicrm_entityTypes($entityTypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_civicrm_preProcess().
|
||||||
|
*
|
||||||
|
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_preProcess
|
||||||
|
*/
|
||||||
|
function softcreditcustomfields_civicrm_preProcess($formName, &$form) {
|
||||||
|
if (in_array($formName, ['CRM_Contribute_Form_Search', 'CRM_Contact_Form_Search_Advanced'])) {
|
||||||
|
$extendsMap = &CRM_Core_BAO_CustomQuery::$extendsMap;
|
||||||
|
$extendsMap['ContributionSoft'] = 'civicrm_contribution_soft';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements hook_civicrm_buildForm().
|
* Implements hook_civicrm_buildForm().
|
||||||
*
|
*
|
||||||
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_buildForm
|
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_buildForm
|
||||||
*/
|
*/
|
||||||
function softcreditcustomfields_civicrm_buildForm($formName, &$form) {
|
function softcreditcustomfields_civicrm_buildForm($formName, &$form) {
|
||||||
|
if (('CRM_Contribute_Form_Search' == $formName && $form->getVar('_context') == 'search')
|
||||||
|
|| ('CRM_Contact_Form_Search_Advanced' == $formName && ('CiviContribute' == $form->_searchPane || $form->_flagSubmitted))
|
||||||
|
) {
|
||||||
|
CRM_Contribute_BAO_Query::addCustomFormFields($form, ['ContributionSoft']);
|
||||||
|
$form->add('text', 'soft_credit_name', ts('Soft Creditee\'s name'));
|
||||||
|
if ('CRM_Contact_Form_Search_Advanced' == $formName && 'CiviContribute' != $form->_searchPane) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CRM_Core_Region::instance('page-footer')->add(array(
|
||||||
|
'template' => "CRM/Contribute/Form/Search/SoftCredit-Search.tpl",
|
||||||
|
));
|
||||||
|
}
|
||||||
if ('CRM_Contribute_Form_ContributionView' == $formName) {
|
if ('CRM_Contribute_Form_ContributionView' == $formName) {
|
||||||
$softCredits = $form->get_template_vars('softContributions');
|
$softCredits = $form->get_template_vars('softContributions');
|
||||||
if (!empty($softCredits)) {
|
if (!empty($softCredits)) {
|
||||||
@ -188,7 +212,18 @@ function softcreditcustomfields_civicrm_buildForm($formName, &$form) {
|
|||||||
);
|
);
|
||||||
_softcreditcustomfields_addCustomDataToForm($form, $entityId, $blockId);
|
_softcreditcustomfields_addCustomDataToForm($form, $entityId, $blockId);
|
||||||
}
|
}
|
||||||
|
if ($form->_flagSubmitted) {
|
||||||
|
$submitValues = $form->_submitValues;
|
||||||
|
foreach ($form->_required as $key => $fieldName) {
|
||||||
|
if (strpos($fieldName, 'soft_credit_custom[') !== FALSE) {
|
||||||
|
$fieldName = str_replace('soft_credit_custom[', '', $fieldName);
|
||||||
|
$blockId = strstr($fieldName, ']', TRUE);
|
||||||
|
if (empty($submitValues['soft_credit_amount'][$blockId])) {
|
||||||
|
unset($form->_required[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -208,7 +243,7 @@ function _softcreditcustomfields_addCustomDataToForm(&$form, $entityId, $blockId
|
|||||||
foreach ($groupTree as $id => $group) {
|
foreach ($groupTree as $id => $group) {
|
||||||
foreach ($group['fields'] as $fldId => $field) {
|
foreach ($group['fields'] as $fldId => $field) {
|
||||||
$groupTree[$id]['fields'][$fldId]['element_custom_name'] = $field['element_name'];
|
$groupTree[$id]['fields'][$fldId]['element_custom_name'] = $field['element_name'];
|
||||||
$groupTree[$id]['fields'][$fldId]['element_name'] = "soft_credit[$blockId][{$field['element_name']}]";
|
$groupTree[$id]['fields'][$fldId]['element_name'] = "soft_credit_custom[$blockId][{$field['element_name']}]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,17 +269,87 @@ function _softcreditcustomfields_addCustomDataToForm(&$form, $entityId, $blockId
|
|||||||
// And we can't set it to 'soft_credit_' because we want to set it in a slightly different format.
|
// And we can't set it to 'soft_credit_' because we want to set it in a slightly different format.
|
||||||
CRM_Core_BAO_CustomGroup::buildQuickForm($form, $groupTree, FALSE, 'dnc_');
|
CRM_Core_BAO_CustomGroup::buildQuickForm($form, $groupTree, FALSE, 'dnc_');
|
||||||
|
|
||||||
// during contact editing : if no softCredit is filled
|
|
||||||
// required custom data must not produce 'required' form rule error
|
|
||||||
// more handling done in formRule func
|
|
||||||
//self::storeRequiredCustomDataInfo($form, $groupTree);
|
|
||||||
$tplGroupTree = CRM_Core_Smarty::singleton()
|
$tplGroupTree = CRM_Core_Smarty::singleton()
|
||||||
->get_template_vars('soft_credit_groupTree');
|
->get_template_vars('soft_credit_custom_groupTree');
|
||||||
$tplGroupTree = empty($tplGroupTree) ? [] : $tplGroupTree;
|
$tplGroupTree = empty($tplGroupTree) ? [] : $tplGroupTree;
|
||||||
|
|
||||||
$form->assign('soft_credit_groupTree', $tplGroupTree + [$blockId => $groupTree]);
|
$form->assign('soft_credit_custom_groupTree', $tplGroupTree + [$blockId => $groupTree]);
|
||||||
// unset the temp smarty var that got created
|
// unset the temp smarty var that got created
|
||||||
$form->assign('dnc_groupTree', NULL);
|
$form->assign('dnc_groupTree', NULL);
|
||||||
}
|
}
|
||||||
// softCredit custom data processing ends ..
|
// softCredit custom data processing ends ..
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_civicrm_postProcess().
|
||||||
|
*
|
||||||
|
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_postProcess
|
||||||
|
*/
|
||||||
|
function softcreditcustomfields_civicrm_postProcess($formName, &$form) {
|
||||||
|
if ('CRM_Contribute_Form_Contribution' == $formName
|
||||||
|
&& !($form->getVar('_action') & CRM_Core_Action::DELETE)
|
||||||
|
) {
|
||||||
|
$contributionId = $form->getVar('_id');
|
||||||
|
$params = $form->getVar('_params');
|
||||||
|
if (empty($params['soft_credit_custom'])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!empty($params['soft_credit_contact_id'])) {
|
||||||
|
foreach ($params['soft_credit_contact_id'] as $key => $softContactId) {
|
||||||
|
if ($softContactId
|
||||||
|
&& isset($params['soft_credit_amount'][$key])
|
||||||
|
&& !empty($params['soft_credit_custom'][$key])
|
||||||
|
) {
|
||||||
|
$softParams = [
|
||||||
|
'contribution_id' => $contributionId,
|
||||||
|
'contact_id' => $softContactId,
|
||||||
|
'amount' => $params['soft_credit_amount'][$key],
|
||||||
|
'return' => 'id',
|
||||||
|
];
|
||||||
|
if (!empty($params['soft_credit_type'][$key])) {
|
||||||
|
$softParams['soft_credit_type_id'] = $params['soft_credit_type'][$key];
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$softContributionId = civicrm_api3('ContributionSoft', 'getvalue', $softParams);
|
||||||
|
$softParams = [
|
||||||
|
'id' => $softContributionId,
|
||||||
|
] + $params['soft_credit_custom'][$key];
|
||||||
|
civicrm_api3('ContributionSoft', 'create', $softParams);
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_civicrm_queryObjects().
|
||||||
|
*
|
||||||
|
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_queryObjects
|
||||||
|
*/
|
||||||
|
function softcreditcustomfields_civicrm_queryObjects(&$queryObjects, $type) {
|
||||||
|
if ($type == 'Contact') {
|
||||||
|
$queryObjects[] = new CRM_SoftCredit_SoftCreditQueryObject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements hook_civicrm_queryObjects().
|
||||||
|
*
|
||||||
|
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_queryObjects
|
||||||
|
*/
|
||||||
|
function softcreditcustomfields_civicrm_alterContent(&$content, $context, $tplName, &$object) {
|
||||||
|
if (in_array($tplName, [
|
||||||
|
'CRM/Contribute/Form/Search/AdvancedSearchPane.tpl',
|
||||||
|
'CRM/Contribute/Form/Search.tpl'
|
||||||
|
])) {
|
||||||
|
$content = str_replace(
|
||||||
|
"cj('#contribution_soft_credit_type_id').val('');",
|
||||||
|
'',
|
||||||
|
$content
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
33
templates/CRM/Contribute/Form/Search/SoftCredit-Search.tpl
Normal file
33
templates/CRM/Contribute/Form/Search/SoftCredit-Search.tpl
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
{if $form.soft_credit_name}
|
||||||
|
<div class="crm-softcredit-form-block-soft_credit_sort_name">
|
||||||
|
{$form.soft_credit_name.label}<br>
|
||||||
|
{$form.soft_credit_name.html}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{if $contributionSoftGroupTree}
|
||||||
|
<div class="softcredit_custom_groups">
|
||||||
|
<br>
|
||||||
|
{include file="CRM/Custom/Form/Search.tpl" groupTree=$contributionSoftGroupTree showHideLinks=false}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
{if $contributionSoftGroupTree OR $form.soft_credit_name}
|
||||||
|
<script type="text/javascript">
|
||||||
|
{literal}
|
||||||
|
CRM.$(function($) {
|
||||||
|
$('div#contribution_soft_credit_type_wrapper').append($('div.crm-softcredit-form-block-soft_credit_sort_name'));
|
||||||
|
$('div#contribution_soft_credit_type_wrapper').append($('div.softcredit_custom_groups'));
|
||||||
|
|
||||||
|
hideShowInMemoryOf();
|
||||||
|
$('select#contribution_or_softcredits').change(hideShowInMemoryOf);
|
||||||
|
|
||||||
|
function hideShowInMemoryOf() {
|
||||||
|
let softOption = $('select#contribution_or_softcredits').val();
|
||||||
|
if (softOption == 'only_contribs') {
|
||||||
|
$('div#contribution_soft_credit_type_wrapper').show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
{/literal}
|
||||||
|
</script>
|
||||||
|
{/if}
|
@ -3,7 +3,7 @@
|
|||||||
{assign var='blockId' value=$smarty.section.i.index}
|
{assign var='blockId' value=$smarty.section.i.index}
|
||||||
<tr id="soft-credit-custom_row-{$blockId}" class="customFieldIgnore {if $blockId gte $showSoftCreditRow}hiddenElement{/if}" >
|
<tr id="soft-credit-custom_row-{$blockId}" class="customFieldIgnore {if $blockId gte $showSoftCreditRow}hiddenElement{/if}" >
|
||||||
<td colspan='3'>
|
<td colspan='3'>
|
||||||
{foreach from=$soft_credit_groupTree.$blockId item=cd_edit key=group_id name=custom_sets}
|
{foreach from=$soft_credit_custom_groupTree.$blockId item=cd_edit key=group_id name=custom_sets}
|
||||||
{if $cd_edit.is_multiple and $multiRecordDisplay eq 'single'}
|
{if $cd_edit.is_multiple and $multiRecordDisplay eq 'single'}
|
||||||
{assign var="isSingleRecordEdit" value=TRUE}
|
{assign var="isSingleRecordEdit" value=TRUE}
|
||||||
{else}
|
{else}
|
||||||
@ -12,7 +12,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{if $isSingleRecordEdit}
|
{if $isSingleRecordEdit}
|
||||||
<div class="custom-group custom-group-{$cd_edit.name}">
|
<div class="custom-group custom-group-{$cd_edit.name}">
|
||||||
{include file="CRM/Custom/Form/Edit/CustomData.tpl" customDataEntity='soft_credit'}
|
{include file="CRM/Custom/Form/Edit/CustomData.tpl" customDataEntity='soft_credit_custom'}
|
||||||
</div>
|
</div>
|
||||||
{else}
|
{else}
|
||||||
<div class="custom-group custom-group-{$cd_edit.name} crm-accordion-wrapper crm-custom-accordion {if $cd_edit.collapse_display and !$skipTitle}collapsed{/if}">
|
<div class="custom-group custom-group-{$cd_edit.name} crm-accordion-wrapper crm-custom-accordion {if $cd_edit.collapse_display and !$skipTitle}collapsed{/if}">
|
||||||
@ -22,7 +22,7 @@
|
|||||||
</div><!-- /.crm-accordion-header -->
|
</div><!-- /.crm-accordion-header -->
|
||||||
{/if}
|
{/if}
|
||||||
<div class="crm-accordion-body">
|
<div class="crm-accordion-body">
|
||||||
{include file="CRM/Custom/Form/Edit/CustomData.tpl" customDataEntity='soft_credit'}
|
{include file="CRM/Custom/Form/Edit/CustomData.tpl" customDataEntity='soft_credit_custom'}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
Reference in New Issue
Block a user