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.
35 * It includes any bulk operations that apply across the list of all XML
36 * documents of all case-types.
38 class CRM_Case_XMLRepository
{
39 private static $singleton;
42 * @var array<String,SimpleXMLElement>
44 protected $xml = array();
49 protected $hookCache = NULL;
52 * @var array|NULL symbolic names of case-types
54 protected $allCaseTypes = NULL;
58 * @return CRM_Case_XMLRepository
60 public static function singleton($fresh = FALSE) {
61 if (!self
::$singleton ||
$fresh) {
62 self
::$singleton = new static();
64 return self
::$singleton;
68 * @param array<String,SimpleXMLElement> $xml
70 public function __construct($allCaseTypes = NULL, $xml = array()) {
71 $this->allCaseTypes
= $allCaseTypes;
76 * @param string $caseType
77 * @return SimpleXMLElement|FALSE
79 public function retrieve($caseType) {
80 $caseType = CRM_Case_XMLProcessor
::mungeCaseType($caseType);
82 if (!CRM_Utils_Array
::value($caseType, $this->xml
)) {
83 // first check custom templates directory
86 if (!$fileName ||
!file_exists($fileName)) {
87 $caseTypesViaHook = $this->getCaseTypesViaHook();
88 if (isset($caseTypesViaHook[$caseType], $caseTypesViaHook[$caseType]['file'])) {
89 $fileName = $caseTypesViaHook[$caseType]['file'];
93 if (!$fileName ||
!file_exists($fileName)) {
94 $config = CRM_Core_Config
::singleton();
95 if (isset($config->customTemplateDir
) && $config->customTemplateDir
) {
96 // check if the file exists in the custom templates directory
97 $fileName = implode(DIRECTORY_SEPARATOR
,
99 $config->customTemplateDir
,
110 if (!$fileName ||
!file_exists($fileName)) {
111 if (!file_exists($fileName)) {
112 // check if file exists locally
113 $fileName = implode(DIRECTORY_SEPARATOR
,
123 if (!file_exists($fileName)) {
124 // check if file exists locally
125 $fileName = implode(DIRECTORY_SEPARATOR
,
129 'configuration.sample',
135 if (!file_exists($fileName)) {
141 $dom = new DomDocument();
142 $dom->load($fileName);
144 $this->xml
[$caseType] = simplexml_import_dom($dom);
146 return $this->xml
[$caseType];
151 * @see CRM_Utils_Hook::caseTypes
153 public function getCaseTypesViaHook() {
154 if ($this->hookCache
=== NULL) {
155 $this->hookCache
= array();
156 CRM_Utils_Hook
::caseTypes($this->hookCache
);
158 return $this->hookCache
;
162 * @return array<string> symbolic names of case-types
164 public function getAllCaseTypes() {
165 if ($this->allCaseTypes
=== NULL) {
166 $this->allCaseTypes
= CRM_Case_PseudoConstant
::caseType("name");
168 return $this->allCaseTypes
;
172 * @return array<string> symbolic-names of activity-types
174 public function getAllDeclaredActivityTypes() {
177 $p = new CRM_Case_XMLProcessor_Process();
178 foreach ($this->getAllCaseTypes() as $caseTypeName) {
179 $caseTypeXML = $this->retrieve($caseTypeName);
180 $result = array_merge($result, $p->getDeclaredActivityTypes($caseTypeXML));
183 $result = array_unique($result);
189 * @return array<string> symbolic-names of relationship-types
191 public function getAllDeclaredRelationshipTypes() {
194 $p = new CRM_Case_XMLProcessor_Process();
195 foreach ($this->getAllCaseTypes() as $caseTypeName) {
196 $caseTypeXML = $this->retrieve($caseTypeName);
197 $result = array_merge($result, $p->getDeclaredRelationshipTypes($caseTypeXML));
200 $result = array_unique($result);
206 * Determine the number of times a particular activity-type is
207 * referenced in CiviCase XML.
209 * @param string $activityType symbolic-name of an activity type
212 function getActivityReferenceCount($activityType) {
213 $p = new CRM_Case_XMLProcessor_Process();
215 foreach ($this->getAllCaseTypes() as $caseTypeName) {
216 $caseTypeXML = $this->retrieve($caseTypeName);
217 if (in_array($activityType, $p->getDeclaredActivityTypes($caseTypeXML))) {
225 * Determine the number of times a particular activity-type is
226 * referenced in CiviCase XML.
228 * @param string $relationshipTypeName symbolic-name of a relationship-type
231 function getRelationshipReferenceCount($relationshipTypeName) {
232 $p = new CRM_Case_XMLProcessor_Process();
234 foreach ($this->getAllCaseTypes() as $caseTypeName) {
235 $caseTypeXML = $this->retrieve($caseTypeName);
236 if (in_array($relationshipTypeName, $p->getDeclaredRelationshipTypes($caseTypeXML))) {