Commit 8f20c99f authored by jaapjansma's avatar jaapjansma

Added action for changing e-mail of contact

parent d920d162
......@@ -16,5 +16,7 @@ Version 1.2
* Send E-mail To Participants
* Find message template by name
* Create or Update relationship
* Create or Update an E-mail address of an contact
* Get e-mail address of an contact
<?php
namespace Civi\ActionProvider\Action\Contact;
use \Civi\ActionProvider\Action\AbstractAction;
use \Civi\ActionProvider\Parameter\ParameterBagInterface;
use \Civi\ActionProvider\Parameter\SpecificationBag;
use \Civi\ActionProvider\Parameter\Specification;
use \Civi\ActionProvider\Parameter\OptionGroupSpecification;
use \Civi\ActionProvider\Action\Contact\ContactActionUtils;
use CRM_ActionProvider_ExtensionUtil as E;
class CreateUpdateEmailAddress 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) {
$contact_id = $parameters->getParameter('contact_id');
$id = ContactActionUtils::createEmail($contact_id, $parameters, $this->configuration);
$output->setParameter('id', $id);
}
/**
* Returns the specification of the configuration options for the actual action.
*
* @return SpecificationBag
*/
public function getConfigurationSpecification() {
$specs = new SpecificationBag();
ContactActionUtils::createEmailConfigurationSpecification($specs);
return $specs;
}
/**
* Returns the specification of the parameters of the actual action.
*
* @return SpecificationBag
*/
public function getParameterSpecification() {
$specs = new SpecificationBag(array(
new Specification('contact_id', 'Integer', E::ts('Contact ID'), false),
));
ContactActionUtils::createEmailParameterSpecification($specs);
return $specs;
}
/**
* Returns the specification of the output parameters of this action.
*
* This function could be overriden by child classes.
*
* @return SpecificationBag
*/
public function getOutputSpecification() {
return new SpecificationBag(array(
new Specification('id', 'Integer', E::ts('Email ID')),
));
}
}
\ No newline at end of file
<?php
namespace Civi\ActionProvider\Action\Contact;
use \Civi\ActionProvider\Action\AbstractAction;
use \Civi\ActionProvider\Action\Contact\ContactActionUtils;
use \Civi\ActionProvider\Parameter\ParameterBagInterface;
use \Civi\ActionProvider\Parameter\SpecificationBag;
use \Civi\ActionProvider\Parameter\Specification;
use \Civi\ActionProvider\Parameter\OptionGroupSpecification;
use \Civi\ActionProvider\Utils\CustomField;
use CRM_ActionProvider_ExtensionUtil as E;
class GetEmailAddress 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) {
$contact_id = $parameters->getParameter('contact_id');
$existingEmailAddressParams['contact_id'] = $contact_id;
$existingEmailAddressParams['location_type_id'] = $this->configuration->getParameter('location_type_id');
try {
$existingEmail = civicrm_api3('Email', 'getsingle', $existingEmailAddressParams);
foreach($existingEmail as $field => $value) {
$output->setParameter($field, $value);
}
} catch (\Exception $e) {
// Do nothing
}
}
/**
* Returns the specification of the configuration options for the actual action.
*
* @return SpecificationBag
*/
public function getConfigurationSpecification() {
$locationTypes = ContactActionUtils::getLocationTypes();
reset($locationTypes);
$defaultLocationType = key($locationTypes);
return new SpecificationBag(array(
new Specification('location_type_id', 'Integer', E::ts('Location type'), true, $defaultLocationType, null, $locationTypes, FALSE)
));
}
/**
* Returns the specification of the parameters of the actual action.
*
* @return SpecificationBag
*/
public function getParameterSpecification() {
return new SpecificationBag(array(
new Specification('contact_id', 'Integer', E::ts('Contact ID'), true),
));
}
/**
* Returns the specification of the output parameters of this action.
*
* This function could be overriden by child classes.
*
* @return SpecificationBag
*/
public function getOutputSpecification() {
$bag = new SpecificationBag();
$contact_fields = civicrm_api3('Email', 'getfields', array('action' => 'get', 'options' => array('limit' => 0)));
foreach($contact_fields['values'] as $field) {
if (empty($field['type'])) {
continue;
}
$type = \CRM_Utils_Type::typeToString($field['type']);
if (empty($type)) {
continue;
}
switch ($type) {
case 'Int':
$type = 'Integer';
break;
}
if (stripos($field['name'], 'custom_') === 0) {
// It is a custom field
$customFieldId = str_replace("custom_", "", $field['name']);
$fieldName = CustomField::getCustomFieldName($customFieldId);
$fieldSpec = new Specification(
$fieldName,
$type,
$field['title'],
false
);
$fieldSpec->setApiFieldName($field['name']);
} else {
$fieldSpec = new Specification(
$field['name'],
$type,
$field['title'],
false
);
}
$bag->addSpecification($fieldSpec);
}
return $bag;
}
}
\ No newline at end of file
......@@ -85,6 +85,10 @@ class Provider {
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_MANIPULATION_TAG,
));
$this->addActionWithoutFiltering('CreateUpdateEmailAddress', '\Civi\ActionProvider\Action\Contact\CreateUpdateEmailAddress', E::ts('Create or update an e-mail address of a contact'), array(
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_MANIPULATION_TAG,
));
$this->addActionWithoutFiltering('UsePrimaryAddressOfContact', '\Civi\ActionProvider\Action\Contact\UsePrimaryAddressOfContact', E::ts('Use primary address of another contact'), array(
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_MANIPULATION_TAG,
......@@ -93,6 +97,10 @@ class Provider {
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_RETRIEVAL_TAG,
));
$this->addActionWithoutFiltering('GetEmailAddress', '\Civi\ActionProvider\Action\Contact\GetEmailAddress', E::ts('Get e-mail address of a contact'), array(
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_RETRIEVAL_TAG,
));
$this->addActionWithoutFiltering('GetAddressById', '\Civi\ActionProvider\Action\Contact\GetAddressById', E::ts('Get address by ID'), array(
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_RETRIEVAL_TAG,
......
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