Skip to content

Commit

Permalink
[#26] merged form processor actions (dev_26)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjendres committed Apr 7, 2020
2 parents 7585f55 + 9d2614d commit 4c33dc4
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 13 deletions.
3 changes: 2 additions & 1 deletion CRM/I3val/Handler/SddUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function getField2Label() {
'end_date' => E::ts('End Date'),
'frequency' => E::ts('Frequency'),
'cycle_day' => E::ts('Cycle Day'),
'reason' => E::ts('Reason'),
'financial_type' => E::ts('Financial Type'),
'campaign' => E::ts('Campaign'),
'amount' => E::ts('Amount'),
Expand Down Expand Up @@ -398,7 +399,7 @@ public function generateDiffData($entity, $submitted_data, &$activity_data) {
}

// OK, we have the mandate, look for differences
$mandate_diff = array();
$mandate_diff = array();
$main_attributes = $this->getMainFields();
$all_attributes = $this->getFields();
$custom_group_name = $this->getCustomGroupName();
Expand Down
13 changes: 3 additions & 10 deletions Civi/I3val/ActionProvider/Action/RequestContactUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,12 @@ class RequestContactUpdate extends AbstractAction {
* @return SpecificationBag specs
*/
public function getConfigurationSpecification() {
// load activity types
$activity_types = ['' => E::ts("none")];
$types = \civicrm_api3('OptionValue', 'get', [
'option.limit' => 0,
'option_group_id' => 'activity_type',
'return' => 'value,label']);
foreach ($types['values'] as $type) {
$types[$type['value']] = $type['label'];
}
// get the current configuration
$configuration = \CRM_I3val_Configuration::getConfiguration();

// specify config
return new SpecificationBag([
new Specification('activity_type_id', 'Integer', E::ts('Default Activity Type'), false, null, null, $activity_types, false),
new Specification('activity_type_id', 'Integer', E::ts('Default Activity Type'), false, null, null, $configuration->getActivityTypes(), false),
]);
}

Expand Down
115 changes: 115 additions & 0 deletions Civi/I3val/ActionProvider/Action/RequestMandateUpdate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php
/*-------------------------------------------------------+
| Ilja's Input Validation Extension |
| Amnesty International Vlaanderen |
| Copyright (C) 2017-2020 SYSTOPIA |
| Author: B. Endres ([email protected]) |
| http://www.systopia.de/ |
+--------------------------------------------------------+
| This program is released as free software under the |
| Affero GPL license. You can redistribute it and/or |
| modify it under the terms of this license which you |
| can read by viewing the included agpl.txt or online |
| at www.gnu.org/licenses/agpl.html. Removal of this |
| copyright header is strictly prohibited without |
| written permission from the original author(s). |
+--------------------------------------------------------*/

namespace Civi\I3val\ActionProvider\Action;

use CRM_I3val_ExtensionUtil as E;

use \Civi\ActionProvider\Action\AbstractAction;
use \Civi\ActionProvider\Parameter\ParameterBagInterface;
use \Civi\ActionProvider\Parameter\Specification;
use \Civi\ActionProvider\Parameter\SpecificationBag;

class RequestMandateUpdate extends AbstractAction {

/**
* Returns the specification of the configuration options for the actual action.
* @return SpecificationBag specs
*/
public function getConfigurationSpecification() {
// get the current configuration
$configuration = \CRM_I3val_Configuration::getConfiguration();

// allowed status requests
$requested_status = [
'' => E::ts("No Status Change"),
'COMPLETE' => E::ts("Terminate Mandate (COMPLETE)"),
'INVALID' => E::ts("Mark Mandate as Invalid (INVALID)"),
];

// specify config
return new SpecificationBag([
new Specification('activity_type_id', 'Integer', E::ts('Default Activity Type'), false, null, null, $configuration->getActivityTypes(), false),
new Specification('i3val_note', 'String', E::ts('Note'), false, null, null, $activity_types, false),
new Specification('status', 'String', E::ts('Requested Status'), false, null, null, $requested_status, false),
]);
}

/**
* Returns the specification of the parameters of the actual action.
*
* @return SpecificationBag specs
*/
public function getParameterSpecification() {
$specs = [];

// add metadata
$specs[] = new Specification('activity_type_id', 'Integer', E::ts('Activity Type'), false, null, null, null, false);
$specs[] = new Specification('id', 'Integer', E::ts('Contact ID'), false, null, null, null, false);
$specs[] = new Specification('i3val_note', 'String', E::ts('Note'), false, null, null, null, false);
$specs[] = new Specification('i3val_schedule_date', 'String', E::ts('Requested Change Date'), false, null, null, null, false);
$specs[] = new Specification('i3val_parent_id', 'Integer', E::ts('Linked Activity ID'), false, null, null, null, false);
$specs[] = new Specification('source', 'String', E::ts('Source'), false, null, null, null, false);
$specs[] = new Specification('sdd_reason', 'String', E::ts('Cancel Reason'), false, null, null, null, false);

// add mandate identifier
$specs[] = new Specification('reference', 'String', E::ts('Mandate Reference'), true, null, null, null, false);

// basic fields
$specs[] = new Specification('status', 'String', E::ts('Status'), false, null, null, null, false);
$specs[] = new Specification('iban', 'String', E::ts('IBAN'), false, null, null, null, false);
$specs[] = new Specification('bic', 'String', E::ts('BIC'), false, null, null, null, false);

// add date fields
$specs[] = new Specification('date', 'Date', E::ts('Signature Date'), false, null, null, null, false);
$specs[] = new Specification('validation_date', 'Date', E::ts('Validation Date'), false, null, null, null, false);
$specs[] = new Specification('start_date', 'Date', E::ts('Start Date'), false, null, null, null, false);
$specs[] = new Specification('end_date', 'Date', E::ts('End Date'), false, null, null, null, false);

// add collection fields
$specs[] = new Specification('frequency', 'Integer', E::ts('Frequency'), false, null, null, null, false);
$specs[] = new Specification('cycle_day', 'Integer', E::ts('Cycle Day'), false, null, null, null, false);
$specs[] = new Specification('financial_type', 'String', E::ts('Financial Type'), false, null, null, null, false);
$specs[] = new Specification('campaign', 'String', E::ts('Campaign'), false, null, null, null, false);
$specs[] = new Specification('amount', 'Float', E::ts('Amount'), false, null, null, null, false);

return new SpecificationBag($specs);
}

/**
* Run the action
*
* @param ParameterBagInterface $parameters
* The parameters to this action.
* @param ParameterBagInterface $output
* The parameters this action can send back
* @return void
*/
protected function doAction(ParameterBagInterface $parameters, ParameterBagInterface $output) {
$params = $parameters->toArray();

// override if necessary
foreach (['activity_type_id', 'i3val_note', 'status'] as $field_name) {
if (empty($params[$field_name])) {
$params[$field_name] = $this->configuration->getParameter($field_name);
}
}

// execute
$result = \civicrm_api3('SepaMandate', 'request_update', $params);
}
}
8 changes: 6 additions & 2 deletions Civi/I3val/ContainerSpecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*-------------------------------------------------------+
| Ilja's Input Validation Extension |
| Amnesty International Vlaanderen |
| Copyright (C) 2017-2019 SYSTOPIA |
| Copyright (C) 2017-2020 SYSTOPIA |
| Author: B. Endres ([email protected]) |
| http://www.systopia.de/ |
+--------------------------------------------------------+
Expand Down Expand Up @@ -34,7 +34,11 @@ public function process(ContainerBuilder $container) {
$typeFactoryDefinition = $container->getDefinition('action_provider');
$typeFactoryDefinition->addMethodCall('addAction', ['RequestContactUpdate', 'Civi\I3val\ActionProvider\Action\RequestContactUpdate', E::ts('Request Contact Update'), [
\Civi\ActionProvider\Action\AbstractAction::SINGLE_CONTACT_ACTION_TAG,
\Civi\ActionProvider\Action\AbstractAction::DATA_RETRIEVAL_TAG
\Civi\ActionProvider\Action\AbstractAction::DATA_MANIPULATION_TAG
]]);
$typeFactoryDefinition->addMethodCall('addAction', ['RequestMandateUpdate', 'Civi\I3val\ActionProvider\Action\RequestMandateUpdate', E::ts('Request CiviSEPA Mandate Update'), [
\Civi\ActionProvider\Action\AbstractAction::SINGLE_CONTACT_ACTION_TAG,
\Civi\ActionProvider\Action\AbstractAction::DATA_MANIPULATION_TAG
]]);
}
}

0 comments on commit 4c33dc4

Please sign in to comment.