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