Merge pull request #19380 from civicrm/5.34
[civicrm-core.git] / CRM / Case / XMLProcessor.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17 class CRM_Case_XMLProcessor {
18
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 *
23 * Format is [int $id => string $relTypeCname].
24 *
25 * @var array|null
26 */
27 public static $activityTypes = NULL;
28
29 /**
30 * @param $caseType
31 *
32 * @return FALSE|SimpleXMLElement
33 */
34 public function retrieve($caseType) {
35 return CRM_Case_XMLRepository::singleton()->retrieve($caseType);
36 }
37
38 /**
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.
51 *
52 * @param string $caseType
53 * @return string
54 * @deprecated
55 * @see CRM_Case_BAO_CaseType::isValidName
56 */
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
64 /**
65 * @deprecated
66 *
67 * @param bool $indexName
68 * @param bool $all
69 *
70 * @return array
71 */
72 public static function &allActivityTypes($indexName = TRUE, $all = FALSE) {
73 CRM_Core_Error::deprecatedFunctionWarning('CRM_Case_PseudoConstant::caseActivityType');
74 if (self::$activityTypes === NULL) {
75 self::$activityTypes = CRM_Case_PseudoConstant::caseActivityType($indexName, $all);
76 }
77 return self::$activityTypes;
78 }
79
80 /**
81 * Get all relationship type display labels (not machine names)
82 *
83 * @param bool $fromXML
84 * TODO: This parameter is always FALSE now so no longer needed.
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.
90 * @return array
91 */
92 public function &allRelationshipTypes($fromXML = FALSE) {
93 if (!isset(Civi::$statics[__CLASS__]['reltypes'][$fromXML])) {
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 ]);
101
102 Civi::$statics[__CLASS__]['reltypes'][$fromXML] = [];
103 foreach ($relationshipInfo['values'] as $id => $info) {
104 Civi::$statics[__CLASS__]['reltypes'][$fromXML][$id . '_b_a'] = ($fromXML) ? $info['label_a_b'] : $info['label_b_a'];
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 */
112 if ($info['label_b_a'] !== $info['label_a_b']) {
113 Civi::$statics[__CLASS__]['reltypes'][$fromXML][$id . '_a_b'] = ($fromXML) ? $info['label_b_a'] : $info['label_a_b'];
114 }
115 }
116 }
117
118 return Civi::$statics[__CLASS__]['reltypes'][$fromXML];
119 }
120
121 /**
122 * FIXME: This should not exist
123 */
124 public static function flushStaticCaches() {
125 self::$activityTypes = NULL;
126 unset(Civi::$statics[__CLASS__]['reltypes']);
127 }
128
129 }