Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
32 | */ |
33 | class CRM_Case_XMLProcessor { | |
34 | ||
4bc6c777 TO |
35 | /** |
36 | * FIXME: This does *NOT* belong in a static property, but we're too late in | |
37 | * the 4.5-cycle to do the necessary cleanup. | |
38 | * | |
041ecc95 | 39 | * Format is [int $id => string $relTypeCname]. |
40 | * | |
41 | * @var array|null | |
4bc6c777 TO |
42 | */ |
43 | public static $activityTypes = NULL; | |
44 | ||
4c6ce474 EM |
45 | /** |
46 | * @param $caseType | |
47 | * | |
48 | * @return FALSE|SimpleXMLElement | |
49 | */ | |
fa1c763d TO |
50 | public function retrieve($caseType) { |
51 | return CRM_Case_XMLRepository::singleton()->retrieve($caseType); | |
6a488035 TO |
52 | } |
53 | ||
4c6ce474 | 54 | /** |
076f81b6 | 55 | * This function was previously used to convert a case-type's |
56 | * machine-name to a file-name. However, it's mind-boggling | |
57 | * that the file-name might be a munged version of the | |
58 | * machine-name (which is itself a munged version of the | |
59 | * display-name), and naming is now a more visible issue (since | |
60 | * the overhaul of CaseType admin UI). | |
61 | * | |
62 | * Usage note: This is called externally by civix stubs as a | |
63 | * sort of side-ways validation of the case-type's name | |
64 | * (validation which was needed because of the unintuitive | |
65 | * double-munge). We should update civix templates and then | |
66 | * remove this function in Civi 4.6 or 5.0. | |
4c6ce474 | 67 | * |
076f81b6 | 68 | * @param string $caseType |
69 | * @return string | |
70 | * @deprecated | |
71 | * @see CRM_Case_BAO_CaseType::isValidName | |
4c6ce474 | 72 | */ |
6b86870e TO |
73 | public static function mungeCaseType($caseType) { |
74 | // trim all spaces from $caseType | |
75 | $caseType = str_replace('_', ' ', $caseType); | |
76 | $caseType = CRM_Utils_String::munge(ucwords($caseType), '', 0); | |
77 | return $caseType; | |
78 | } | |
79 | ||
4c6ce474 EM |
80 | /** |
81 | * @param bool $indexName | |
82 | * @param bool $all | |
83 | * | |
84 | * @return array | |
85 | */ | |
00be9182 | 86 | public function &allActivityTypes($indexName = TRUE, $all = FALSE) { |
4bc6c777 TO |
87 | if (self::$activityTypes === NULL) { |
88 | self::$activityTypes = CRM_Case_PseudoConstant::caseActivityType($indexName, $all); | |
6a488035 | 89 | } |
4bc6c777 | 90 | return self::$activityTypes; |
6a488035 TO |
91 | } |
92 | ||
4c6ce474 | 93 | /** |
d0a94888 AF |
94 | * Get all relationship type labels |
95 | * | |
96 | * TODO: These should probably be names, but under legacy behavior this has | |
97 | * been labels. | |
98 | * | |
99 | * @param bool $fromXML | |
100 | * Is this to be used for lookup of values from XML? | |
101 | * Relationships are recorded in XML from the perspective of the non-client | |
102 | * while relationships in the UI and everywhere else are from the | |
103 | * perspective of the client. Since the XML can't be expected to be | |
104 | * switched, the direction needs to be translated. | |
4c6ce474 EM |
105 | * @return array |
106 | */ | |
d0a94888 AF |
107 | public function &allRelationshipTypes($fromXML = FALSE) { |
108 | if (!isset(Civi::$statics[__CLASS__]['reltypes'][$fromXML])) { | |
4bc6c777 | 109 | $relationshipInfo = CRM_Core_PseudoConstant::relationshipType('label', TRUE); |
6a488035 | 110 | |
d0a94888 | 111 | Civi::$statics[__CLASS__]['reltypes'][$fromXML] = []; |
6a488035 | 112 | foreach ($relationshipInfo as $id => $info) { |
d0a94888 | 113 | Civi::$statics[__CLASS__]['reltypes'][$fromXML][$id . '_b_a'] = ($fromXML) ? $info['label_a_b'] : $info['label_b_a']; |
41cf58d3 | 114 | if ($info['label_b_a'] !== $info['label_a_b']) { |
d0a94888 | 115 | Civi::$statics[__CLASS__]['reltypes'][$fromXML][$id . '_a_b'] = ($fromXML) ? $info['label_b_a'] : $info['label_a_b']; |
41cf58d3 | 116 | } |
6a488035 TO |
117 | } |
118 | } | |
119 | ||
d0a94888 | 120 | return Civi::$statics[__CLASS__]['reltypes'][$fromXML]; |
4bc6c777 TO |
121 | } |
122 | ||
123 | /** | |
124 | * FIXME: This should not exist | |
125 | */ | |
126 | public static function flushStaticCaches() { | |
127 | self::$activityTypes = NULL; | |
d0a94888 | 128 | unset(Civi::$statics[__CLASS__]['reltypes']); |
6a488035 | 129 | } |
96025800 | 130 | |
6a488035 | 131 | } |