Skip to content

Commit

Permalink
Merge pull request #385 from systopia/extend-RemoteFundingApplication…
Browse files Browse the repository at this point in the history
…Process-deprecate-FundingCaseInfo

Extend RemoteFundingApplicationProcess and deprecate FundingCaseInfo
  • Loading branch information
dontub authored Jan 6, 2025
2 parents ea67419 + 17bf0aa commit 0ee842c
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Civi/Api4/FundingCaseInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
use Civi\Funding\Api4\Action\FundingCaseInfo\GetFieldsAction;
use Civi\Funding\Api4\Traits\AccessPermissionsTrait;

/**
* @deprecated Use FundingApplicationProcess (with joins) instead.
*/
final class FundingCaseInfo extends AbstractEntity {

use AccessPermissionsTrait;
Expand Down
3 changes: 3 additions & 0 deletions Civi/Api4/RemoteFundingCaseInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
use Civi\Funding\Api4\AbstractRemoteFundingEntityLegacy;
use Civi\Funding\Api4\Action\Remote\RemoteFundingGetActionLegacy;

/**
* @deprecated Use RemoteFundingApplicationProcess instead.
*/
final class RemoteFundingCaseInfo extends AbstractRemoteFundingEntityLegacy {

public static function get(): RemoteFundingGetActionLegacy {
Expand Down
3 changes: 3 additions & 0 deletions Civi/Funding/Api4/Action/FundingCaseInfo/GetAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
use Civi\RemoteTools\Api4\Query\CompositeCondition;
use Civi\RemoteTools\Api4\Query\ConditionInterface;

/**
* @deprecated
*/
final class GetAction extends AbstractGetAction {

/**
Expand Down
3 changes: 3 additions & 0 deletions Civi/Funding/Api4/Action/FundingCaseInfo/GetFieldsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
use Civi\RemoteTools\Api4\RemoteApiConstants;
use CRM_Funding_ExtensionUtil as E;

/**
* @deprecated
*/
final class GetFieldsAction extends BasicGetFieldsAction {

private Api4Interface $api4;
Expand Down
27 changes: 24 additions & 3 deletions Civi/Funding/Api4/Util/WhereUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static function containsField(array $where, string $field): bool {
foreach ($where as $clause) {
if (is_array($clause[1])) {
// Composite condition.
// @phpstan-ignore-next-line
// @phpstan-ignore argument.type
if (self::containsField($clause[1], $field)) {
return TRUE;
}
Expand All @@ -47,14 +47,35 @@ public static function containsField(array $where, string $field): bool {
return FALSE;
}

/**
* @phpstan-param whereT $where
*/
public static function containsFieldPrefix(array $where, string $fieldPrefix): bool {
foreach ($where as $clause) {
if (is_array($clause[1])) {
// Composite condition.
// @phpstan-ignore argument.type
if (self::containsFieldPrefix($clause[1], $fieldPrefix)) {
return TRUE;
}
}

if (str_starts_with($clause[0], $fieldPrefix)) {
return TRUE;
}
}

return FALSE;
}

/**
* @phpstan-param whereT $where
*/
public static function getBool(array $where, string $field): ?bool {
foreach ($where as $clause) {
if (is_array($clause[1])) {
// Composite condition.
// @phpstan-ignore-next-line
// @phpstan-ignore argument.type
return 'AND' === $clause[0] ? self::getBool($clause[1], $field) : NULL;
}

Expand All @@ -77,7 +98,7 @@ public static function getInt(array $where, string $field): ?int {
foreach ($where as $clause) {
if (is_array($clause[1])) {
// Composite condition.
// @phpstan-ignore-next-line
// @phpstan-ignore argument.type
return 'AND' === $clause[0] ? self::getInt($clause[1], $field) : NULL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ protected function getEntityName(): string {
}

protected function getJoin(RemoteFundingGetAction $action): array {
if (in_array('funding_clearing_process.status', $action->getSelect(), TRUE)
|| WhereUtil::containsField($action->getWhere(), 'funding_clearing_process.status')
if ($this->isClearingProcessFieldSelected($action)
|| WhereUtil::containsFieldPrefix($action->getWhere(), 'funding_clearing_process.')
) {
return [
[
Expand All @@ -48,4 +48,14 @@ protected function getJoin(RemoteFundingGetAction $action): array {
return [];
}

private function isClearingProcessFieldSelected(RemoteFundingGetAction $action): bool {
foreach ($action->getSelect() as $field) {
if (str_starts_with($field, 'funding_clearing_process.')) {
return TRUE;
}
}

return FALSE;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace Civi\Funding\ApplicationProcess\Api4\ActionHandler;

use Civi\Api4\FundingApplicationProcess;
use Civi\Api4\FundingCase;
use Civi\Api4\FundingClearingProcess;
use Civi\Api4\Generic\Result;
use Civi\Funding\Api4\ActionHandler\AbstractRemoteFundingGetFieldsActionHandler;
Expand All @@ -41,13 +42,122 @@ public function __construct(Api4Interface $api4, OptionsLoaderInterface $options

public function getFields(AbstractRemoteGetFieldsAction $action): Result {
$fields = parent::getFields($action);
$fields[] = [
'type' => 'Extra',
'name' => 'funding_case_id.identifier',
'nullable' => TRUE,
'title' => E::ts('Funding Case Identifier'),
'data_type' => 'String',
];

$fields[] = [
'type' => 'Extra',
'name' => 'funding_case_id.permissions',
'title' => E::ts('Permissions'),
'data_type' => 'String',
'serialize' => \CRM_Core_DAO::SERIALIZE_JSON,
'options' => $this->getOptions($action, 'FundingCase', 'permissions'),
'nullable' => FALSE,
];

$fields[] = [
'type' => 'Extra',
'name' => 'funding_case_id.status',
'title' => E::ts('Funding Case Status'),
'data_type' => 'String',
'options' => $this->getOptions($action, FundingCase::getEntityName(), 'status'),
'input_type' => 'Select',
'nullable' => FALSE,
];

$fields[] = [
'type' => 'Extra',
'name' => 'funding_case_id.creation_date',
'title' => E::ts('Funding Case Creation Date'),
'data_type' => 'Date',
'nullable' => FALSE,
];

$fields[] = [
'type' => 'Extra',
'name' => 'funding_case_id.modification_date',
'title' => E::ts('Funding Case Modification Date'),
'data_type' => 'Date',
'nullable' => FALSE,
];

$fields[] = [
'type' => 'Extra',
'name' => 'funding_case_id.amount_approved',
'title' => E::ts('Amount Approved'),
'data_type' => 'Float',
'nullable' => TRUE,
];

$fields[] = [
'type' => 'Extra',
'name' => 'funding_case_id.recipient_contact_id',
'title' => 'funding_case_recipient_contact_id',
'data_type' => 'Integer',
'nullable' => FALSE,
];

$fields[] = [
'type' => 'Extra',
'name' => 'funding_case_id.recipient_contact_id.display_name',
'title' => E::ts('Recipient'),
'data_type' => 'String',
'nullable' => FALSE,
];

$fields[] = [
'type' => 'Extra',
'name' => 'funding_case_id.funding_case_type_id',
'title' => 'funding_case_type_id',
'data_type' => 'Integer',
'nullable' => FALSE,
];

$fields[] = [
'type' => 'Extra',
'name' => 'funding_case_id.funding_case_type_id.is_combined_application',
'title' => E::ts('Is Combined Application'),
'data_type' => 'Boolean',
'nullable' => FALSE,
];

$fields[] = [
'type' => 'Extra',
'name' => 'funding_case.transfer_contract_uri',
'title' => 'funding_case_transfer_contract_uri',
'data_type' => 'String',
'nullable' => TRUE,
'operators' => [],
];

$fields[] = [
'type' => 'Extra',
'name' => 'funding_case_id.funding_program_id',
'title' => 'funding_program_id',
'data_type' => 'Integer',
'nullable' => FALSE,
];

$fields[] = [
'type' => 'Extra',
'name' => 'funding_case_id.funding_program_id.title',
'title' => E::ts('Funding Program'),
'data_type' => 'String',
'nullable' => FALSE,
];

$fields[] = [
'type' => 'Extra',
'name' => 'funding_clearing_process.status',
'nullable' => TRUE,
'title' => E::ts('Clearing Status'),
'data_type' => 'String',
'options' => $this->optionsLoader->getOptions(FundingClearingProcess::getEntityName(), 'status'),
'options' => $this->getOptions($action, FundingClearingProcess::getEntityName(), 'status'),
'input_type' => 'Select',
];

Expand All @@ -58,4 +168,17 @@ protected function getEntityName(): string {
return FundingApplicationProcess::getEntityName();
}

/**
* @phpstan-return bool|array<string|int, string>
*
* @throws \CRM_Core_Exception
*/
private function getOptions(AbstractRemoteGetFieldsAction $action, string $entityName, string $field) {
if (FALSE === $action->getLoadOptions()) {
return TRUE;
}

return $this->optionsLoader->getOptions($entityName, $field);
}

}
2 changes: 1 addition & 1 deletion Civi/RemoteTools/Api4/OptionsLoaderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
interface OptionsLoaderInterface {

/**
* @phpstan-return array<scalar|null, string>
* @phpstan-return array<string|int, string>
* Options in the form "value => label".
*
* @throws \CRM_Core_Exception
Expand Down
2 changes: 2 additions & 0 deletions services/funding-case-info.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
use Civi\Funding\EventSubscriber\Remote\FundingCaseInfoGetFieldsSubscriber;
use Civi\Funding\EventSubscriber\Remote\FundingCaseInfoGetSubscriber;

// @phpstan-ignore classConstant.deprecatedClass
$container->autowire(GetAction::class)
->setPublic(TRUE)
->setShared(FALSE);
// @phpstan-ignore classConstant.deprecatedClass
$container->autowire(GetFieldsAction::class)
->setPublic(TRUE)
->setShared(FALSE);
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/Civi/Api4/FundingCaseInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
use CRM_Funding_ExtensionUtil as E;

/**
* @deprecated
*
* @group headless
*
* @covers \Civi\Api4\FundingCaseInfo
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/Civi/Api4/RemoteFundingCaseInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
use CRM_Funding_ExtensionUtil as E;

/**
* @deprecated
*
* @group headless
*
* @covers \Civi\Api4\RemoteFundingCaseInfo
Expand Down

0 comments on commit 0ee842c

Please sign in to comment.