Skip to content
Snippets Groups Projects
Commit 02a1d4bf authored by jaapjansma's avatar jaapjansma
Browse files

Updated the Case Status change action. When a case status is set to a closed...

Updated the Case Status change action. When a case status is set to a closed case status also end the case roles.
parent 47613f4e
No related branches found
No related tags found
No related merge requests found
<?php
class CRM_CivirulesActions_Case_SetStatus extends CRM_CivirulesActions_Generic_Api {
class CRM_CivirulesActions_Case_SetStatus extends CRM_Civirules_Action {
/**
* Method to get the api action to process in this CiviRule action
* Process the action
*
* @param CRM_Civirules_TriggerData_TriggerData $triggerData
* @access public
*/
protected function getApiEntity() {
return 'Case';
}
public function processAction(CRM_Civirules_TriggerData_TriggerData $triggerData) {
$case = $triggerData->getEntityData("Case");
$params = $this->getActionParameters();
$params['id'] = $case['id'];
$caseStatusOptionGroupId = civicrm_api3('OptionGroup', 'getvalue', array('name' => 'case_status', 'return' => 'id'));
$grouping = civicrm_api3('OptionValue', 'getvalue', array('value' => $params['status_id'], 'option_group_id' => $caseStatusOptionGroupId, 'return' => 'grouping'));
// Set case end_date if we're closing the case. Clear end_date if we're (re)opening it.
if ($grouping=='Closed') {
if (empty($case['end_date'])) {
$endDate = new DateTime();
$params['end_date'] = $endDate->format('Ymd');
// Update the case roles
$relQuery = 'UPDATE civicrm_relationship SET end_date=%2 WHERE case_id=%1 AND end_date IS NOT NULL';
$relParams = array(
1 => array($case['id'], 'Integer'),
2 => array($params['end_date'], 'Timestamp'),
);
CRM_Core_DAO::executeQuery($relQuery, $relParams);
}
} else {
$params['end_date'] = '';
/**
* Method to get the api action to process in this CiviRule action
*/
protected function getApiAction() {
return 'create';
}
// Update the case roles
$relQuery = 'UPDATE civicrm_relationship SET end_date=NULL WHERE case_id=%1';
$relParams = array(
1 => array($case['id'], 'Integer'),
);
CRM_Core_DAO::executeQuery($relQuery, $relParams);
}
//execute the action
$this->executeApiAction('Case', 'create', $params);
}
/**
* Returns an array with parameters used for processing an action
* Executes the action
*
* This method could be overridden if needed
*
* @param $entity
* @param $action
* @param $parameters
* @access protected
* @throws Exception on api error
*/
protected function alterApiParameters($parameters, CRM_Civirules_TriggerData_TriggerData $triggerData) {
$case = $triggerData->getEntityData("Case");
$parameters['id'] = $case['id'];
return $parameters;
protected function executeApiAction($entity, $action, $parameters) {
try {
civicrm_api3($entity, $action, $parameters);
} catch (Exception $e) {
echo $e->getMessage(); exit();
$formattedParams = '';
foreach($parameters as $key => $param) {
if (strlen($formattedParams)) {
$formattedParams .= ', ';
}
$formattedParams .= $key.' = '.$param;
}
throw new Exception('Civirules api action exception '.$entity.'.'.$action.' ('.$formattedParams.')');
}
}
/**
* Returns a redirect url to extra data input from the user after adding a action
*
......
......@@ -14,8 +14,8 @@
<author>CiviCooP</author>
<email>helpdesk@civicoop.org</email>
</maintainer>
<releaseDate>2016-12-18</releaseDate>
<version>1.10</version>
<releaseDate>2017-01-31</releaseDate>
<version>1.11</version>
<develStage>stable</develStage>
<compatibility>
<ver>4.4</ver>
......
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