Commit d3f12ce6 authored by jaapjansma's avatar jaapjansma

added conditions and create relationship does not check for existing relationships.

parent 2efbfde4
......@@ -13,6 +13,7 @@ use \Civi\ActionProvider\Parameter\Specification;
use \Civi\ActionProvider\Utils\CustomField;
use CRM_ActionProvider_ExtensionUtil as E;
use Dompdf\Exception;
class CreateRelationship extends AbstractAction {
......@@ -105,7 +106,6 @@ class CreateRelationship extends AbstractAction {
$relationshipParams['start_date'] = $today->format('Ymd');
}
foreach($this->getParameterSpecification() as $spec) {
if (stripos($spec->getName(), 'custom_')!==0) {
continue;
......@@ -116,9 +116,9 @@ class CreateRelationship extends AbstractAction {
}
try {
var_dump($relationshipParams);
$result = civicrm_api3('Relationship', 'create', $relationshipParams);
$output->setParameter('id', $result['id']);
// Do not use api as the api checks for an existing relationship.
$relationship = \CRM_Contact_BAO_Relationship::add($relationshipParams);
$output->setParameter('id', $relationship->id);
} catch (\Exception $e) {
// Do nothing.
}
......
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
namespace Civi\ActionProvider\Condition;
use \Civi\ActionProvider\Parameter\ParameterBagInterface;
use \Civi\ActionProvider\Parameter\ParameterBag;
use Civi\ActionProvider\Parameter\Specification;
use \Civi\ActionProvider\Parameter\SpecificationBag;
use CRM_ActionProvider_ExtensionUtil as E;
class ParameterHasValue extends AbstractCondition {
/**
* @param \Civi\ActionProvider\Parameter\ParameterBagInterface $parameterBag
*
* @return bool
*/
public function isConditionValid(ParameterBagInterface $parameterBag) {
$parameter = $parameterBag->getParameter('parameter');
$value = $this->configuration->getParameter('value');
if ($parameter == $value) {
return true;
}
return false;
}
/**
* Returns the specification of the configuration options for the actual condition.
*
* @return SpecificationBag
*/
public function getConfigurationSpecification() {
return new SpecificationBag(array(
new Specification('value', 'String', E::ts('Value'), true)
));
}
/**
* Returns the specification of the parameters of the actual condition.
*
* @return SpecificationBag
*/
public function getParameterSpecification() {
return new SpecificationBag(array(
new Specification('parameter', 'String', E::ts('Parameter')),
));
}
/**
* Returns the human readable title of this condition
*/
public function getTitle() {
return E::ts('Parameter has value');
}
}
\ No newline at end of file
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
namespace Civi\ActionProvider\Condition;
use \Civi\ActionProvider\Parameter\ParameterBagInterface;
use \Civi\ActionProvider\Parameter\ParameterBag;
use Civi\ActionProvider\Parameter\Specification;
use \Civi\ActionProvider\Parameter\SpecificationBag;
use CRM_ActionProvider_ExtensionUtil as E;
class ParameterIsNotEmpty extends AbstractCondition {
/**
* @param \Civi\ActionProvider\Parameter\ParameterBagInterface $parameterBag
*
* @return bool
*/
public function isConditionValid(ParameterBagInterface $parameterBag) {
$parameter = $parameterBag->getParameter('parameter');
if (empty($parameter)) {
return false;
}
return true;
}
/**
* Returns the specification of the configuration options for the actual condition.
*
* @return SpecificationBag
*/
public function getConfigurationSpecification() {
return new SpecificationBag();
}
/**
* Returns the specification of the parameters of the actual condition.
*
* @return SpecificationBag
*/
public function getParameterSpecification() {
return new SpecificationBag(array(
new Specification('parameter', 'String', E::ts('Parameter')),
));
}
/**
* Returns the human readable title of this condition
*/
public function getTitle() {
return E::ts('Parameter is not empty');
}
}
\ No newline at end of file
......@@ -57,6 +57,8 @@ class Provider {
$conditions = array(
new \Civi\ActionProvider\Condition\ParameterIsEmpty(),
new \Civi\ActionProvider\Condition\ParameterIsNotEmpty(),
new \Civi\ActionProvider\Condition\ParameterHasValue(),
);
foreach($actions as $action) {
......
......@@ -31,7 +31,7 @@
type="text"
crm-ui-id="{{spec.name}}"
name="{{spec.name}}"
ng-model="configuration[spec.name]"
ng-model="action.condition_configuration.configuration[spec.name]"
class="big crm-form-text"
ng-required="spec.required"
/>
......
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