3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
34 * The XMLRepository is responsible for loading XML for case-types.
36 class CRM_Case_XMLRepository
{
37 private static $singleton;
40 * @var array<String,SimpleXMLElement>
42 protected $xml = array();
47 protected $hookCache = NULL;
50 * @var array|NULL symbolic names of case-types
52 protected $allCaseTypes = NULL;
56 * @return CRM_Case_XMLProcessor
58 public static function singleton($fresh = FALSE) {
59 if (!self
::$singleton ||
$fresh) {
60 self
::$singleton = new static();
62 return self
::$singleton;
66 * @param array<String,SimpleXMLElement> $xml
68 public function __construct($xml = array()) {
73 * @param string $caseType
74 * @return SimpleXMLElement|FALSE
76 public function retrieve($caseType) {
77 $caseType = CRM_Case_XMLProcessor
::mungeCaseType($caseType);
79 if (!CRM_Utils_Array
::value($caseType, $this->xml
)) {
80 // first check custom templates directory
82 $config = CRM_Core_Config
::singleton();
83 if (isset($config->customTemplateDir
) &&
84 $config->customTemplateDir
86 // check if the file exists in the custom templates directory
87 $fileName = implode(DIRECTORY_SEPARATOR
,
89 $config->customTemplateDir
,
100 !file_exists($fileName)
102 // check if file exists locally
103 $fileName = implode(DIRECTORY_SEPARATOR
,
112 if (!file_exists($fileName)) {
113 // check if file exists locally
114 $fileName = implode(DIRECTORY_SEPARATOR
,
118 'configuration.sample',
124 if (!file_exists($fileName)) {
125 $caseTypesViaHook = $this->getCaseTypesViaHook();
126 if (isset($caseTypesViaHook[$caseType], $caseTypesViaHook[$caseType]['file'])) {
127 $fileName = $caseTypesViaHook[$caseType]['file'];
131 if (!file_exists($fileName)) {
137 $dom = new DomDocument();
138 $dom->load($fileName);
140 $this->xml
[$caseType] = simplexml_import_dom($dom);
142 return $this->xml
[$caseType];
147 * @see CRM_Utils_Hook::caseTypes
149 public function getCaseTypesViaHook() {
150 if ($this->hookCache
=== NULL) {
151 $this->hookCache
= array();
152 CRM_Utils_Hook
::caseTypes($this->hookCache
);
154 return $this->hookCache
;