Skip to content
Snippets Groups Projects
Commit 6b44a55c authored by jaapjansma's avatar jaapjansma
Browse files

Added configuration to the event trigger to use the logged in user as the contact for the trigger.

parent 0a7fe594
No related branches found
Tags 2.39
No related merge requests found
# CHANGELOG
## Version 2.39
* Added configuration to the event trigger to use the logged in user as the contact for the trigger.
## Version 2.38
* Add cron trigger for next scheduled contribution date on recurring contribution, fixes #162
......
<?php
/**
* Copyright (C) 2021 Jaap Jansma (jaap.jansma@civicoop.org)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use CRM_Civirules_ExtensionUtil as E;
/**
* Class CRM_CivirulesPostTrigger_Event
*
* Use a custom class for event triggers because we will optionally add the logged in user
* as the contact of the trigger.
*
*/
class CRM_CivirulesPostTrigger_Event extends CRM_Civirules_Trigger_Post {
public function setTriggerParams($triggerParams) {
$this->triggerParams = unserialize($triggerParams);
}
protected function getTriggerDataFromPost($op, $objectName, $objectId, $objectRef, $eventID = NULL) {
$triggerData = parent::getTriggerDataFromPost($op, $objectName, $objectId, $objectRef, $eventID);
if (isset($this->triggerParams['contact_id']) && $this->triggerParams['contact_id'] == 1) {
$contactId = CRM_Core_Session::getLoggedInContactID();
$triggerData->setContactId($contactId);
}
return $triggerData;
}
/**
* Returns a redirect url to extra data input from the user after adding a trigger
*
* Return false if you do not need extra data input
*
* @param int $ruleId
* @return bool|string
* @access public
* @abstract
*/
public function getExtraDataInputUrl($ruleId) {
return CRM_Utils_System::url('civicrm/civirule/form/trigger/event', 'rule_id='.$ruleId);
}
/**
* Returns a description of this trigger
*
* @return string
* @access public
* @abstract
*/
public function getTriggerDescription() {
if (isset($this->triggerParams['contact_id']) && $this->triggerParams['contact_id'] == 1) {
return E::ts('Trigger uses the logged in user as the contact.');
} else {
return E::ts('Trigger does not use a contact.');
}
}
}
<?php
/**
* Copyright (C) 2021 Jaap Jansma (jaap.jansma@civicoop.org)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use CRM_Civirules_ExtensionUtil as E;
class CRM_CivirulesPostTrigger_Form_Event extends CRM_CivirulesTrigger_Form_Form {
/**
* Overridden parent method to build form
*
* @access public
*/
public function buildQuickForm() {
$this->add('hidden', 'rule_id');
$result = civicrm_api3('ActivityContact', 'getoptions', [
'field' => "record_type_id",
]);
$options[0] = E::ts('Do not use Contact ID');
$options[1] = E::ts('Set contact id to logged in contact');
$this->add('select', 'contact_id', E::ts('Contact ID'),$options, true, ['class' => 'crm-select2 huge']);
$this->addButtons(array(
array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE,),
array('type' => 'cancel', 'name' => ts('Cancel'))));
}
/**
* Overridden parent method to set default values
*
* @return array $defaultValues
* @access public
*/
public function setDefaultValues() {
$defaultValues = parent::setDefaultValues();
$data = unserialize($this->rule->trigger_params);
if ($data === false && $this->ruleId) {
$defaultValues['contact_id'] = 0;
} elseif (!empty($data['contact_id'])) {
$defaultValues['contact_id'] = $data['contact_id'];
} else {
$defaultValues['contact_id'] = 0;
}
return $defaultValues;
}
/**
* Overridden parent method to process form data after submission
*
* @throws Exception when rule condition not found
* @access public
*/
public function postProcess() {
$data['contact_id'] = $this->_submitValues['contact_id'];
$this->rule->trigger_params = serialize($data);
$this->rule->save();
parent::postProcess();
}
/**
* Returns a help text for this trigger.
* The help text is shown to the administrator who is configuring the condition.
*
* @return string
*/
protected function getHelpText() {
return E::ts('An event does not have related contacts. So you can trigger without any contact are use the logged in contact (recommended).');
}
}
......@@ -14,8 +14,8 @@
<author>CiviCooP</author>
<email>helpdesk@civicoop.org</email>
</maintainer>
<releaseDate>2021-11-10</releaseDate>
<version>2.38</version>
<releaseDate>2021-11-17</releaseDate>
<version>2.39</version>
<develStage>stable</develStage>
<compatibility>
<ver>5.28</ver>
......
......@@ -44,9 +44,9 @@
{"name":"deleted_emailaddress","label":"Email-address is deleted","object_name":"Email","op":"delete","class_name":null,"cron":"0"},
{"name":"new_entity_tag","label":"Contact is tagged (tag is added to contact)","object_name":"EntityTag","op":"create","class_name":"CRM_CivirulesPostTrigger_EntityTag","cron":"0"},
{"name":"deleted_entity_tag","label":"Contact is un-tagged (tag is removed from contact)","object_name":"EntityTag","op":"delete","class_name":"CRM_CivirulesPostTrigger_EntityTag","cron":"0"},
{"name":"new_event","label":"Event is added","object_name":"Event","op":"create","class_name":null,"cron":"0"},
{"name":"changed_event","label":"Event is changed","object_name":"Event","op":"edit","class_name":null,"cron":"0"},
{"name":"deleted_event","label":"Event is deleted","object_name":"Event","op":"delete","class_name":null,"cron":"0"},
{"name":"new_event","label":"Event is added","object_name":"Event","op":"create","class_name":"CRM_CivirulesPostTrigger_Event","cron":"0"},
{"name":"changed_event","label":"Event is changed","object_name":"Event","op":"edit","class_name":"CRM_CivirulesPostTrigger_Event","cron":"0"},
{"name":"deleted_event","label":"Event is deleted","object_name":"Event","op":"delete","class_name":"CRM_CivirulesPostTrigger_Event","cron":"0"},
{"name":"new_grant","label":"Grant is added","object_name":"Grant","op":"create","class_name":null,"cron":"0"},
{"name":"changed_grant","label":"Grant is changed","object_name":"Grant","op":"edit","class_name":null,"cron":"0"},
{"name":"deleted_grant","label":"Grant is deleted","object_name":"Grant","op":"delete","class_name":null,"cron":"0"},
......
{crmScope extensionKey='org.civicoop.civirules'}
<h3>{$ruleTriggerHeader}</h3>
<div class="crm-block crm-form-block crm-civirule-post-trigger-block-event">
<div class="help">{$ruleTriggerHelp}</div>
<div class="crm-section">
<div class="label">{$form.contact_id.label}</div>
<div class="content">{$form.contact_id.html}
</div>
<div class="clear">
</div>
</div>
</div>
<div class="crm-submit-buttons">
{include file="CRM/common/formButtons.tpl" location="bottom"}
</div>
{/crmScope}
......@@ -288,6 +288,12 @@
<title>Group membership</title>
<access_arguments>administer CiviCRM</access_arguments>
</item>
<item>
<path>civicrm/civirule/form/trigger/event</path>
<page_callback>CRM_CivirulesPostTrigger_Form_Event</page_callback>
<title>Event</title>
<access_arguments>administer CiviCRM</access_arguments>
</item>
<item>
<path>civicrm/civirule/form/trigger/activitydate</path>
<page_callback>CRM_CivirulesCronTrigger_Form_ActivityDate</page_callback>
......
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