Merge pull request #3653 from totten/master-case-failures
[civicrm-core.git] / CRM / Case / XMLProcessor.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
06b69b18 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
06b69b18 31 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
32 * $Id$
33 *
34 */
35class CRM_Case_XMLProcessor {
36
168f458e
TO
37 /**
38 * Relationship-types have four name fields (name_a_b, name_b_a, label_a_b,
39 * label_b_a), but CiviCase XML refers to reltypes by a single name.
40 * REL_TYPE_CNAME identifies the canonical name field as used by CiviCase XML.
41 *
42 * This appears to be "label_b_a", but IMHO "name_b_a" would be more
43 * sensible.
44 */
45 const REL_TYPE_CNAME = 'label_b_a';
46
4c6ce474
EM
47 /**
48 * @param $caseType
49 *
50 * @return FALSE|SimpleXMLElement
51 */
fa1c763d
TO
52 public function retrieve($caseType) {
53 return CRM_Case_XMLRepository::singleton()->retrieve($caseType);
6a488035
TO
54 }
55
4c6ce474 56 /**
076f81b6 57 * This function was previously used to convert a case-type's
58 * machine-name to a file-name. However, it's mind-boggling
59 * that the file-name might be a munged version of the
60 * machine-name (which is itself a munged version of the
61 * display-name), and naming is now a more visible issue (since
62 * the overhaul of CaseType admin UI).
63 *
64 * Usage note: This is called externally by civix stubs as a
65 * sort of side-ways validation of the case-type's name
66 * (validation which was needed because of the unintuitive
67 * double-munge). We should update civix templates and then
68 * remove this function in Civi 4.6 or 5.0.
4c6ce474 69 *
076f81b6 70 * @param string $caseType
71 * @return string
72 * @deprecated
73 * @see CRM_Case_BAO_CaseType::isValidName
4c6ce474 74 */
6b86870e
TO
75 public static function mungeCaseType($caseType) {
76 // trim all spaces from $caseType
77 $caseType = str_replace('_', ' ', $caseType);
78 $caseType = CRM_Utils_String::munge(ucwords($caseType), '', 0);
79 return $caseType;
80 }
81
4c6ce474
EM
82 /**
83 * @param bool $indexName
84 * @param bool $all
85 *
86 * @return array
87 */
6a488035
TO
88 function &allActivityTypes($indexName = TRUE, $all = FALSE) {
89 static $activityTypes = NULL;
90 if (!$activityTypes) {
91 $activityTypes = CRM_Case_PseudoConstant::caseActivityType($indexName, $all);
92 }
93 return $activityTypes;
94 }
95
4c6ce474
EM
96 /**
97 * @return array
98 */
6a488035
TO
99 function &allRelationshipTypes() {
100 static $relationshipTypes = array();
101
102 if (!$relationshipTypes) {
103 $relationshipInfo = CRM_Core_PseudoConstant::relationshipType();
104
105 $relationshipTypes = array();
106 foreach ($relationshipInfo as $id => $info) {
168f458e 107 $relationshipTypes[$id] = $info[CRM_Case_XMLProcessor::REL_TYPE_CNAME];
6a488035
TO
108 }
109 }
110
111 return $relationshipTypes;
112 }
113}
114