Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Apr 26, 2017
1 parent 208d4c1 commit f1f166c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
26 changes: 19 additions & 7 deletions casetokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,14 @@ function casetokens_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) {
}

/**
* Implements hook_civicrm_tokens().
* Get the case id when loading tokens.
*
* This is hacky for now because of limitations in the token hooks.
* Ideally case_id would be passed to the hooks; instead we have to rely on _GET and _POST.
*
* @return int|null
*/
function casetokens_civicrm_tokens(&$tokens) {
function _casetokens_get_case_id() {
// Hack to get case id from the url
if (!empty($_GET['caseid'])) {
\Civi::$statics['casetokens']['case_id'] = $_GET['caseid'];
Expand All @@ -136,9 +141,17 @@ function casetokens_civicrm_tokens(&$tokens) {
preg_match('#caseid=(\d+)#', $_POST['entryURL'], $matches);
\Civi::$statics['casetokens']['case_id'] = CRM_Utils_Array::value(1, $matches);
}
if (!empty(\Civi::$statics['casetokens']['case_id'])) {
return isset(\Civi::$statics['casetokens']['case_id']) ? \Civi::$statics['casetokens']['case_id'] : NULL;
}

/**
* Implements hook_civicrm_tokens().
*/
function casetokens_civicrm_tokens(&$tokens) {
$caseId = _casetokens_get_case_id();
if ($caseId) {
$case = civicrm_api3('Case', 'getsingle', array(
'id' => \Civi::$statics['casetokens']['case_id'],
'id' => $caseId,
'return' => 'case_type_id.definition',
));
$tokens['case_roles'] = array(
Expand All @@ -161,9 +174,8 @@ function casetokens_civicrm_tokens(&$tokens) {
* Implements hook_civicrm_tokens().
*/
function casetokens_civicrm_tokenvalues(&$values, $cids, $job = NULL, $tokens = array(), $context = NULL) {
if (!empty(\Civi::$statics['casetokens']['case_id'])) {
$caseId = \Civi::$statics['casetokens']['case_id'];

$caseId = _casetokens_get_case_id();
if ($caseId) {
// Get client(s)
$caseContact = civicrm_api3('CaseContact', 'get', array(
'case_id' => $caseId,
Expand Down
11 changes: 5 additions & 6 deletions info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
<email>[email protected]</email>
</maintainer>
<urls>
<url desc="Main Extension Page">http://FIXME</url>
<url desc="Documentation">http://FIXME</url>
<url desc="Support">http://FIXME</url>
<url desc="Main Extension Page">https://civicrm.org/extensions/civicase-tokens</url>
<url desc="Development">https://github.com/civicrm/org.civicrm.casetokens</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2017-04-22</releaseDate>
<releaseDate>2017-04-26</releaseDate>
<version>1.0</version>
<develStage>alpha</develStage>
<develStage>stable</develStage>
<compatibility>
<ver>4.7</ver>
</compatibility>
<comments>This is a new, undeveloped module</comments>
<comments>Adds tokens for case client, manager and contact info for other case roles.</comments>
<civix>
<namespace>CRM/Casetokens</namespace>
</civix>
Expand Down

0 comments on commit f1f166c

Please sign in to comment.