Compare commits

..

No commits in common. "master" and "master" have entirely different histories.

4 changed files with 93 additions and 56 deletions

View File

@ -1,7 +1,7 @@
<?php <?php
require_once 'batchexportperm.civix.php'; require_once 'batchexportperm.civix.php';
// use CRM_Batchexportperm_ExtensionUtil as E; use CRM_Batchexportperm_ExtensionUtil as E;
/** /**
* Implements hook_civicrm_config(). * Implements hook_civicrm_config().
@ -85,6 +85,47 @@ function batchexportperm_civicrm_upgrade($op, CRM_Queue_Queue $queue = NULL) {
*/ */
function batchexportperm_civicrm_managed(&$entities) { function batchexportperm_civicrm_managed(&$entities) {
_batchexportperm_civix_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' => TRUE,
'is_active' => TRUE,
'is_multiple' => FALSE,
'collapse_adv_display' => FALSE,
'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',
],
];
} }
/** /**
@ -240,51 +281,59 @@ function _batchexportperm_civicrm_check_permission($contributionId, $errorType =
* @param int $contributionId * @param int $contributionId
*/ */
function _batchexportperm_civicrm_allow_contribution_to_edit($contributionId) { function _batchexportperm_civicrm_allow_contribution_to_edit($contributionId) {
$customFieldId = civicrm_api3('CustomField', 'getvalue', [
$exportDate = _getExportData($contributionId); 'return' => "id",
'custom_group_id' => "batchexportperm_batch_details",
if (!$exportDate || CRM_Core_Permission::check('edit exported contributions')) { 'name' => "export_date",
]);
$exportDate = civicrm_api3('Contribution', 'getvalue', [
'return' => "custom_{$customFieldId}",
'id' => $contributionId,
]);
if (empty($exportDate) || CRM_Core_Permission::check('edit exported contributions')) {
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
} }
/** /**
* Given a contribution ID, return its batch export date. * Implements hook_civicrm_post().
*
* @param int $contributionId
* @return string|null This contribution's batch export date if it exists.
* *
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_post * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_post
*/ */
function _getExportData($contributionId) { function batchexportperm_civicrm_post($op, $objectName, $objectId, &$objectRef) {
// See if the contribution has been exported. if ($objectName == 'Batch' && $op == 'edit') {
// Man, I wish API4 actually worked. if (CRM_Core_Smarty::singleton()->get_template_vars("batch_status_change_{$objectId}")) {
$query = "SELECT cb.modified_date " _batchexportperm_civicrm_update_contribution_exporteddate($objectId);
. "FROM civicrm_entity_batch ceb " CRM_Core_Smarty::singleton()->assign("batch_status_change_{$objectId}", FALSE);
. "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']];
$date = CRM_Core_DAO::singleValueQuery($query, $params);
return CRM_Utils_Date::customFormat($date);
} }
/** /**
* Display batch eport info on the contribution. * Set export date custom field for contribution when batch is exported.
* *
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_buildForm * @param int $batchId
*/ */
function batchexportperm_civicrm_buildForm($formName, $form) { function _batchexportperm_civicrm_update_contribution_exporteddate($batchId) {
if ($formName == 'CRM_Contribute_Form_ContributionView' || $customFieldId = civicrm_api3('CustomField', 'getvalue', [
$formName == 'CRM_Contribute_Form_Contribution' && !empty($form->_id)) { 'return' => "id",
// ContributionView doesn't pass the ID in the form object? Really? 'custom_group_id' => "batchexportperm_batch_details",
$contributionId = $form->_id ?? CRM_Utils_Request::retrieve('id', 'Positive'); 'name' => "export_date",
$exportDate = _getExportData($contributionId); ]);
$form->assign('exportDate', $exportDate); $sql = "SELECT cc.id contribution_id
CRM_Core_Region::instance('page-body')->add(['template' => "CRM/Batchexportperm/Form/BatchDetails.tpl"]); FROM civicrm_contribution cc
CRM_Core_Resources::singleton()->addScriptFile('org.agbu.batchexportperm', 'js/exportDate.js'); 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'),
]);
} }
} }

View File

@ -14,13 +14,20 @@
<url desc="Support">http://FIXME</url> <url desc="Support">http://FIXME</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url> <url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls> </urls>
<releaseDate>2019-08-13</releaseDate> <releaseDate>2018-06-29</releaseDate>
<version>2.0</version> <version>1.0</version>
<develStage>stable</develStage> <develStage>stable</develStage>
<compatibility> <compatibility>
<ver>5.16</ver> <ver>4.6</ver>
<ver>4.7</ver>
<ver>5.0</ver>
<ver>5.1</ver>
<ver>5.2</ver>
<ver>5.2</ver>
<ver>5.3</ver>
<ver>5.4</ver>
</compatibility> </compatibility>
<comments></comments> <comments>This is a new, undeveloped module</comments>
<civix> <civix>
<namespace>CRM/BatchExportPerm</namespace> <namespace>CRM/BatchExportPerm</namespace>
</civix> </civix>

View File

@ -1,3 +0,0 @@
CRM.$(function ($) {
$('#export-details-accordion').insertBefore('.crm-submit-buttons:last');
});

View File

@ -1,16 +0,0 @@
<div id="export-details-accordion" class="crm-accordion-wrapper">
<div class="crm-accordion-header">
{ts}Export Details{/ts}
</div><!-- /.crm-accordion-header -->
<div class="crm-accordion-body">
<table>
<tr class="export-details">
<td class="label">Export Date</td>
<td>{$exportDate}</td>
</tr>
</table>
</div><!-- /.crm-accordion-body -->
</div><!-- /.crm-accordion-wrapper -->