Skip to content
Snippets Groups Projects
Commit 114a9de9 authored by jaapjansma's avatar jaapjansma
Browse files

Fixed #11: Action for retrieving the group and when it doesn't exists create it based on the title

parent 1342d2e3
No related branches found
No related tags found
No related merge requests found
Version 1.50 (not yet released)
------------
* Create/Update group action also checks on the title. (#11)
* Added summary to create event action (!32 and #10)
Version 1.49
......
......@@ -25,7 +25,10 @@ class Create extends AbstractAction {
*/
public function getConfigurationSpecification() {
$visibilityOptions = \CRM_Contact_DAO_Group::buildOptions('visibility');
$checkTitle = new Specification('check_for_title', 'Boolean', E::ts('Check title for existence'), false, false);
$checkTitle->setDescription(E::ts('Check whether the group already exists based on the title'));
return new SpecificationBag([
$checkTitle,
new OptionGroupSpecification('group_type','group_type', E::ts('Group type'), FALSE),
new Specification('visibility','String', E::ts('Visibility'), FALSE, null, null, $visibilityOptions),
]);
......@@ -92,6 +95,17 @@ class Create extends AbstractAction {
// Get the contact and the event.
if ($parameters->doesParameterExists('id')) {
$groupApiParams['id'] = $parameters->getParameter('id');
} elseif ($this->configuration->getParameter('check_for_title')) {
try {
$groupApiParams['id'] = civicrm_api3('Group', 'getvalue', [
'return' => 'id',
'is_active' => 1,
'is_hidden' => 0,
'title' => $parameters->getParameter('title')
]);
} catch (\CiviCRM_API3_Exception $ex) {
// Do nothing
}
}
$groupApiParams['title'] = $parameters->getParameter('title');
$groupApiParams['description'] = $parameters->getParameter('description');
......@@ -121,4 +135,4 @@ class Create extends AbstractAction {
}
\ No newline at end of file
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment