copyright and version fixes
[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
37 static protected $_xml;
38
6b86870e
TO
39 static protected $_hookCache = NULL;
40
6a488035 41 function retrieve($caseType) {
6b86870e 42 $caseType = self::mungeCaseType($caseType);
6a488035
TO
43
44 if (!CRM_Utils_Array::value($caseType, self::$_xml)) {
45 if (!self::$_xml) {
46 self::$_xml = array();
47 }
48
49 // first check custom templates directory
50 $fileName = NULL;
51 $config = CRM_Core_Config::singleton();
52 if (isset($config->customTemplateDir) &&
53 $config->customTemplateDir
54 ) {
55 // check if the file exists in the custom templates directory
56 $fileName = implode(DIRECTORY_SEPARATOR,
57 array(
58 $config->customTemplateDir,
59 'CRM',
60 'Case',
61 'xml',
62 'configuration',
63 "$caseType.xml",
64 )
65 );
66 }
67
68 if (!$fileName ||
69 !file_exists($fileName)
70 ) {
71 // check if file exists locally
72 $fileName = implode(DIRECTORY_SEPARATOR,
73 array(dirname(__FILE__),
74 'xml',
75 'configuration',
76 "$caseType.xml",
77 )
78 );
79
80 if (!file_exists($fileName)) {
81 // check if file exists locally
82 $fileName = implode(DIRECTORY_SEPARATOR,
83 array(dirname(__FILE__),
84 'xml',
85 'configuration.sample',
86 "$caseType.xml",
87 )
88 );
89 }
6b86870e
TO
90
91 if (!file_exists($fileName)) {
92 if (self::$_hookCache === NULL) {
93 self::$_hookCache = array();
94 CRM_Utils_Hook::caseTypes(self::$_hookCache);
95 }
96 if (isset(self::$_hookCache[$caseType], self::$_hookCache[$caseType]['file'])) {
97 $fileName = self::$_hookCache[$caseType]['file'];
98 }
99 }
100
6a488035
TO
101 if (!file_exists($fileName)) {
102 return FALSE;
103 }
104 }
105
106 // read xml file
107 $dom = new DomDocument();
108 $dom->load($fileName);
109 $dom->xinclude();
110 self::$_xml[$caseType] = simplexml_import_dom($dom);
111 }
112 return self::$_xml[$caseType];
113 }
114
6b86870e
TO
115 public static function mungeCaseType($caseType) {
116 // trim all spaces from $caseType
117 $caseType = str_replace('_', ' ', $caseType);
118 $caseType = CRM_Utils_String::munge(ucwords($caseType), '', 0);
119 return $caseType;
120 }
121
6a488035
TO
122 function &allActivityTypes($indexName = TRUE, $all = FALSE) {
123 static $activityTypes = NULL;
124 if (!$activityTypes) {
125 $activityTypes = CRM_Case_PseudoConstant::caseActivityType($indexName, $all);
126 }
127 return $activityTypes;
128 }
129
130 function &allRelationshipTypes() {
131 static $relationshipTypes = array();
132
133 if (!$relationshipTypes) {
134 $relationshipInfo = CRM_Core_PseudoConstant::relationshipType();
135
136 $relationshipTypes = array();
137 foreach ($relationshipInfo as $id => $info) {
138 $relationshipTypes[$id] = $info['label_b_a'];
139 }
140 }
141
142 return $relationshipTypes;
143 }
144}
145