This repository has been archived by the owner on Oct 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #159 from compucorp/develop
HC-58: Fix Problems Scheduling Unlimited Resources
- Loading branch information
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters