added a way to store new budget for financial type

This commit is contained in:
CiviWare Solutions 2018-08-12 01:29:39 +05:30
parent 1b4aa80f24
commit cb23c5152b
2 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,36 @@
<?php
class CRM_AnnualGrantBudgets_APIWrapper implements API_Wrapper {
/**
* the wrapper contains a method that allows you to alter the parameters of the api request (including the action and the entity)
*/
public function fromApiInput($apiRequest) {
$params = $apiRequest['params'];
if (!empty($params['id'])) {
$ids = explode('_', $params['id']);
if (count($ids) == 2) {
unset($params['id']);
$gBParams = [
'financial_type_id' => $ids[0],
'fiscal_year' => $ids[1],
];
try {
$gBId = civicrm_api3('GrantBudget', 'getvalue', $gBParams + ['return' => 'id']);
$params['id'] = $gBId;
}
catch (CiviCRM_API3_Exception $e) {
$params += $gBParams;
}
$apiRequest['params'] = $params;
}
}
return $apiRequest;
}
/**
* alter the result before returning it to the caller.
*/
public function toApiOutput($apiRequest, $result) {
return $result;
}
}

View File

@ -201,3 +201,15 @@ function annualgrantbudgets_civicrm_navigationMenu(&$menu) {
]);
_annualgrantbudgets_civix_navigationMenu($menu);
}
/**
* Implements hook_civicrm_apiWrappers().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_apiWrappers
*
*/
function annualgrantbudgets_civicrm_apiWrappers(&$wrappers, $apiRequest) {
if (strtolower($apiRequest['entity']) == 'grantbudget' && $apiRequest['action'] == 'create') {
$wrappers[] = new CRM_AnnualGrantBudgets_APIWrapper();
}
}