Commit bb84ebba authored by jaapjansma's avatar jaapjansma

Added Option label action

parent db36337c
......@@ -3,6 +3,7 @@ Version 1.4 (not yet released)
* Changed the implementation of the civicrm_container hook.
* Added action to upload files
* Added action to retrieve the labels from option values
Version 1.3
-----------
......
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
namespace Civi\ActionProvider\Action\Generic;
use \Civi\ActionProvider\Action\AbstractAction;
use \Civi\ActionProvider\Parameter\ParameterBagInterface;
use \Civi\ActionProvider\Parameter\SpecificationBag;
use \Civi\ActionProvider\Parameter\Specification;
use \Civi\ActionProvider\Utils\CustomField;
use CRM_ActionProvider_ExtensionUtil as E;
class OptionValueToLabel extends AbstractAction {
/**
* Returns the specification of the configuration options for the actual action.
*
* @return SpecificationBag
*/
public function getConfigurationSpecification() {
$optionGroups = array();
$option_groups_api = civicrm_api3('OptionGroup', 'get', array('options' => array('limit' => 0, 'is_active' => 1)));
foreach($option_groups_api['values'] as $optionGroup) {
$optionGroups[$optionGroup['name']] = $optionGroup['title'];
}
return new SpecificationBag(array(
new Specification('option_group_id', 'String', E::ts('Option Group'), true, null, null, $optionGroups),
));
}
/**
* Returns the specification of the configuration options for the actual action.
*
* @return SpecificationBag
* @throws \Exception
*/
public function getParameterSpecification() {
return new SpecificationBag(array(
new Specification('value', 'String', E::ts('Value'), true, null, null, null, true),
));
}
/**
* 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('value', 'String', E::ts('Value')),
));
}
/**
* 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) {
$value = $parameters->getParameter('value');
$option_group_id = $this->configuration->getParameter('option_group_id');
if (is_array($value)) {
$labels = array();
foreach($value as $v) {
$labels[] = civicrm_api3('OptionValue', 'getvalue', array('return' => 'label', 'value' => $v, 'option_group_id' => $option_group_id));
}
$output->setParameter('value', $labels);
} else {
$label = civicrm_api3('OptionValue', 'getvalue', array('return' => 'label', 'value' => $v, 'option_group_id' => $option_group_id));
$output->setParameter('value', $label);
}
}
}
\ No newline at end of file
......@@ -56,6 +56,8 @@ class Provider {
protected $batchActions = array();
public function __construct() {
$this->addActionWithoutFiltering('OptionValueToLabel', '\Civi\ActionProvider\Action\Generic\OptionValueToLabel', E::ts('Show option value(s) as their Label(s)'), array(
AbstractAction::DATA_MANIPULATION_TAG));
$this->addActionWithoutFiltering('SetValue', '\Civi\ActionProvider\Action\Generic\SetValue', E::ts('Set Value'), array(
AbstractAction::DATA_MANIPULATION_TAG));
$this->addActionWithoutFiltering('SetDateValue', '\Civi\ActionProvider\Action\Generic\SetDateValue', E::ts('Set date value'), array(
......
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