Skip to content
Snippets Groups Projects
Commit 61fc8dea authored by Jaap Jansma's avatar Jaap Jansma
Browse files

Merge pull request #84 from jaapjansma/issue_83

Fixed issue #83 added trigger data for relationships
parents 1d11255c b67a73e9
No related branches found
No related tags found
No related merge requests found
......@@ -12,8 +12,6 @@ class CRM_Civirules_TriggerData_Post extends CRM_Civirules_TriggerData_TriggerDa
$this->setEntityData($entity, $data);
if ($entity == 'contact') {
$this->contact_id = $objectId;
} elseif (strtolower($entity) == 'relationship' && isset($data['contact_id_a'])) {
$this->contact_id = $data['contact_id_a'];
} elseif (isset($data['contact_id'])) {
$this->contact_id = $data['contact_id'];
}
......
......@@ -93,4 +93,15 @@ class CRM_Civirules_Upgrader extends CRM_Civirules_Upgrader_Base {
CRM_Core_DAO::executeQuery("update `civirule_trigger` SET `class_name` = 'CRM_CivirulesPostTrigger_Case' where `object_name` = 'Case'");
return true;
}
/**
* Update for a trigger class for relationships
*
* See https://github.com/CiviCooP/org.civicoop.civirules/issues/83
* @return bool
*/
public function upgrade_1006() {
CRM_Core_DAO::executeQuery("update `civirule_trigger` SET `class_name` = 'CRM_CivirulesPostTrigger_Relationship' where `object_name` = 'Relationship'");
return true;
}
}
\ No newline at end of file
<?php
/**
* @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org>
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/
return array (
0 =>
array (
'name' => 'Civirules:Condition.RelationshipIsContactA',
'entity' => 'CiviRuleCondition',
'params' =>
array (
'version' => 3,
'name' => 'relationship_is_contact_a',
'label' => 'Relationship is contact a',
'class_name' => 'CRM_CivirulesConditions_Relationship_IsContactA',
'is_active' => 1
),
),
1 =>
array (
'name' => 'Civirules:Condition.RelationshipIsContactB',
'entity' => 'CiviRuleCondition',
'params' =>
array (
'version' => 3,
'name' => 'relationship_is_contact_b',
'label' => 'Relationship is contact b',
'class_name' => 'CRM_CivirulesConditions_Relationship_IsContactB',
'is_active' => 1
),
),
);
\ No newline at end of file
<?php
/**
* @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org>
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/
class CRM_CivirulesConditions_Relationship_IsContactA extends CRM_Civirules_Condition {
/**
* Method to determine if the condition is valid
*
* @param CRM_Civirules_TriggerData_TriggerData $triggerData
* @return bool
*/
public function isConditionValid(CRM_Civirules_TriggerData_TriggerData $triggerData) {
$relationship = $triggerData->getEntityData('Relationship');
if (!empty($relationship) && !empty($relationship['contact_id_a']) && $relationship['contact_id_a'] == $triggerData->getContactId()) {
return true;
}
return false;
}
/**
* Returns a redirect url to extra data input from the user after adding a condition
*
* Return false if you do not need extra data input
*
* @param int $ruleConditionId
* @return bool|string
* @access public
* @abstract
*/
public function getExtraDataInputUrl($ruleConditionId) {
return false;
}
/**
* Returns an array with required entity names
*
* @return array
* @access public
*/
public function requiredEntities() {
return array('Relationship');
}
}
\ No newline at end of file
<?php
/**
* @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org>
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/
class CRM_CivirulesConditions_Relationship_IsContactB extends CRM_Civirules_Condition {
/**
* Method to determine if the condition is valid
*
* @param CRM_Civirules_TriggerData_TriggerData $triggerData
* @return bool
*/
public function isConditionValid(CRM_Civirules_TriggerData_TriggerData $triggerData) {
$relationship = $triggerData->getEntityData('Relationship');
if (!empty($relationship) && !empty($relationship['contact_id_b']) && $relationship['contact_id_b'] == $triggerData->getContactId()) {
return true;
}
return false;
}
/**
* Returns a redirect url to extra data input from the user after adding a condition
*
* Return false if you do not need extra data input
*
* @param int $ruleConditionId
* @return bool|string
* @access public
* @abstract
*/
public function getExtraDataInputUrl($ruleConditionId) {
return false;
}
/**
* Returns an array with required entity names
*
* @return array
* @access public
*/
public function requiredEntities() {
return array('Relationship');
}
}
\ No newline at end of file
<?php
/**
* @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org>
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/
class CRM_CivirulesPostTrigger_Relationship extends CRM_Civirules_Trigger_Post {
/**
* Returns an array of entities on which the trigger reacts
*
* @return CRM_Civirules_TriggerData_EntityDefinition
*/
protected function reactOnEntity() {
return new CRM_Civirules_TriggerData_EntityDefinition($this->objectName, $this->objectName, $this->getDaoClassName(), 'Relationship');
}
/**
* Return the name of the DAO Class. If a dao class does not exist return an empty value
*
* @return string
*/
protected function getDaoClassName() {
return 'CRM_Contact_DAO_Relationship';
}
/**
* Trigger a rule for this trigger
*
* @param $op
* @param $objectName
* @param $objectId
* @param $objectRef
*/
public function triggerTrigger($op, $objectName, $objectId, $objectRef) {
$t = $this->getTriggerDataFromPost($op, $objectName, $objectId, $objectRef);
$relationship = $t->getEntityData('Relationship');
if (!empty($relationship['contact_id_a'])) {
$triggerData = clone $t;
$triggerData->setContactId($relationship['contact_id_a']);
CRM_Civirules_Engine::triggerRule($this, $triggerData);
}
if (!empty($relationship['contact_id_b'])) {
$triggerData = clone $t;
$triggerData->setContactId($relationship['contact_id_b']);
CRM_Civirules_Engine::triggerRule($this, $triggerData);
}
}
}
\ No newline at end of file
......@@ -78,9 +78,9 @@ VALUES
('new_pledge_payment', 'Pledge Payment is added', 'PledgePayment', 'create', null, CURDATE(), 1),
('changed_pledge_payment', 'Pledge Payment is changed', 'PledgePayment', 'edit', null, CURDATE(), 1),
('deleted_pledge_payment', 'Pledge Payment is deleted', 'PledgePayment', 'delete', null, CURDATE(), 1),
('new_relationship', 'Relationship is added', 'Relationship', 'create', null, CURDATE(), 1),
('changed_relationship', 'Relationship is changed', 'Relationship', 'edit', null, CURDATE(), 1),
('deleted_relationship', 'Relationship is deleted', 'Relationship', 'delete', null, CURDATE(), 1),
('new_relationship', 'Relationship is added', 'Relationship', 'create', 'CRM_CivirulesPostTrigger_Relationship', CURDATE(), 1),
('changed_relationship', 'Relationship is changed', 'Relationship', 'edit', 'CRM_CivirulesPostTrigger_Relationship', CURDATE(), 1),
('deleted_relationship', 'Relationship is deleted', 'Relationship', 'delete', 'CRM_CivirulesPostTrigger_Relationship', CURDATE(), 1),
('new_tag', 'Tag is added', 'Tag', 'create', null, CURDATE(), 1),
('changed_tag', 'Tag is changed', 'Tag', 'edit', null, CURDATE(), 1),
('deleted_tag', 'Tag is deleted', 'Tag', 'delete', null, CURDATE(), 1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment