From 93e3e57749490b7b2bca1a079dc6f147265d5cf6 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 11 Sep 2019 21:02:59 -0400 Subject: [PATCH] WIP Submit api --- .../core/Civi/Api4/Action/Afform/Submit.php | 55 +++++++++++++++++++ ext/afform/core/ang/af/ModelList.js | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 ext/afform/core/Civi/Api4/Action/Afform/Submit.php diff --git a/ext/afform/core/Civi/Api4/Action/Afform/Submit.php b/ext/afform/core/Civi/Api4/Action/Afform/Submit.php new file mode 100644 index 0000000000..94241a121f --- /dev/null +++ b/ext/afform/core/Civi/Api4/Action/Afform/Submit.php @@ -0,0 +1,55 @@ +_afformEntities as $entityName => $entity) { + // Predetermined values override submitted values + $this->_submission[$entity['af-type']][$entityName] = ($entity['af-values'] ?? []) + ($this->values[$entityName] ?? []); + } + // Determines the order in which to process entities. Contacts go first. + $entitiesToProcess = [ + 'Contact' => 'processContacts', + 'Activity' => 'processActivities', + ]; + foreach ($entitiesToProcess as $entityType => $callback) { + if (!empty($this->_submission[$entityType])) { + $this->$callback($this->_submission[$entityType]); + } + } + foreach (array_diff_key($this->_submission, $entitiesToProcess) as $entityType) { + + } + } + + protected function processGenericEntity($entityType, $items) { + foreach ($items as $name => $item) { + civicrm_api4($entityType, 'save', $items); + } + } + + protected function processContacts($contacts) { + foreach ($contacts as $name => $contact) { + + } + } + +} diff --git a/ext/afform/core/ang/af/ModelList.js b/ext/afform/core/ang/af/ModelList.js index 03652da7ae..ef696de090 100644 --- a/ext/afform/core/ang/af/ModelList.js +++ b/ext/afform/core/ang/af/ModelList.js @@ -55,7 +55,7 @@ }; this.submit = function submit() { - CRM.alert('TODO: Submit'); + crmApi4('Afform', 'submit', {name: CRM.afform.open, args: $routeParams, values: data}); }; } }; -- 2.25.1