Commit 5b80509c authored by jaapjansma's avatar jaapjansma
Browse files

update

parent 8bf8d209
Version 1.6
-----------
* Update related membership when create relationship or create/update relationship action is performed.
* Added action Get Contact By Custom Field.
Version 1.5
-----------
------------------------------
* Added action Get Relationship By Contact ID
* Added action Get State/Province ID by name
* Fixed issue with the Get Relationship action
Version 1.4
......
......@@ -127,8 +127,8 @@ class ContactActionUtils {
$addressParams['city'] = $parameters->getParameter('city');
$hasAddressParams = true;
}
if ($parameters->getParameter('state')) {
$addressParams['state_province_id'] = $parameters->getParameter('state');
if ($parameters->getParameter('state_province_id')) {
$addressParams['state_province_id'] = $parameters->getParameter('state_province_id');
$hasAddressParams = true;
}
if ($parameters->getParameter('country_id')) {
......
<?php
namespace Civi\ActionProvider\Action\Contact;
use \Civi\ActionProvider\Action\AbstractAction;
use Civi\ActionProvider\Exception\InvalidParameterException;
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 FindByCustomField 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_type = civicrm_api3('ContactType', 'getsingle', array('id' => $this->configuration->getParameter('contact_type')));
$contact_sub_type = false;
if (isset($contact_type['parent_id']) && $contact_type['parent_id'] > 0) {
$contact_sub_type = $contact_type;
$contact_type = civicrm_api3('ContactType', 'getsingle', array('id' => $contact_sub_type['parent_id']));
}
$apiParams = array();
foreach($this->getParameterSpecification() as $spec) {
if ($parameters->doesParameterExists($spec->getName())) {
$apiParams[$spec->getApiFieldName()] = $parameters->getParameter($spec->getName());
}
}
if (!count($apiParams)) {
throw new InvalidParameterException(E::ts("No parameter given"));
}
$apiParams['contact_type'] = $contact_type['name'];
if ($contact_sub_type) {
$apiParams['contact_sub_type'] = $contact_sub_type['name'];
}
$apiParams['return'] = 'id';
$contact_id = civicrm_api3('Contact', 'getvalue', $apiParams);
$output->setParameter('contact_id', $contact_id);
}
/**
* Returns the specification of the configuration options for the actual action.
*
* @return SpecificationBag
*/
public function getConfigurationSpecification() {
return new SpecificationBag(array(
new Specification('contact_type', 'Integer', E::ts('Contact type'), true, null, 'ContactType', null, FALSE),
));
}
/**
* Returns the specification of the parameters of the actual action.
*
* @return SpecificationBag
*/
public function getParameterSpecification() {
$specs = new SpecificationBag();
$customGroups = civicrm_api3('CustomGroup', 'get', array('is_active' => 1, 'is_multiple' => 0, 'options' => array('limit' => 0)));
foreach($customGroups['values'] as $customGroup) {
if (!in_array($customGroup['extends'], array('Individual', 'Household', 'Organization', 'Contact'))) {
continue;
}
$customFields = civicrm_api3('CustomField', 'get', array('custom_group_id' => $customGroup['id'], 'is_active' => 1, 'options' => array('limit' => 0)));
foreach($customFields['values'] as $customField) {
$spec = CustomField::getSpecFromCustomField($customField, $customGroup['title'].': ', false);
if ($spec) {
$specs->addSpecification($spec);
}
}
}
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('contact_id', 'Integer', E::ts('Contact ID'), true)
));
}
}
<?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\Utils\CustomField;
use CRM_ActionProvider_ExtensionUtil as E;
class GetStateProvinceId extends AbstractAction {
/**
* Run the action
*
* @param ParameterBagInterface $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) {
if ($this->configuration->doesParameterExists('use_abbreviation') && $this->configuration->getParameter('use_abbreviation')) {
$sql = "SELECT id FROM `civicrm_state_province` WHERE `country_id` = %1 AND `abbreviation` = %2";
$params[1] = [$parameters->getParameter('country_id'), 'Integer'];
$params[2] = [$parameters->getParameter('state_province'), 'String'];
} else {
$sql = "SELECT id FROM `civicrm_state_province` WHERE `country_id` = %1 AND `name` = %2";
$params[1] = [$parameters->getParameter('country_id'), 'Integer'];
$params[2] = [$parameters->getParameter('state_province'), 'String'];
}
$state_id = \CRM_Core_DAO::singleValueQuery($sql, $params);
$output->setParameter('state_province_id', $state_id);
}
/**
* Returns the specification of the configuration options for the actual action.
*
* @return SpecificationBag
*/
public function getConfigurationSpecification() {
return new SpecificationBag(array(
new Specification('use_abbreviation', 'Boolean', E::ts('Use abbreviation'), true, false),
));
}
/**
* Returns the specification of the parameters of the actual action.
*
* @return SpecificationBag
*/
public function getParameterSpecification() {
return new SpecificationBag(array(
new Specification('country_id', 'Integer', E::ts('Country ID'), true),
new Specification('state_province', 'String', E::ts('State/Province name'), 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([
new Specification('state_province_id', 'Integer', E::ts('State/Province ID'), true),
]);
return $bag;
}
}
......@@ -60,6 +60,10 @@ class UpdateCustomData extends AbstractAction {
$customFields = civicrm_api3('CustomField', 'get', array('custom_group_id' => $customGroup['id'], 'is_active' => 1, 'options' => array('limit' => 0)));
foreach($customFields['values'] as $customField) {
if (isset($customField['is_view']) && $customField['is_view']) {
continue;
}
$spec = CustomField::getSpecFromCustomField($customField, $customGroup['title'].': ', false);
if ($spec) {
$specs->addSpecification($spec);
......
......@@ -116,7 +116,7 @@ class CreateOrUpdateRelationship extends CreateRelationship {
try {
// Do not use api as the api checks for an existing relationship.
$relationship = \CRM_Contact_BAO_Relationship::create($relationshipParams);
$relationship = \CRM_Contact_BAO_Relationship::add($relationshipParams);
$output->setParameter('id', $relationship->id);
} catch (\Exception $e) {
// Do nothing.
......
......@@ -129,7 +129,7 @@ class CreateRelationship extends AbstractAction {
}
try {
// Do not use api as the api checks for an existing relationship.
$relationship = \CRM_Contact_BAO_Relationship::create($relationshipParams);
$relationship = \CRM_Contact_BAO_Relationship::add($relationshipParams);
$output->setParameter('id', $relationship->id);
} catch (\Exception $e) {
// Do nothing.
......
......@@ -111,6 +111,10 @@ class Provider {
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_RETRIEVAL_TAG,
));
$this->addActionWithoutFiltering('GetStateProvinceId', '\Civi\ActionProvider\Action\Contact\GetStateProvinceId', E::ts('Get state/province ID by name'), array(
AbstractAction::WITHOUT_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,
......@@ -123,10 +127,6 @@ class Provider {
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_RETRIEVAL_TAG,
));
$this->addActionWithoutFiltering('FindContactByCustomField', '\Civi\ActionProvider\Action\Contact\FindByCustomField', E::ts('Find contact by custom field'), array(
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_RETRIEVAL_TAG,
));
$this->addActionWithoutFiltering('CreateUpdateIndividual', '\Civi\ActionProvider\Action\Contact\CreateUpdateIndividual', E::ts('Create or update Individual'), array(
AbstractAction::SINGLE_CONTACT_ACTION_TAG,
AbstractAction::DATA_MANIPULATION_TAG,
......
......@@ -25,8 +25,6 @@ class CustomField {
switch ($type) {
case 'Int':
case 'ContactReference':
case 'StateProvince':
case 'Country':
$type = 'Integer';
break;
case 'File':
......
......@@ -13,8 +13,8 @@
<url desc="Documentation">https://lab.civicrm.org/jaapjansma/action-provider/wikis/home</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2019-08-29</releaseDate>
<version>1.7-dev</version>
<releaseDate>2019-08-14</releaseDate>
<version>1.6-dev</version>
<develStage>stable</develStage>
<compatibility>
<ver>4.7</ver>
......
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