f118d4c203beb375f6903da41b7cb4307312c99e
[civicrm-core.git] / CRM / Case / XMLProcessor.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2019
32 */
33 class CRM_Case_XMLProcessor {
34
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 *
39 * Format is [int $id => string $relTypeCname].
40 *
41 * @var array|null
42 */
43 public static $activityTypes = NULL;
44
45 /**
46 * FIXME: This does *NOT* belong in a static property, but we're too late in
47 * the 4.5-cycle to do the necessary cleanup.
48 *
49 * Format is array(int $id => string $relTypeCname).
50 *
51 * @var array|null
52 */
53 public static $relationshipTypes = NULL;
54
55 /**
56 * @param $caseType
57 *
58 * @return FALSE|SimpleXMLElement
59 */
60 public function retrieve($caseType) {
61 return CRM_Case_XMLRepository::singleton()->retrieve($caseType);
62 }
63
64 /**
65 * This function was previously used to convert a case-type's
66 * machine-name to a file-name. However, it's mind-boggling
67 * that the file-name might be a munged version of the
68 * machine-name (which is itself a munged version of the
69 * display-name), and naming is now a more visible issue (since
70 * the overhaul of CaseType admin UI).
71 *
72 * Usage note: This is called externally by civix stubs as a
73 * sort of side-ways validation of the case-type's name
74 * (validation which was needed because of the unintuitive
75 * double-munge). We should update civix templates and then
76 * remove this function in Civi 4.6 or 5.0.
77 *
78 * @param string $caseType
79 * @return string
80 * @deprecated
81 * @see CRM_Case_BAO_CaseType::isValidName
82 */
83 public static function mungeCaseType($caseType) {
84 // trim all spaces from $caseType
85 $caseType = str_replace('_', ' ', $caseType);
86 $caseType = CRM_Utils_String::munge(ucwords($caseType), '', 0);
87 return $caseType;
88 }
89
90 /**
91 * @param bool $indexName
92 * @param bool $all
93 *
94 * @return array
95 */
96 public function &allActivityTypes($indexName = TRUE, $all = FALSE) {
97 if (self::$activityTypes === NULL) {
98 self::$activityTypes = CRM_Case_PseudoConstant::caseActivityType($indexName, $all);
99 }
100 return self::$activityTypes;
101 }
102
103 /**
104 * @return array
105 */
106 public function &allRelationshipTypes() {
107 if (self::$relationshipTypes === NULL) {
108 $relationshipInfo = CRM_Core_PseudoConstant::relationshipType('label', TRUE);
109
110 self::$relationshipTypes = [];
111 foreach ($relationshipInfo as $id => $info) {
112 self::$relationshipTypes[$id . '_b_a'] = $info['label_b_a'];
113 if ($info['label_b_a'] !== $info['label_a_b']) {
114 self::$relationshipTypes[$id . '_a_b'] = $info['label_a_b'];
115 }
116 }
117 }
118
119 return self::$relationshipTypes;
120 }
121
122 /**
123 * FIXME: This should not exist
124 */
125 public static function flushStaticCaches() {
126 self::$activityTypes = NULL;
127 self::$relationshipTypes = NULL;
128 }
129
130 }