0214254bef118b4a275bb291bd83c29468ab084f
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_XMLRepository
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($allCaseTypes = NULL, $xml = array()) {
69 $this->allCaseTypes
= $allCaseTypes;
74 * @param string $caseType
75 * @return SimpleXMLElement|FALSE
77 public function retrieve($caseType) {
78 $caseType = CRM_Case_XMLProcessor
::mungeCaseType($caseType);
80 if (!CRM_Utils_Array
::value($caseType, $this->xml
)) {
81 // first check custom templates directory
83 $config = CRM_Core_Config
::singleton();
84 if (isset($config->customTemplateDir
) &&
85 $config->customTemplateDir
87 // check if the file exists in the custom templates directory
88 $fileName = implode(DIRECTORY_SEPARATOR
,
90 $config->customTemplateDir
,
101 !file_exists($fileName)
103 // check if file exists locally
104 $fileName = implode(DIRECTORY_SEPARATOR
,
113 if (!file_exists($fileName)) {
114 // check if file exists locally
115 $fileName = implode(DIRECTORY_SEPARATOR
,
119 'configuration.sample',
125 if (!file_exists($fileName)) {
126 $caseTypesViaHook = $this->getCaseTypesViaHook();
127 if (isset($caseTypesViaHook[$caseType], $caseTypesViaHook[$caseType]['file'])) {
128 $fileName = $caseTypesViaHook[$caseType]['file'];
132 if (!file_exists($fileName)) {
138 $dom = new DomDocument();
139 $dom->load($fileName);
141 $this->xml
[$caseType] = simplexml_import_dom($dom);
143 return $this->xml
[$caseType];
148 * @see CRM_Utils_Hook::caseTypes
150 public function getCaseTypesViaHook() {
151 if ($this->hookCache
=== NULL) {
152 $this->hookCache
= array();
153 CRM_Utils_Hook
::caseTypes($this->hookCache
);
155 return $this->hookCache
;
159 * @return array<string> symbolic names of case-types
161 public function getAllCaseTypes() {
162 if ($this->allCaseTypes
=== NULL) {
163 $this->allCaseTypes
= CRM_Case_PseudoConstant
::caseType("name");
165 return $this->allCaseTypes
;
169 * Determine the number of times a particular activity-type is
170 * referenced in CiviCase XML.
172 * @param string $activityType symbolic-name of an activity type
175 function getActivityReferenceCount($activityType) {
176 $p = new CRM_Case_XMLProcessor_Process();
178 foreach ($this->getAllCaseTypes() as $caseTypeName) {
179 $caseTypeXML = $this->retrieve($caseTypeName);
180 if (in_array($activityType, $p->getDeclaredActivityTypes($caseTypeXML))) {
188 * Determine the number of times a particular activity-type is
189 * referenced in CiviCase XML.
191 * @param string $relationshipTypeName symbolic-name of a relationship-type
194 function getRelationshipReferenceCount($relationshipTypeName) {
195 $p = new CRM_Case_XMLProcessor_Process();
197 foreach ($this->getAllCaseTypes() as $caseTypeName) {
198 $caseTypeXML = $this->retrieve($caseTypeName);
199 if (in_array($relationshipTypeName, $p->getDeclaredRelationshipTypes($caseTypeXML))) {