Merge pull request #5535 from colemanw/CRM-16081
[civicrm-core.git] / CRM / Case / XMLProcessor.php
index c83ed418642bea3771585cf918a950742131e032..614dbf8c95088adfff06228c8b10ca5ca03498cc 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
 class CRM_Case_XMLProcessor {
 
+  /**
+   * FIXME: This does *NOT* belong in a static property, but we're too late in
+   * the 4.5-cycle to do the necessary cleanup.
+   *
+   * @var array|null array(int $id => string $relTypeCname)
+   */
+  public static $activityTypes = NULL;
+
+  /**
+   * FIXME: This does *NOT* belong in a static property, but we're too late in
+   * the 4.5-cycle to do the necessary cleanup.
+   *
+   * @var array|null array(int $id => string $relTypeCname)
+   */
+  public static $relationshipTypes = NULL;
+
   /**
    * Relationship-types have four name fields (name_a_b, name_b_a, label_a_b,
    * label_b_a), but CiviCase XML refers to reltypes by a single name.
@@ -54,9 +70,23 @@ class CRM_Case_XMLProcessor {
   }
 
   /**
-   * @param $caseType
+   * This function was previously used to convert a case-type's
+   * machine-name to a file-name. However, it's mind-boggling
+   * that the file-name might be a munged version of the
+   * machine-name (which is itself a munged version of the
+   * display-name), and naming is now a more visible issue (since
+   * the overhaul of CaseType admin UI).
+   *
+   * Usage note: This is called externally by civix stubs as a
+   * sort of side-ways validation of the case-type's name
+   * (validation which was needed because of the unintuitive
+   * double-munge). We should update civix templates and then
+   * remove this function in Civi 4.6 or 5.0.
    *
-   * @return mixed|string
+   * @param string $caseType
+   * @return string
+   * @deprecated
+   * @see CRM_Case_BAO_CaseType::isValidName
    */
   public static function mungeCaseType($caseType) {
     // trim all spaces from $caseType
@@ -71,30 +101,35 @@ class CRM_Case_XMLProcessor {
    *
    * @return array
    */
-  function &allActivityTypes($indexName = TRUE, $all = FALSE) {
-    static $activityTypes = NULL;
-    if (!$activityTypes) {
-      $activityTypes = CRM_Case_PseudoConstant::caseActivityType($indexName, $all);
+  public function &allActivityTypes($indexName = TRUE, $all = FALSE) {
+    if (self::$activityTypes === NULL) {
+      self::$activityTypes = CRM_Case_PseudoConstant::caseActivityType($indexName, $all);
     }
-    return $activityTypes;
+    return self::$activityTypes;
   }
 
   /**
    * @return array
    */
-  function &allRelationshipTypes() {
-    static $relationshipTypes = array();
-
-    if (!$relationshipTypes) {
-      $relationshipInfo = CRM_Core_PseudoConstant::relationshipType();
+  public function &allRelationshipTypes() {
+    if (self::$relationshipTypes === NULL) {
+      $relationshipInfo = CRM_Core_PseudoConstant::relationshipType('label', TRUE);
 
-      $relationshipTypes = array();
+      self::$relationshipTypes = array();
       foreach ($relationshipInfo as $id => $info) {
-        $relationshipTypes[$id] = $info[CRM_Case_XMLProcessor::REL_TYPE_CNAME];
+        self::$relationshipTypes[$id] = $info[CRM_Case_XMLProcessor::REL_TYPE_CNAME];
       }
     }
 
-    return $relationshipTypes;
+    return self::$relationshipTypes;
   }
-}
 
+  /**
+   * FIXME: This should not exist
+   */
+  public static function flushStaticCaches() {
+    self::$activityTypes = NULL;
+    self::$relationshipTypes = NULL;
+  }
+
+}