diff --git a/app/Model/EventBlocklist.php b/app/Model/EventBlocklist.php index cd9c0d21f..dce41343c 100644 --- a/app/Model/EventBlocklist.php +++ b/app/Model/EventBlocklist.php @@ -79,4 +79,14 @@ class EventBlocklist extends AppModel { return $this->hasAny(['event_uuid' => $eventUuid]); } + + /** + * @param string $eventUuid + * @return bool + */ + public function addEntry($entry=[]) + { + $this->create(); + return $this->save($entry); + } } diff --git a/app/Model/WorkflowModules/action/Module_add_eventblocklist_entry.php b/app/Model/WorkflowModules/action/Module_add_eventblocklist_entry.php new file mode 100644 index 000000000..19fd36c35 --- /dev/null +++ b/app/Model/WorkflowModules/action/Module_add_eventblocklist_entry.php @@ -0,0 +1,81 @@ +params = [ + [ + 'id' => 'uuid_hash_path', + 'label' => 'Event UUID Hash path', + 'type' => 'hashpath', + 'placeholder' => 'Event.uuid', + 'default' => 'Event.uuid', + 'hashpath' => [ + 'is_sub_selector' => true + ] + ], + [ + 'id' => 'eventinfo_hash_path', + 'label' => 'Event Info Hash path', + 'type' => 'hashpath', + 'placeholder' => 'Event.info', + 'default' => 'Event.info', + 'hashpath' => [ + 'is_sub_selector' => true + ] + ], + [ + 'id' => 'block_comment', + 'label' => 'Blocklist Comment', + 'type' => 'input', + 'placeholder' => 'Blocked from workflow', + 'default' => 'Blocked from workflow', + ], + ]; + + $this->EventBlocklist = ClassRegistry::init('EventBlocklist'); + $this->Organisation = ClassRegistry::init('Organisation'); + } + + public function exec(array $node, WorkflowRoamingData $roamingData, array &$errors = []): bool + { + $params = $this->getParamsWithValues($node); + + $rData = $roamingData->getData(); + + $eventUUIDExtractionPath = $params['uuid_hash_path']['value']; + $eventUUID = Hash::get($rData, $eventUUIDExtractionPath); + $eventInfoExtractionPath = $params['eventinfo_hash_path']['value']; + $eventInfo = Hash::get($rData, $eventInfoExtractionPath); + $comment = $params['block_comment']['value']; + + $org = $this->Organisation->find('first', ['conditions' => array('Organisation.id' => $rData['Event']['orgc_id']), 'recursive' => -1, 'fields' => ['Organisation.name']]); + $entry = [ + 'event_uuid' => $eventUUID, + 'event_info' => $eventInfo, + 'event_orgc' => !empty($org['Organisation']['name']) ? $org['Organisation']['name'] : 'unkwown', + 'comment' => $comment, + ]; + $r = $this->EventBlocklist->addEntry($entry); + return true; + } +}