convert batchexportperm to use actual batch data; displaying export data is WIP

This commit is contained in:
Jon Goldberg 2019-08-13 12:37:18 -04:00
parent 9f2da42ae1
commit 05997ff2f6
No known key found for this signature in database
GPG Key ID: C2D2247364F9DB13

View File

@ -85,47 +85,6 @@ function batchexportperm_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
*/
function batchexportperm_civicrm_managed(&$entities) {
_batchexportperm_civix_civicrm_managed($entities);
$entities[] = [
'module' => 'org.agbu.batchexportperm',
'name' => 'batchexportperm_batch_details',
'entity' => 'CustomGroup',
'params' => [
'version' => 3,
'name' => 'batchexportperm_batch_details',
'title' => 'Batch Details',
'extends' => 'Contribution',
'style' => 'Inline',
'collapse_display' => 1,
'is_active' => TRUE,
'is_multiple' => FALSE,
'collapse_adv_display' => 0,
'is_reserved' => TRUE,
],
];
$entities[] = [
'module' => 'org.agbu.batchexportperm',
'name' => 'export_date',
'entity' => 'CustomField',
'params' => [
'version' => 3,
'name' => 'export_date',
'label' => 'Export Date',
'data_type' => 'Date',
'html_type' => 'Select Date',
'is_required' => FALSE,
'is_searchable' => FALSE,
'is_search_range' => FALSE,
'is_active' => TRUE,
'is_view' => TRUE,
'date_format' => 'mm/dd/yy',
'time_format' => 1,
'text_length' => 255,
'column_name' => 'export_date',
'note_columns' => 150,
'note_rows' => 4,
'custom_group_id' => 'batchexportperm_batch_details',
],
];
}
/**
@ -281,17 +240,19 @@ function _batchexportperm_civicrm_check_permission($contributionId, $errorType =
* @param int $contributionId
*/
function _batchexportperm_civicrm_allow_contribution_to_edit($contributionId) {
$customFieldId = civicrm_api3('CustomField', 'getvalue', [
'return' => "id",
'custom_group_id' => "batchexportperm_batch_details",
'name' => "export_date",
]);
$exportDate = civicrm_api3('Contribution', 'get', [
'return' => "custom_{$customFieldId}",
'id' => $contributionId,
'sequential' => 1,
])['values'][0]["custom_{$customFieldId}"];
if (empty($exportDate) || CRM_Core_Permission::check('edit exported contributions')) {
// See if the contribution has been exported.
// Man, I wish API4 actually worked.
$query = "SELECT ceft.entity_id "
. "FROM civicrm_entity_batch ceb "
. "JOIN civicrm_batch cb on ceb.batch_id = cb.id AND ceb.entity_table = 'civicrm_financial_trxn' "
. "JOIN civicrm_entity_financial_trxn ceft ON ceft.entity_table = 'civicrm_contribution' AND ceb.entity_id = ceft.financial_trxn_id "
. "JOIN civicrm_option_value cov on cov.value = cb.status_id AND cov.label = 'Exported' "
. "JOIN civicrm_option_group cog ON cov.option_group_id = cog.id AND cog.name = 'batch_status' "
. "WHERE ceft.entity_id = %1";
$params = [1 => [$contributionId, 'Integer']];
$dao = CRM_Core_DAO::executeQuery($query, $params);
if ($dao->N === 0 || CRM_Core_Permission::check('edit exported contributions')) {
return TRUE;
}
return FALSE;
@ -312,29 +273,13 @@ function batchexportperm_civicrm_post($op, $objectName, $objectId, &$objectRef)
}
/**
* Set export date custom field for contribution when batch is exported.
* Display batch eport info on the contribution.
*
* @param int $batchId
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_buildForm
*/
function _batchexportperm_civicrm_update_contribution_exporteddate($batchId) {
$customFieldId = civicrm_api3('CustomField', 'getvalue', [
'return' => "id",
'custom_group_id' => "batchexportperm_batch_details",
'name' => "export_date",
]);
$sql = "SELECT cc.id contribution_id
FROM civicrm_contribution cc
INNER JOIN civicrm_entity_financial_trxn ceft
ON ceft.entity_id = cc.id AND ceft.entity_table = 'civicrm_contribution'
INNER JOIN civicrm_entity_batch ceb
ON ceb.entity_id = ceft.financial_trxn_id
AND ceb.entity_table = 'civicrm_financial_trxn' AND ceb.batch_id = {$batchId}
GROUP BY cc.id";
$dao = CRM_Core_DAO::executeQuery($sql);
while ($dao->fetch()) {
civicrm_api3('Contribution', 'create', [
'id' => $dao->contribution_id,
"custom_{$customFieldId}" => date('Y-m-d H:i:s'),
]);
}
function batchexportperm_civicrm_buildForm($formName, $form) {
if (in_array($formName, ['CRM_Contribute_Form_ContributionView', 'CRM_Contribute_Form_Contribution']) &&
!empty($form->_id)) {
$temp = $form->_id;
$temp2 = }
}