Skip to content

Commit

Permalink
CIVIMM-261: Support automatic email filing for case type categories o…
Browse files Browse the repository at this point in the history
…ther than cases
  • Loading branch information
Muhammad Shahrukh committed Jan 16, 2025
1 parent 9230a07 commit 2e6f20b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 80 deletions.

This file was deleted.

60 changes: 60 additions & 0 deletions CRM/Civicase/Hook/alterMailParams/SubjectProcessor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

use CRM_Civicase_Helper_CaseCategory as CaseCategoryHelper;

/**
* Class CRM_Civicase_Hook_alterMailParams_SubjectProcessor.
*/
class CRM_Civicase_Hook_alterMailParams_SubjectProcessor {

/**
* A substring of email subject that should be removed.
*
* @var string
* This substring will be removed.
*/
private $toRemove = '[case ';

/**
* Email subject processor.
*
* Remove word 'case' in email subject.
*
* @param array $params
* Mail parameters.
* @param string $context
* Mail context.
*/
public function run(array &$params, $context) {
$caseId = CRM_Utils_Request::retrieve('caseid', 'Integer');
if (!$this->shouldRun($params, $context, $caseId)) {
return;
}

// Make sure we make just 1 replacement.
$subject = explode($this->toRemove, $params['subject'], 2);
$params['subject'] = '[' . $subject[1];
}

/**
* Determines if the hook will run.
*
* @param array $params
* Mail parameters.
* @param string $context
* Mail context.
* @param int $caseId
* Case id.
*
* @return bool
* returns TRUE if hook should run, FALSE otherwise.
*/
private function shouldRun(array $params, $context, $caseId) {
if (empty($params['subject'])) {
return FALSE;
}
// If case id is set and email subject starts with '[case '.
return $caseId && strpos($params['subject'], $this->toRemove) === 0;
}

}
7 changes: 6 additions & 1 deletion civicase.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ function _civicase_add_case_category_case_type_entity(array &$entityTypes) {
*/
function civicase_civicrm_alterMailParams(&$params, $context) {
$hooks = [
new CRM_Civicase_Hook_alterMailParams_SubjectCaseTypeCategoryProcessor(),
new CRM_Civicase_Hook_alterMailParams_SubjectProcessor(),
new CRM_Civicase_Hook_alterMailParams_AttachQuotation(),
];

Expand Down Expand Up @@ -660,3 +660,8 @@ function civicase_civicrm_alterContent(&$content, $context, $tplName, &$object)
$hook->run();
}
}

function civicase_civicrm_caseEmailSubjectPatterns(&$subjectPatterns) {
$subjectPatterns[] = '/\[[a-z0-9\s]*#([0-9a-f]{7})\]/i';
$subjectPatterns[] = '/\[[a-z0-9\s]*#(\d+)\]/i';
}

0 comments on commit 2e6f20b

Please sign in to comment.