Commit | Line | Data |
---|---|---|
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 | */ |
17 | class 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 EM |
64 | /** |
65 | * @param bool $indexName | |
66 | * @param bool $all | |
67 | * | |
68 | * @return array | |
69 | */ | |
a6fb2325 | 70 | public static function &allActivityTypes($indexName = TRUE, $all = FALSE) { |
4bc6c777 TO |
71 | if (self::$activityTypes === NULL) { |
72 | self::$activityTypes = CRM_Case_PseudoConstant::caseActivityType($indexName, $all); | |
6a488035 | 73 | } |
4bc6c777 | 74 | return self::$activityTypes; |
6a488035 TO |
75 | } |
76 | ||
4c6ce474 | 77 | /** |
2058bf54 | 78 | * Get all relationship type display labels (not machine names) |
d0a94888 AF |
79 | * |
80 | * @param bool $fromXML | |
2058bf54 | 81 | * TODO: This parameter is always FALSE now so no longer needed. |
d0a94888 AF |
82 | * Is this to be used for lookup of values from XML? |
83 | * Relationships are recorded in XML from the perspective of the non-client | |
84 | * while relationships in the UI and everywhere else are from the | |
85 | * perspective of the client. Since the XML can't be expected to be | |
86 | * switched, the direction needs to be translated. | |
4c6ce474 EM |
87 | * @return array |
88 | */ | |
d0a94888 AF |
89 | public function &allRelationshipTypes($fromXML = FALSE) { |
90 | if (!isset(Civi::$statics[__CLASS__]['reltypes'][$fromXML])) { | |
2058bf54 D |
91 | // Note this now includes disabled types too. The only place this |
92 | // function is being used is for comparison against a list, not | |
93 | // displaying a dropdown list or something like that, so we need | |
94 | // to include disabled. | |
95 | $relationshipInfo = civicrm_api3('RelationshipType', 'get', [ | |
96 | 'options' => ['limit' => 0], | |
97 | ]); | |
6a488035 | 98 | |
d0a94888 | 99 | Civi::$statics[__CLASS__]['reltypes'][$fromXML] = []; |
2058bf54 | 100 | foreach ($relationshipInfo['values'] as $id => $info) { |
d0a94888 | 101 | Civi::$statics[__CLASS__]['reltypes'][$fromXML][$id . '_b_a'] = ($fromXML) ? $info['label_a_b'] : $info['label_b_a']; |
2058bf54 D |
102 | /** |
103 | * Exclude if bidirectional | |
104 | * (Why? I'm thinking this was for consistency with the dropdown | |
105 | * in ang/crmCaseType.js where it would be needed to avoid seeing | |
106 | * duplicates in the dropdown. Not sure if needed here but keeping | |
107 | * as-is.) | |
108 | */ | |
41cf58d3 | 109 | if ($info['label_b_a'] !== $info['label_a_b']) { |
d0a94888 | 110 | Civi::$statics[__CLASS__]['reltypes'][$fromXML][$id . '_a_b'] = ($fromXML) ? $info['label_b_a'] : $info['label_a_b']; |
41cf58d3 | 111 | } |
6a488035 TO |
112 | } |
113 | } | |
114 | ||
d0a94888 | 115 | return Civi::$statics[__CLASS__]['reltypes'][$fromXML]; |
4bc6c777 TO |
116 | } |
117 | ||
118 | /** | |
119 | * FIXME: This should not exist | |
120 | */ | |
121 | public static function flushStaticCaches() { | |
122 | self::$activityTypes = NULL; | |
d0a94888 | 123 | unset(Civi::$statics[__CLASS__]['reltypes']); |
6a488035 | 124 | } |
96025800 | 125 | |
6a488035 | 126 | } |