Commit 76bb12a6 authored by FoadYousefi's avatar FoadYousefi
Browse files

New action to add multiple contacts to a group

This is useful if you want to add multiple contacts at once to a group instead of one at a time
parent 8cea3cb1
......@@ -26,6 +26,10 @@ class Actions {
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_MANIPULATION_TAG,
));
$provider->addAction('AddMultipleToGroupParameter', '\Civi\ActionProvider\Action\Group\AddMultipleToGroupParameter', E::ts('Contact: Add multiple to Group (with group ID as parameter)'), array(
AbstractAction::MULTIPLE_CONTACTS_ACTION_TAG,
AbstractAction::DATA_MANIPULATION_TAG,
));
$provider->addAction('RemoveFromGroupParameter', '\Civi\ActionProvider\Action\Group\RemoveFromGroupParameter', E::ts('Contact: Remove from group (with group ID as parameter)'), array(
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_MANIPULATION_TAG,
......
<?php
namespace Civi\ActionProvider\Action\Group;
use \Civi\ActionProvider\Action\AbstractAction;
use \Civi\ActionProvider\Parameter\ParameterBagInterface;
use \Civi\ActionProvider\Parameter\SpecificationBag;
use \Civi\ActionProvider\Parameter\Specification;
use CRM_ActionProvider_ExtensionUtil as E;
class AddMultipleToGroupParameter extends AbstractAction {
/**
* Run the action
*
* @param ParameterInterface $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) {
$contactIds = $parameters->getParameter('contact_id');
$contactIds = explode( ',', $contactIds );
$contactIds = array_map( 'trim', $contactIds );
civicrm_api3('GroupContact', 'create', array(
'contact_id' => $contactIds,
'group_id' => $parameters->getParameter('group_id'),
));
}
/**
* Returns the specification of the configuration options for the actual action.
*
* @return SpecificationBag
*/
public function getConfigurationSpecification() {
return new SpecificationBag(array());
}
/**
* Returns the specification of the parameters of the actual action.
*
* @return SpecificationBag
*/
public function getParameterSpecification() {
return new SpecificationBag(array(
new Specification('contact_id', 'String', E::ts('Contact IDs'), true),
new Specification('group_id', 'Integer', E::ts('Group ID'), true, null, 'Group', null, FALSE),
));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment