Commit 8afcebe0 authored by jaapjansma's avatar jaapjansma

refactor

parent 47d07b2c
Version 1.2
===========
** Renamed actions**
* Renamed the Create/Update Group action from Create to GroupCreate. If you are using the _Create/Update Group_ action you have to reconfigure it.
** Other Major changes **
* Refactor of the action provider, so that list of available actions only contains the title, name and not the instaciated class (with all the loaded configuration, such as groups, option values etc..)
** New actions**
* Added action to send an e-mail to event participants
......@@ -87,25 +87,6 @@ abstract class AbstractAction implements \JsonSerializable {
*/
abstract public function getParameterSpecification();
/**
* Returns the human readable title of this action
*/
abstract public function getTitle();
/**
* Returns the system name of the action.
*
* We generate one based on the namespace of the class
* and the class name.
*
* @return string
*/
public function getName() {
$reflect = new \ReflectionClass($this);
$className = $reflect->getShortName();
return $className;
}
/**
* Returns the specification of the output parameters of this action.
*
......@@ -135,10 +116,10 @@ abstract class AbstractAction implements \JsonSerializable {
*/
public function execute(ParameterBagInterface $parameters, ParameterBagInterface $conditionParameters, ParameterBagInterface $invalidConditionOutput) {
if (!$this->validateConfiguration()) {
throw new InvalidConfigurationException("Found invalid configuration for the action: ".$this->getTitle());
throw new InvalidConfigurationException("Found invalid configuration for the action: ".get_class($this));
}
if (!$this->validateParameters($parameters)) {
throw new InvalidParameterException("Found invalid parameters for the action: ".$this->getTitle());
throw new InvalidParameterException("Found invalid parameters for the action: ".get_class($this));
}
if ($this->condition && !$this->condition->isConditionValid($conditionParameters)) {
......@@ -190,21 +171,6 @@ abstract class AbstractAction implements \JsonSerializable {
$this->configuration = $configuration;
return $this;
}
/**
* Returns a list with tags for this action.
*
* Each tag might indicate in what context this action might be used.
* Filtering which actions might be useful in a certain context
* is done by the Provider class or a child class of the provider.
*
* Tags could also be aliases of the action name.
*
* @return array
*/
public function getTags() {
return array();
}
/**
* Sets the condition object
......@@ -265,17 +231,13 @@ abstract class AbstractAction implements \JsonSerializable {
if ($this->getDefaultConfiguration()) {
$return['default_configuration'] = $this->getDefaultConfiguration()->toArray();
}
$return['name'] = $this->getName();
$return['title'] = $this->getTitle();
return $return;
}
/**
* Returns the data structure to serialize it as a json
*/
public function jsonSerialize() {
$return['name'] = $this->getName();
$return['title'] = $this->getTitle();
// An empty array goes wrong with the default confifuration.
if (empty($return['default_configuration'])) {
$return['default_configuration'] = new \stdClass();;
......
......@@ -17,13 +17,6 @@ use CRM_ActionProvider_ExtensionUtil as E;
class CreateActivity extends AbstractAction {
/**
* Returns the human readable title of this action
*/
public function getTitle() {
return E::ts('Create or update activity');
}
/**
* Returns the specification of the configuration options for the actual
* action.
......@@ -137,16 +130,6 @@ class CreateActivity extends AbstractAction {
}
}
/**
* Returns the tags for this action.
*/
public function getTags() {
return array(
AbstractAction::MULTIPLE_CONTACTS_ACTION_TAG,
AbstractAction::DATA_MANIPULATION_TAG
);
}
}
\ No newline at end of file
......@@ -17,13 +17,6 @@ use CRM_ActionProvider_ExtensionUtil as E;
class DeleteActivity extends AbstractAction {
/**
* Returns the human readable title of this action
*/
public function getTitle() {
return E::ts('Delete activity');
}
/**
* Returns the specification of the configuration options for the actual
* action.
......@@ -80,16 +73,6 @@ class DeleteActivity extends AbstractAction {
}
}
/**
* Returns the tags for this action.
*/
public function getTags() {
return array(
AbstractAction::MULTIPLE_CONTACTS_ACTION_TAG,
AbstractAction::DATA_MANIPULATION_TAG
);
}
}
\ No newline at end of file
......@@ -16,13 +16,6 @@ use CRM_ActionProvider_ExtensionUtil as E;
class GetActivity extends AbstractAction {
/**
* Returns the human readable title of this action
*/
public function getTitle() {
return E::ts('Get activity data');
}
/**
* Returns the specification of the configuration options for the actual
* action.
......@@ -106,16 +99,6 @@ class GetActivity extends AbstractAction {
}
}
/**
* Returns the tags for this action.
*/
public function getTags() {
return array(
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_RETRIEVAL_TAG,
);
}
}
\ No newline at end of file
......@@ -16,13 +16,6 @@ use CRM_ActionProvider_ExtensionUtil as E;
class Send extends AbstractAction {
/**
* Returns the human readable title of this action
*/
public function getTitle() {
return E::ts('Send Bulk Mail');
}
/**
* Returns the specification of the configuration options for the actual action.
*
......@@ -113,14 +106,4 @@ class Send extends AbstractAction {
$output->setParameter('id', $mailing['id']);
}
/**
* Returns the tags for this action.
*/
public function getTags() {
return array(
AbstractAction::SEND_MESSAGES_TO_CONTACTS,
'bulk_mail',
);
}
}
\ No newline at end of file
......@@ -104,21 +104,4 @@ class ContactDataById extends AbstractAction {
return $bag;
}
/**
* Returns the human readable title of this action
*/
public function getTitle() {
return E::ts('Get contact data by ID');
}
/**
* Returns the tags for this action.
*/
public function getTags() {
return array(
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_RETRIEVAL_TAG,
);
}
}
......@@ -66,21 +66,4 @@ class CreateUpdateAddress extends AbstractAction {
));
}
/**
* Returns the human readable title of this action
*/
public function getTitle() {
return E::ts('Create or update address of a contact');
}
/**
* Returns the tags for this action.
*/
public function getTags() {
return array(
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_MANIPULATION_TAG,
);
}
}
\ No newline at end of file
......@@ -114,21 +114,4 @@ class CreateUpdateHousehold extends AbstractAction {
));
}
/**
* Returns the human readable title of this action
*/
public function getTitle() {
return E::ts('Create or update Household');
}
/**
* Returns the tags for this action.
*/
public function getTags() {
return array(
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_MANIPULATION_TAG,
);
}
}
......@@ -128,21 +128,4 @@ class CreateUpdateIndividual extends AbstractAction {
));
}
/**
* Returns the human readable title of this action
*/
public function getTitle() {
return E::ts('Create or update Individual');
}
/**
* Returns the tags for this action.
*/
public function getTags() {
return array(
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_MANIPULATION_TAG,
);
}
}
......@@ -84,21 +84,4 @@ class FindOrCreateContactByEmail extends AbstractAction {
));
}
/**
* Returns the human readable title of this action
*/
public function getTitle() {
return E::ts('Find or create contact by e-mail');
}
/**
* Returns the tags for this action.
*/
public function getTags() {
return array(
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_MANIPULATION_TAG,
);
}
}
......@@ -112,21 +112,4 @@ class GetAddress extends AbstractAction {
return $bag;
}
/**
* Returns the human readable title of this action
*/
public function getTitle() {
return E::ts('Get address of a contact');
}
/**
* Returns the tags for this action.
*/
public function getTags() {
return array(
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_RETRIEVAL_TAG,
);
}
}
\ No newline at end of file
......@@ -106,21 +106,4 @@ class GetAddressById extends AbstractAction {
return $bag;
}
/**
* Returns the human readable title of this action
*/
public function getTitle() {
return E::ts('Get address by ID');
}
/**
* Returns the tags for this action.
*/
public function getTags() {
return array(
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_RETRIEVAL_TAG,
);
}
}
\ No newline at end of file
......@@ -87,21 +87,4 @@ class GetContactIdFromMasterAddress extends AbstractAction {
));
}
/**
* Returns the human readable title of this action
*/
public function getTitle() {
return E::ts('Get contact ID of a master address');
}
/**
* Returns the tags for this action.
*/
public function getTags() {
return array(
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_RETRIEVAL_TAG,
);
}
}
\ No newline at end of file
......@@ -80,23 +80,6 @@ class UpdateCustomData extends AbstractAction {
public function getOutputSpecification() {
return new SpecificationBag();
}
/**
* Returns the human readable title of this action
*/
public function getTitle() {
return E::ts('Update custom data for a contact');
}
/**
* Returns the tags for this action.
*/
public function getTags() {
return array(
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_MANIPULATION_TAG,
);
}
}
\ No newline at end of file
......@@ -120,22 +120,4 @@ class UsePrimaryAddressOfContact extends AbstractAction {
new Specification('id', 'Integer', E::ts('Address ID')),
));
}
/**
* Returns the human readable title of this action
*/
public function getTitle() {
return E::ts('Use primary address of another contact');
}
/**
* Returns the tags for this action.
*/
public function getTags() {
return array(
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_MANIPULATION_TAG,
);
}
}
\ No newline at end of file
......@@ -15,13 +15,6 @@ use Dompdf\Exception;
class CreateOrUpdateEvent extends AbstractAction {
/**
* Returns the human readable title of this action
*/
public function getTitle() {
return E::ts('Create or update an event');
}
/**
* Returns the specification of the configuration options for the actual action.
*
......@@ -160,14 +153,5 @@ class CreateOrUpdateEvent extends AbstractAction {
throw new \Civi\ActionProvider\Exception\ExecutionException(E::ts('Could not update or create an event.'));
}
}
/**
* Returns the tags for this action.
*/
public function getTags() {
return array(
AbstractAction::DATA_MANIPULATION_TAG,
);
}
}
\ No newline at end of file
......@@ -12,14 +12,7 @@ use \Civi\ActionProvider\Utils\CustomField;
use CRM_ActionProvider_ExtensionUtil as E;
class CreateOrUpdateParticipant extends AbstractAction {
/**
* Returns the human readable title of this action
*/
public function getTitle() {
return E::ts('Register contact for an event');
}
/**
* Returns the specification of the configuration options for the actual action.
*
......@@ -143,15 +136,5 @@ class CreateOrUpdateParticipant extends AbstractAction {
throw new \Civi\ActionProvider\Exception\ExecutionException(E::ts('Could not update or create a participant record'));
}
}
/**
* Returns the tags for this action.
*/
public function getTags() {
return array(
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_MANIPULATION_TAG,
);
}
}
\ No newline at end of file
......@@ -13,13 +13,6 @@ use CRM_ActionProvider_ExtensionUtil as E;
class CreateOrUpdateParticipantWithDynamicStatus extends AbstractAction {
/**
* Returns the human readable title of this action
*/
public function getTitle() {
return E::ts('Register contact for an event (with dynamic status)');
}
/**
* Returns the specification of the configuration options for the actual action.
*
......@@ -143,15 +136,5 @@ class CreateOrUpdateParticipantWithDynamicStatus extends AbstractAction {
throw new \Civi\ActionProvider\Exception\ExecutionException(E::ts('Could not update or create a participant record'));
}
}
/**
* Returns the tags for this action.
*/
public function getTags() {
return array(
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_MANIPULATION_TAG,
);
}
}
\ No newline at end of file
......@@ -15,13 +15,6 @@ use CRM_ActionProvider_ExtensionUtil as E;
class DeleteEvent extends AbstractAction {
/**
* Returns the human readable title of this action
*/
public function getTitle() {
return E::ts('Delete event');
}
/**
* Returns the specification of the configuration options for the actual
* action.
......@@ -78,15 +71,6 @@ class DeleteEvent extends AbstractAction {
}
}
/**
* Returns the tags for this action.
*/
public function getTags() {
return array(
AbstractAction::DATA_MANIPULATION_TAG
);
}
}
\ No newline at end of file
......@@ -11,13 +11,6 @@ use CRM_ActionProvider_ExtensionUtil as E;
class DeleteParticipant extends AbstractAction {
/**
* Returns the human readable title of this action
*/
public function getTitle() {
return E::ts('Delete participant');
}
/**
* Returns the specification of the configuration options for the actual action.
*
......@@ -96,15 +89,5 @@ class DeleteParticipant extends AbstractAction {
throw new \Civi\ActionProvider\Exception\ExecutionException(E::ts('Could not delete participant'));
}
}
/**
* Returns the tags for this action.
*/
public function getTags() {
return array(
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_MANIPULATION_TAG,
);
}
}
\ No newline at end of file
......@@ -14,13 +14,6 @@ use CRM_ActionProvider_ExtensionUtil as E;
class GetEvent extends AbstractAction {
/**
* Returns the human readable title of this action
*/
public function getTitle() {
return E::ts('Get event data');
}
/**
* Returns the specification of the configuration options for the actual action.
*
......@@ -78,14 +71,6 @@ class GetEvent extends AbstractAction {
}
if (stripos($field['name'], 'custom_') === 0) {
$customFieldId = str_replace("custom_", "", $field['name']);
/*var_dump($field);
// It is a custom field
$customFieldId = str_replace("custom_", "", $field['name']);
$fieldSpec = CustomField::getSpecFromCustomField($field);
echo $field['id']."\r\n";
if ($fieldSpec) {
echo "API: ".$fieldSpec->getApiFieldName()."\r\n";
}*/
$fieldName = CustomField::getCustomFieldName($customFieldId);
$fieldSpec = new Specification(
$fieldName,
......@@ -160,13 +145,6 @@ class GetEvent extends AbstractAction {
// Do nothing
}
}
/**
* Returns the tags for this action.
*/
public function getTags() {
return array(
AbstractAction::DATA_RETRIEVAL_TAG,
);
}
}
\ No newline at end of file
......@@ -13,13 +13,6 @@ use CRM_ActionProvider_ExtensionUtil as E;
class GetParticipant extends AbstractAction {
/**
* Returns the human readable title of this action
*/
public function getTitle() {
return E::ts('Get participant data');
}
/**
* Returns the specification of the configuration options for the actual action.
*
......@@ -137,14 +130,5 @@ class GetParticipant extends AbstractAction {
}
}
/**
* Returns the tags for this action.
*/
public function getTags() {
return array(
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_RETRIEVAL_TAG,
);
}
}
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
namespace Civi\ActionProvider\Action\Event;
use Civi\ActionProvider\Action\AbstractAction;
use Civi\ActionProvider\Parameter\ParameterBagInterface;
use Civi\ActionProvider\Parameter\Specification;
use Civi\ActionProvider\Parameter\SpecificationBag;
use CRM_ActionProvider_ExtensionUtil as E;
class SendEmailToParticipants 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
* @throws \Exception
*/
protected function doAction(ParameterBagInterface $parameters, ParameterBagInterface $output) {
$participantParams['event_id'] = $parameters->getParameter('event_id');
$participantParams['options']['limit'] = 0;
$participants = civicrm_api3('Participant', 'get', $participantParams);
$contactIds = array();
foreach($participants['values'] as $participant) {
$contactIds[] = $participant['contact_id'];
}
$senderContact = civicrm_api3('Contact', 'getsingle', array('id' => $parameters->getParameter('sender_contact_id')));
$email = new \Civi\ActionProvider\Utils\SendEmail($senderContact['email'], $senderContact['display_name']);
$email->send($contactIds, $parameters->getParameter('subject'), $parameters->getParameter('message'), $parameters->getParameter('message'));
}
/**