Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CRM/Banking/BAO/BankTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public function get($k = NULL, $v = NULL) {
public static function findUnprocessedIDs($max_count) {
$results = [];
$maxcount = (int) $max_count;
$status_id_new = banking_helper_optionvalueid_by_groupname_and_name('civicrm_banking.bank_tx_status', 'new');
$status_id_new = CRM_Banking_Helpers_OptionValue::banking_helper_optionvalueid_by_groupname_and_name('civicrm_banking.bank_tx_status', 'new');
$sql_query = "SELECT `id` AS txid FROM `civicrm_bank_tx` WHERE `status_id` = '$status_id_new' ORDER BY `value_date` ASC, `id` ASC LIMIT $maxcount";
$query_results = CRM_Core_DAO::executeQuery($sql_query);
while ($query_results->fetch()) {
Expand Down
244 changes: 124 additions & 120 deletions CRM/Banking/Helpers/OptionValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,140 +16,144 @@

declare(strict_types = 1);

/**
* looks up an option group ID
*
* the implementation is probably not optimal, but it'll do for the moment
*
*/
function banking_helper_optiongroupid_by_name($group_name): int {
$result = civicrm_api3('OptionGroup', 'get', ['name' => $group_name]);

if (empty($result['id'])) {
Civi::log()->debug("org.project60.banking: Couldn't find option group '{$group_name}'!");
return 0;
}
else {
return (int) $result['id'];
}
}
class CRM_Banking_Helpers_OptionValue {

/**
* looks up an option value
*
* the implementation is probably not optimal, but it'll do for the moment
*
*/
function banking_helper_optionvalueid_by_name($group_id, $value_name): int {
$result = civicrm_api3('OptionValue', 'get', [
'name' => $value_name,
'option_group_id' => $group_id,
]);

if (empty($result['id'])) {
Civi::log()->debug("org.project60.banking: Couldn't find option value '{$value_name}'!");
return 0;
}
else {
return (int) $result['id'];
}
}
/**
* looks up an option group ID
*
* the implementation is probably not optimal, but it'll do for the moment
*
*/
public static function banking_helper_optiongroupid_by_name($group_name): int {
$result = civicrm_api3('OptionGroup', 'get', ['name' => $group_name]);

/**
* looks up an option value
*
* the implementation is probably not optimal, but it'll do for the moment
*
* @return string|0
*/
function banking_helper_optionvalue_by_name($group_id, $value_name): string|int {
$result = civicrm_api3('OptionValue', 'get', [
'name' => $value_name,
'option_group_id' => $group_id,
]);

if (empty($result['id'])) {
Civi::log()->debug("org.project60.banking: Couldn't find option value '{$value_name}'!");
return 0;
}
else {
return $result['values'][$result['id']]['value'];
if (empty($result['id'])) {
Civi::log()->debug("org.project60.banking: Couldn't find option group '{$group_name}'!");
return 0;
}
else {
return (int) $result['id'];
}
}
}

/**
* looks up an option value ID by group name and value name
*
* the implementation is probably not optimal, but it'll do for the moment
*
*/
function banking_helper_optionvalueid_by_groupname_and_name($group_name, $value_name): int {
$group_id = banking_helper_optiongroupid_by_name($group_name);
if ($group_id) {
return banking_helper_optionvalueid_by_name($group_id, $value_name);
}
else {
return 0;
/**
* looks up an option value
*
* the implementation is probably not optimal, but it'll do for the moment
*
*/
public static function banking_helper_optionvalueid_by_name($group_id, $value_name): int {
$result = civicrm_api3('OptionValue', 'get', [
'name' => $value_name,
'option_group_id' => $group_id,
]);

if (empty($result['id'])) {
Civi::log()->debug("org.project60.banking: Couldn't find option value '{$value_name}'!");
return 0;
}
else {
return (int) $result['id'];
}
}
}

/**
* looks up an option value by group name and value name
*
* the implementation is probably not optimal, but it'll do for the moment
*
* @return string|0
*/
function banking_helper_optionvalue_by_groupname_and_name($group_name, $value_name): string|int {
$group_id = banking_helper_optiongroupid_by_name($group_name);
if ($group_id) {
return banking_helper_optionvalue_by_name($group_id, $value_name);
/**
* looks up an option value
*
* the implementation is probably not optimal, but it'll do for the moment
*
* @return string|0
*/
public static function banking_helper_optionvalue_by_name($group_id, $value_name): string|int {
$result = civicrm_api3('OptionValue', 'get', [
'name' => $value_name,
'option_group_id' => $group_id,
]);

if (empty($result['id'])) {
Civi::log()->debug("org.project60.banking: Couldn't find option value '{$value_name}'!");
return 0;
}
else {
return $result['values'][$result['id']]['value'];
}
}
else {
return 0;

/**
* looks up an option value ID by group name and value name
*
* the implementation is probably not optimal, but it'll do for the moment
*
*/
public static function banking_helper_optionvalueid_by_groupname_and_name($group_name, $value_name): int {
$group_id = self::banking_helper_optiongroupid_by_name($group_name);
if ($group_id) {
return self::banking_helper_optionvalueid_by_name($group_id, $value_name);
}
else {
return 0;
}
}
}

/**
* creates an id/name => object mapping for the given option group
*
* the implementation is probably not optimal, but it'll do for the moment
*
* @package org.project60.banking
* @copyright GNU Affero General Public License
* $Id$
*
*/
function banking_helper_optiongroup_id_name_mapping($group_name) {
$group_id = banking_helper_optiongroupid_by_name($group_name);

if ($group_id) {
$result = civicrm_api3('OptionValue', 'get', ['option_group_id' => $group_id]);
$mapping = [];
foreach ($result['values'] as $entry) {
$mapping[$entry['id']] = $entry;
$mapping[$entry['name']] = $entry;
/**
* looks up an option value by group name and value name
*
* the implementation is probably not optimal, but it'll do for the moment
*
* @return string|0
*/
public static function banking_helper_optionvalue_by_groupname_and_name($group_name, $value_name): string|int {
$group_id = CRM_Banking_Helpers_OptionValue::banking_helper_optiongroupid_by_name($group_name);
if ($group_id) {
return CRM_Banking_Helpers_OptionValue::banking_helper_optionvalue_by_name($group_id, $value_name);
}
else {
return 0;
}
}

/**
* creates an id/name => object mapping for the given option group
*
* the implementation is probably not optimal, but it'll do for the moment
*
* @package org.project60.banking
* @copyright GNU Affero General Public License
* $Id$
*
*/
public static function banking_helper_optiongroup_id_name_mapping($group_name) {
$group_id = CRM_Banking_Helpers_OptionValue::banking_helper_optiongroupid_by_name($group_name);

// inject 'new' value as id 0 for convenience
$mapping[0] = $mapping['new'];
if ($group_id) {
$result = civicrm_api3('OptionValue', 'get', ['option_group_id' => $group_id]);
$mapping = [];
foreach ($result['values'] as $entry) {
$mapping[$entry['id']] = $entry;
$mapping[$entry['name']] = $entry;
}

return $mapping;
// inject 'new' value as id 0 for convenience
$mapping[0] = $mapping['new'];

return $mapping;

}
else {
return [];
}
}
else {
return [];

/**
* will check if the given tx_status_id is closed,
* i.e. marked as 'processed' or 'ignored'
*
* @return TRUE if closed, FALSE otherwise
*/
public static function banking_helper_tx_status_closed($tx_status_id) {
$status = CRM_Banking_Helpers_OptionValue::banking_helper_optiongroup_id_name_mapping('civicrm_banking.bank_tx_status');
return $status[$tx_status_id]['name'] == 'processed'
|| $status[$tx_status_id]['name'] == 'ignored';
}
}

/**
* will check if the given tx_status_id is closed,
* i.e. marked as 'processed' or 'ignored'
*
* @return TRUE if closed, FALSE otherwise
*/
function banking_helper_tx_status_closed($tx_status_id) {
$status = banking_helper_optiongroup_id_name_mapping('civicrm_banking.bank_tx_status');
return $status[$tx_status_id]['name'] == 'processed'
|| $status[$tx_status_id]['name'] == 'ignored';
}
60 changes: 32 additions & 28 deletions CRM/Banking/Helpers/URLBuilder.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<?php

declare(strict_types = 1);

/**
* -------------------------------------------------------+
* | Project 60 - CiviBanking |
Expand All @@ -18,37 +15,44 @@
* | written permission from the original author(s). |
* +--------------------------------------------------------
*/
function banking_helper_buildURL($base, $set_params, $keep_params = [], $delete_params = [], $keep_param_source = NULL): string {
if ($keep_param_source == NULL) {
$keep_param_source = $_REQUEST;
}

$params = [];
// take over selected parameters from source
foreach ($keep_params as $key) {
if (isset($keep_param_source[$key])) {
$params[$key] = $keep_param_source[$key];
declare(strict_types = 1);

class CRM_Banking_Helpers_URLBuilder {

public static function banking_helper_buildURL($base, $set_params, $keep_params = [], $delete_params = [], $keep_param_source = NULL): string {
if ($keep_param_source == NULL) {
$keep_param_source = $_REQUEST;
}
}

// add (and override) the parameters
foreach ($set_params as $key => $value) {
$params[$key] = $value;
}
$params = [];
// take over selected parameters from source
foreach ($keep_params as $key) {
if (isset($keep_param_source[$key])) {
$params[$key] = $keep_param_source[$key];
}
}

// remove requested parameters
foreach ($delete_params as $key) {
unset($params[$key]);
}
// add (and override) the parameters
foreach ($set_params as $key => $value) {
$params[$key] = $value;
}

// build string:
$pstring = '';
foreach ($params as $key => $value) {
if (strlen($pstring) > 0) {
$pstring = $pstring . '&';
// remove requested parameters
foreach ($delete_params as $key) {
unset($params[$key]);
}
$pstring = $pstring . $key . '=' . $value;

// build string:
$pstring = '';
foreach ($params as $key => $value) {
if (strlen($pstring) > 0) {
$pstring = $pstring . '&';
}
$pstring = $pstring . $key . '=' . $value;
}

return CRM_Utils_System::url($base, $pstring, FALSE, NULL, FALSE);
}

return CRM_Utils_System::url($base, $pstring, FALSE, NULL, FALSE);
}
10 changes: 5 additions & 5 deletions CRM/Banking/Matcher/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static function clearCachedInstance() {
private function getMatchers() {
if ($this->matchers === NULL) {
$this->matchers = [];
$matcher_type_id = banking_helper_optionvalueid_by_groupname_and_name('civicrm_banking.plugin_classes', 'match');
$matcher_type_id = CRM_Banking_Helpers_OptionValue::banking_helper_optionvalueid_by_groupname_and_name('civicrm_banking.plugin_classes', 'match');
$params = ['plugin_type_id' => $matcher_type_id, 'enabled' => 1];
$result = civicrm_api3('BankingPluginInstance', 'get', $params);
if (isset($result['is_error']) && $result['is_error']) {
Expand Down Expand Up @@ -104,7 +104,7 @@ private function getPostprocessors() {
if ($this->postprocessors == NULL) {
$this->postprocessors = [];

$postprocessor_type_id = banking_helper_optionvalueid_by_groupname_and_name('civicrm_banking.plugin_classes', 'postprocess');
$postprocessor_type_id = CRM_Banking_Helpers_OptionValue::banking_helper_optionvalueid_by_groupname_and_name('civicrm_banking.plugin_classes', 'postprocess');
$params = ['plugin_type_id' => $postprocessor_type_id, 'enabled' => 1];
$result = civicrm_api3('BankingPluginInstance', 'get', $params);
if (isset($result['is_error']) && $result['is_error']) {
Expand Down Expand Up @@ -154,8 +154,8 @@ public function match($btx_id, $override_processed = FALSE) {

if (!$override_processed) {
// don't match already executed transactions...
$processed_status_id = banking_helper_optionvalueid_by_groupname_and_name('civicrm_banking.bank_tx_status', 'Processed');
$ignored_status_id = banking_helper_optionvalueid_by_groupname_and_name('civicrm_banking.bank_tx_status', 'Ignored');
$processed_status_id = CRM_Banking_Helpers_OptionValue::banking_helper_optionvalueid_by_groupname_and_name('civicrm_banking.bank_tx_status', 'Processed');
$ignored_status_id = CRM_Banking_Helpers_OptionValue::banking_helper_optionvalueid_by_groupname_and_name('civicrm_banking.bank_tx_status', 'Ignored');
if ($btx->status_id == $processed_status_id || $btx->status_id == $ignored_status_id) {
// will not match already executed transactions
$lock->release();
Expand Down Expand Up @@ -221,7 +221,7 @@ public function match($btx_id, $override_processed = FALSE) {
$btx->saveSuggestions();

// set the status
$newStatus = banking_helper_optionvalueid_by_groupname_and_name('civicrm_banking.bank_tx_status', 'Suggestions');
$newStatus = CRM_Banking_Helpers_OptionValue::banking_helper_optionvalueid_by_groupname_and_name('civicrm_banking.bank_tx_status', 'Suggestions');
$btx->status_id = $newStatus;
$btx->setStatus($newStatus);

Expand Down
Loading
Loading