Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

HC-58: Fix Problems Scheduling Unlimited Resources #159

Merged
merged 5 commits into from
Nov 28, 2017
Merged
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
66 changes: 66 additions & 0 deletions CRM/Booking/APIWrapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

/**
* API Wrapper that pre processes and post processes API Calls.
*/
class CRM_Booking_APIWrapper implements API_Wrapper {
/**
* Alter the parameters of the api request.
*
* @param array $apiRequest
*
* @return array
*/
public function fromApiInput($apiRequest) {
$this->fixParametersArray($apiRequest['params']);

return $apiRequest;
}

/**
* alter the result before returning it to the caller.
*
* @param array $apiRequest
* @param array $result
*
* @return array
*/
public function toApiOutput($apiRequest, $result) {
return $result;
}

/**
* Fixes parameters array so that if chained API calls are made, any chained
* fields with '$value.' are moved to the end of the array.
*
* @param array $params
*/
private function fixParametersArray(&$params) {
$chainedValues = array();

foreach ($params as $parameter => &$value) {
if (stripos($parameter, 'api.') === 0 && is_array($value)) {
$allChainedValues = TRUE;

foreach ($value as $chainedParameter => $chainedValue) {
if (stripos($chainedValue, '$value.') !== 0) {
$allChainedValues = FALSE;
}
}

if ($allChainedValues) {
$value['sequential'] = 0;
}

$this->fixParametersArray($value);
}
elseif (stripos($value, '$value.') === 0) {
unset($params[$parameter]);
$chainedValues[$parameter] = $value;
}
}

$params = array_merge($params, $chainedValues);
}

}
12 changes: 12 additions & 0 deletions booking.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -558,3 +558,15 @@ function booking_civicrm_alterAPIPermissions($entity, $action, &$params, &$permi
}

}

/**
* Implements hook_civicrm_apiWrappers()
*
* @param array $wrappers
* @param array $apiRequest
*/
function booking_civicrm_apiWrappers(&$wrappers, $apiRequest) {
if ($apiRequest['entity'] == 'Resource' && $apiRequest['action'] == 'get') {
$wrappers[] = new CRM_Booking_APIWrapper();
}
}