Commit cd87246a authored by jaapjansma's avatar jaapjansma

Added action get activity contacts

parent f5b7ee60
......@@ -11,6 +11,8 @@ Version 1.3
*New actions*
* Get contact IDs from an activity
Version 1.2
-----------
......
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
namespace Civi\ActionProvider\Action\Activity;
use Civi\ActionProvider\Action\AbstractAction;
use Civi\ActionProvider\Parameter\OptionGroupSpecification;
use Civi\ActionProvider\Parameter\ParameterBagInterface;
use Civi\ActionProvider\Parameter\Specification;
use Civi\ActionProvider\Parameter\SpecificationBag;
use CRM_ActionProvider_ExtensionUtil as E;
class GetActivityContact extends AbstractAction {
/**
* Returns the specification of the configuration options for the actual
* action.
*
* @return SpecificationBag
*/
public function getConfigurationSpecification() {
$bag = new SpecificationBag();
$bag->addSpecification(new OptionGroupSpecification('record_type', 'activity_contacts', E::ts('Record type'), false, null, true));
return $bag;
}
/**
* Returns the specification of the parameters of the actual action.
*
* @return SpecificationBag
*/
public function getParameterSpecification() {
$bag = new SpecificationBag([
new Specification('id', 'Integer', E::ts('Activity ID'), true),
]);
return $bag;
}
/**
* 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();
$bag->addSpecification(new Specification('contact_ids', 'Integer', E::ts('Contact IDs'), false, null, null, false, true));
$bag->addSpecification(new Specification('first_contact_id', 'Integer', E::ts('First found contact ID'), false, null, null, false, false));
return $bag;
}
/**
* Run the action
*
* @param ParameterBagInterface $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) {
$id = $parameters->getParameter('id');
$record_type_ids = $this->configuration->getParameter('record_type');
$sql = "SELECT DISTINCT contact_id FROM civicrm_activity_contact WHERE activity_id = %1";
$sqlParams[1] = array($id, 'Integer');
if ($record_type_ids && is_array($record_type_ids) && count($record_type_ids)) {
$sql .= " AND record_type_id IN (".implode(", ", $record_type_ids).")";
}
$dao = \CRM_Core_DAO::executeQuery($sql, $sqlParams);
$contact_ids = array();
while($dao->fetch()) {
$contact_ids[] = $dao->contact_id;
}
$output->setParameter('first_contact_id', reset($contact_ids));
$output->setParameter('contact_ids', $contact_ids);
}
}
\ No newline at end of file
......@@ -151,6 +151,10 @@ class Provider {
AbstractAction::MULTIPLE_CONTACTS_ACTION_TAG,
AbstractAction::DATA_RETRIEVAL_TAG,
));
$this->addActionWithoutFiltering('GetActivityContact', '\Civi\ActionProvider\Action\Activity\GetActivityContact', E::ts('Get contact IDs from an activity'), array(
AbstractAction::MULTIPLE_CONTACTS_ACTION_TAG,
AbstractAction::DATA_RETRIEVAL_TAG,
));
$this->addActionWithoutFiltering('Send', '\Civi\ActionProvider\Action\BulkMail\Send',E::ts('Send Bulk Mail') , array(
AbstractAction::SEND_MESSAGES_TO_CONTACTS,
'bulk_mail'
......
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