Merge pull request #1639 from eileenmcnaughton/master
[civicrm-core.git] / CRM / Case / XMLProcessor.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
232624b1 4 | CiviCRM version 4.4 |
6a488035
TO
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
32 * $Id$
33 *
34 */
35class CRM_Case_XMLProcessor {
36
37 static protected $_xml;
38
39 function retrieve($caseType) {
40 // trim all spaces from $caseType
41 $caseType = str_replace('_', ' ', $caseType);
42 $caseType = CRM_Utils_String::munge(ucwords($caseType), '', 0);
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 }
90 if (!file_exists($fileName)) {
91 return FALSE;
92 }
93 }
94
95 // read xml file
96 $dom = new DomDocument();
97 $dom->load($fileName);
98 $dom->xinclude();
99 self::$_xml[$caseType] = simplexml_import_dom($dom);
100 }
101 return self::$_xml[$caseType];
102 }
103
104 function &allActivityTypes($indexName = TRUE, $all = FALSE) {
105 static $activityTypes = NULL;
106 if (!$activityTypes) {
107 $activityTypes = CRM_Case_PseudoConstant::caseActivityType($indexName, $all);
108 }
109 return $activityTypes;
110 }
111
112 function &allRelationshipTypes() {
113 static $relationshipTypes = array();
114
115 if (!$relationshipTypes) {
116 $relationshipInfo = CRM_Core_PseudoConstant::relationshipType();
117
118 $relationshipTypes = array();
119 foreach ($relationshipInfo as $id => $info) {
120 $relationshipTypes[$id] = $info['label_b_a'];
121 }
122 }
123
124 return $relationshipTypes;
125 }
126}
127