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 | * | |
39 | * @var array|null array(int $id => string $relTypeCname) | |
40 | */ | |
41 | public static $activityTypes = NULL; | |
42 | ||
43 | /** | |
44 | * FIXME: This does *NOT* belong in a static property, but we're too late in | |
45 | * the 4.5-cycle to do the necessary cleanup. | |
46 | * | |
47 | * @var array|null array(int $id => string $relTypeCname) | |
48 | */ | |
49 | public static $relationshipTypes = NULL; | |
50 | ||
168f458e TO |
51 | /** |
52 | * Relationship-types have four name fields (name_a_b, name_b_a, label_a_b, | |
53 | * label_b_a), but CiviCase XML refers to reltypes by a single name. | |
54 | * REL_TYPE_CNAME identifies the canonical name field as used by CiviCase XML. | |
55 | * | |
56 | * This appears to be "label_b_a", but IMHO "name_b_a" would be more | |
57 | * sensible. | |
58 | */ | |
59 | const REL_TYPE_CNAME = 'label_b_a'; | |
60 | ||
4c6ce474 EM |
61 | /** |
62 | * @param $caseType | |
63 | * | |
64 | * @return FALSE|SimpleXMLElement | |
65 | */ | |
fa1c763d TO |
66 | public function retrieve($caseType) { |
67 | return CRM_Case_XMLRepository::singleton()->retrieve($caseType); | |
6a488035 TO |
68 | } |
69 | ||
4c6ce474 | 70 | /** |
076f81b6 | 71 | * This function was previously used to convert a case-type's |
72 | * machine-name to a file-name. However, it's mind-boggling | |
73 | * that the file-name might be a munged version of the | |
74 | * machine-name (which is itself a munged version of the | |
75 | * display-name), and naming is now a more visible issue (since | |
76 | * the overhaul of CaseType admin UI). | |
77 | * | |
78 | * Usage note: This is called externally by civix stubs as a | |
79 | * sort of side-ways validation of the case-type's name | |
80 | * (validation which was needed because of the unintuitive | |
81 | * double-munge). We should update civix templates and then | |
82 | * remove this function in Civi 4.6 or 5.0. | |
4c6ce474 | 83 | * |
076f81b6 | 84 | * @param string $caseType |
85 | * @return string | |
86 | * @deprecated | |
87 | * @see CRM_Case_BAO_CaseType::isValidName | |
4c6ce474 | 88 | */ |
6b86870e TO |
89 | public static function mungeCaseType($caseType) { |
90 | // trim all spaces from $caseType | |
91 | $caseType = str_replace('_', ' ', $caseType); | |
92 | $caseType = CRM_Utils_String::munge(ucwords($caseType), '', 0); | |
93 | return $caseType; | |
94 | } | |
95 | ||
4c6ce474 EM |
96 | /** |
97 | * @param bool $indexName | |
98 | * @param bool $all | |
99 | * | |
100 | * @return array | |
101 | */ | |
00be9182 | 102 | public function &allActivityTypes($indexName = TRUE, $all = FALSE) { |
4bc6c777 TO |
103 | if (self::$activityTypes === NULL) { |
104 | self::$activityTypes = CRM_Case_PseudoConstant::caseActivityType($indexName, $all); | |
6a488035 | 105 | } |
4bc6c777 | 106 | return self::$activityTypes; |
6a488035 TO |
107 | } |
108 | ||
4c6ce474 EM |
109 | /** |
110 | * @return array | |
111 | */ | |
00be9182 | 112 | public function &allRelationshipTypes() { |
4bc6c777 TO |
113 | if (self::$relationshipTypes === NULL) { |
114 | $relationshipInfo = CRM_Core_PseudoConstant::relationshipType('label', TRUE); | |
6a488035 | 115 | |
4bc6c777 | 116 | self::$relationshipTypes = array(); |
6a488035 | 117 | foreach ($relationshipInfo as $id => $info) { |
4bc6c777 | 118 | self::$relationshipTypes[$id] = $info[CRM_Case_XMLProcessor::REL_TYPE_CNAME]; |
6a488035 TO |
119 | } |
120 | } | |
121 | ||
4bc6c777 TO |
122 | return self::$relationshipTypes; |
123 | } | |
124 | ||
125 | /** | |
126 | * FIXME: This should not exist | |
127 | */ | |
128 | public static function flushStaticCaches() { | |
129 | self::$activityTypes = NULL; | |
130 | self::$relationshipTypes = NULL; | |
6a488035 | 131 | } |
96025800 | 132 | |
6a488035 | 133 | } |