| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.5 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
| 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-2014 |
| 32 | * $Id$ |
| 33 | * |
| 34 | */ |
| 35 | class CRM_Case_XMLProcessor { |
| 36 | |
| 37 | /** |
| 38 | * Relationship-types have four name fields (name_a_b, name_b_a, label_a_b, |
| 39 | * label_b_a), but CiviCase XML refers to reltypes by a single name. |
| 40 | * REL_TYPE_CNAME identifies the canonical name field as used by CiviCase XML. |
| 41 | * |
| 42 | * This appears to be "label_b_a", but IMHO "name_b_a" would be more |
| 43 | * sensible. |
| 44 | */ |
| 45 | const REL_TYPE_CNAME = 'label_b_a'; |
| 46 | |
| 47 | /** |
| 48 | * @param $caseType |
| 49 | * |
| 50 | * @return FALSE|SimpleXMLElement |
| 51 | */ |
| 52 | public function retrieve($caseType) { |
| 53 | return CRM_Case_XMLRepository::singleton()->retrieve($caseType); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * @param $caseType |
| 58 | * |
| 59 | * @return mixed|string |
| 60 | */ |
| 61 | public static function mungeCaseType($caseType) { |
| 62 | // trim all spaces from $caseType |
| 63 | $caseType = str_replace('_', ' ', $caseType); |
| 64 | $caseType = CRM_Utils_String::munge(ucwords($caseType), '', 0); |
| 65 | return $caseType; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @param bool $indexName |
| 70 | * @param bool $all |
| 71 | * |
| 72 | * @return array |
| 73 | */ |
| 74 | function &allActivityTypes($indexName = TRUE, $all = FALSE) { |
| 75 | static $activityTypes = NULL; |
| 76 | if (!$activityTypes) { |
| 77 | $activityTypes = CRM_Case_PseudoConstant::caseActivityType($indexName, $all); |
| 78 | } |
| 79 | return $activityTypes; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * @return array |
| 84 | */ |
| 85 | function &allRelationshipTypes() { |
| 86 | static $relationshipTypes = array(); |
| 87 | |
| 88 | if (!$relationshipTypes) { |
| 89 | $relationshipInfo = CRM_Core_PseudoConstant::relationshipType(); |
| 90 | |
| 91 | $relationshipTypes = array(); |
| 92 | foreach ($relationshipInfo as $id => $info) { |
| 93 | $relationshipTypes[$id] = $info[CRM_Case_XMLProcessor::REL_TYPE_CNAME]; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | return $relationshipTypes; |
| 98 | } |
| 99 | } |
| 100 | |