Merge pull request #19507 from eileenmcnaughton/trans
[civicrm-core.git] / CRM / Case / XMLProcessor.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17class CRM_Case_XMLProcessor {
18
4bc6c777
TO
19 /**
20 * FIXME: This does *NOT* belong in a static property, but we're too late in
21 * the 4.5-cycle to do the necessary cleanup.
22 *
041ecc95 23 * Format is [int $id => string $relTypeCname].
24 *
25 * @var array|null
4bc6c777
TO
26 */
27 public static $activityTypes = NULL;
28
4c6ce474
EM
29 /**
30 * @param $caseType
31 *
32 * @return FALSE|SimpleXMLElement
33 */
fa1c763d
TO
34 public function retrieve($caseType) {
35 return CRM_Case_XMLRepository::singleton()->retrieve($caseType);
6a488035
TO
36 }
37
4c6ce474 38 /**
076f81b6 39 * This function was previously used to convert a case-type's
40 * machine-name to a file-name. However, it's mind-boggling
41 * that the file-name might be a munged version of the
42 * machine-name (which is itself a munged version of the
43 * display-name), and naming is now a more visible issue (since
44 * the overhaul of CaseType admin UI).
45 *
46 * Usage note: This is called externally by civix stubs as a
47 * sort of side-ways validation of the case-type's name
48 * (validation which was needed because of the unintuitive
49 * double-munge). We should update civix templates and then
50 * remove this function in Civi 4.6 or 5.0.
4c6ce474 51 *
076f81b6 52 * @param string $caseType
53 * @return string
54 * @deprecated
55 * @see CRM_Case_BAO_CaseType::isValidName
4c6ce474 56 */
6b86870e
TO
57 public static function mungeCaseType($caseType) {
58 // trim all spaces from $caseType
59 $caseType = str_replace('_', ' ', $caseType);
60 $caseType = CRM_Utils_String::munge(ucwords($caseType), '', 0);
61 return $caseType;
62 }
63
4c6ce474 64 /**
821f520b 65 * @deprecated
66 *
4c6ce474
EM
67 * @param bool $indexName
68 * @param bool $all
69 *
70 * @return array
71 */
a6fb2325 72 public static function &allActivityTypes($indexName = TRUE, $all = FALSE) {
821f520b 73 CRM_Core_Error::deprecatedFunctionWarning('CRM_Case_PseudoConstant::caseActivityType');
4bc6c777
TO
74 if (self::$activityTypes === NULL) {
75 self::$activityTypes = CRM_Case_PseudoConstant::caseActivityType($indexName, $all);
6a488035 76 }
4bc6c777 77 return self::$activityTypes;
6a488035
TO
78 }
79
4c6ce474 80 /**
2058bf54 81 * Get all relationship type display labels (not machine names)
d0a94888
AF
82 *
83 * @param bool $fromXML
2058bf54 84 * TODO: This parameter is always FALSE now so no longer needed.
d0a94888
AF
85 * Is this to be used for lookup of values from XML?
86 * Relationships are recorded in XML from the perspective of the non-client
87 * while relationships in the UI and everywhere else are from the
88 * perspective of the client. Since the XML can't be expected to be
89 * switched, the direction needs to be translated.
4c6ce474
EM
90 * @return array
91 */
d0a94888
AF
92 public function &allRelationshipTypes($fromXML = FALSE) {
93 if (!isset(Civi::$statics[__CLASS__]['reltypes'][$fromXML])) {
2058bf54
D
94 // Note this now includes disabled types too. The only place this
95 // function is being used is for comparison against a list, not
96 // displaying a dropdown list or something like that, so we need
97 // to include disabled.
98 $relationshipInfo = civicrm_api3('RelationshipType', 'get', [
99 'options' => ['limit' => 0],
100 ]);
6a488035 101
d0a94888 102 Civi::$statics[__CLASS__]['reltypes'][$fromXML] = [];
2058bf54 103 foreach ($relationshipInfo['values'] as $id => $info) {
d0a94888 104 Civi::$statics[__CLASS__]['reltypes'][$fromXML][$id . '_b_a'] = ($fromXML) ? $info['label_a_b'] : $info['label_b_a'];
2058bf54
D
105 /**
106 * Exclude if bidirectional
107 * (Why? I'm thinking this was for consistency with the dropdown
108 * in ang/crmCaseType.js where it would be needed to avoid seeing
109 * duplicates in the dropdown. Not sure if needed here but keeping
110 * as-is.)
111 */
41cf58d3 112 if ($info['label_b_a'] !== $info['label_a_b']) {
d0a94888 113 Civi::$statics[__CLASS__]['reltypes'][$fromXML][$id . '_a_b'] = ($fromXML) ? $info['label_b_a'] : $info['label_a_b'];
41cf58d3 114 }
6a488035
TO
115 }
116 }
117
d0a94888 118 return Civi::$statics[__CLASS__]['reltypes'][$fromXML];
4bc6c777
TO
119 }
120
121 /**
122 * FIXME: This should not exist
123 */
124 public static function flushStaticCaches() {
125 self::$activityTypes = NULL;
d0a94888 126 unset(Civi::$statics[__CLASS__]['reltypes']);
6a488035 127 }
96025800 128
6a488035 129}