Merge pull request #3739 from rohankatkar/testCaseTypeDelete_InUse
[civicrm-core.git] / CRM / Case / Info.php
index 8ed9054fd7198fe086c6cdb9178f6b1fc7b02599..d62a10cbdbcddc6353a8e3c13837a1e30282b541 100644 (file)
@@ -42,6 +42,9 @@ class CRM_Case_Info extends CRM_Core_Component_Info {
   protected $keyword = 'case';
 
   // docs inherited from interface
+  /**
+   * @return array
+   */
   public function getInfo() {
     return array(
       'name' => 'CiviCase',
@@ -52,49 +55,45 @@ class CRM_Case_Info extends CRM_Core_Component_Info {
     );
   }
 
-  // docs inherited from interface
-  public function getManagedEntities() {
-    // Use hook_civicrm_caseTypes to build a list of OptionValues
-    // In the long run, we may want more specialized logic for this, but
-    // this design is fairly convenient and will allow us to replace it
-    // without changing the hook_civicrm_caseTypes interface.
-    $entities = array();
-
-    $caseTypes = array();
-    CRM_Utils_Hook::caseTypes($caseTypes);
-
-    $proc = new CRM_Case_XMLProcessor();
-    foreach ($caseTypes as $name => $caseType) {
-      $xml = $proc->retrieve($name);
-      if (!$xml) {
-        throw new CRM_Core_Exception("Failed to load XML for case type (" . $name . ")");
-      }
+  /**
+   * {@inheritDoc}
+   */
+  public function getAngularModules() {
+    $result = array();
+    $result['crmCaseType'] = array(
+      'ext' => 'civicrm',
+      'js' => array('js/angular-crmCaseType.js'),
+      'css' => array('css/angular-crmCaseType.css'),
+    );
 
-      if (isset($caseType['module'], $caseType['name'], $caseType['file'])) {
-        $entities[] = array(
-          'module' => $caseType['module'],
-          'name' => $caseType['name'],
-          'entity' => 'CaseType',
-          'params' => array(
-            'version' => 3,
-            'name' => $caseType['name'],
-            'title' => (string) $xml->name,
-            'description' => (string) $xml->description,
-            'is_reserved' => 1,
-            'is_active' => 1,
-            'weight' => $xml->weight ? $xml->weight : 1,
-          ),
-        );
-      }
-      else {
-        throw new CRM_Core_Exception("Invalid case type");
-      }
-    }
+    CRM_Core_Resources::singleton()->addSetting(array(
+      'crmCaseType' => array(
+        'REL_TYPE_CNAME' => CRM_Case_XMLProcessor::REL_TYPE_CNAME,
+      ),
+    ));
+    return $result;
+  }
 
+  // docs inherited from interface
+  /**
+   * @return array
+   * @throws CRM_Core_Exception
+   */
+  public function getManagedEntities() {
+    $entities = array_merge(
+      CRM_Case_ManagedEntities::createManagedCaseTypes(),
+      CRM_Case_ManagedEntities::createManagedActivityTypes(CRM_Case_XMLRepository::singleton(), CRM_Core_ManagedEntities::singleton()),
+      CRM_Case_ManagedEntities::createManagedRelationshipTypes(CRM_Case_XMLRepository::singleton(), CRM_Core_ManagedEntities::singleton())
+    );
     return $entities;
   }
 
   // docs inherited from interface
+  /**
+   * @param bool $getAllUnconditionally
+   *
+   * @return array
+   */
   public function getPermissions($getAllUnconditionally = FALSE) {
     return array(
       'delete in CiviCase',
@@ -105,12 +104,53 @@ class CRM_Case_Info extends CRM_Core_Component_Info {
     );
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function getReferenceCounts($dao) {
+    $result = array();
+    if ($dao instanceof CRM_Core_DAO_OptionValue) {
+      /** @var $dao CRM_Core_DAO_OptionValue */
+      $activity_type_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'activity_type', 'id', 'name');
+      if ($activity_type_gid == $dao->option_group_id) {
+        $count = CRM_Case_XMLRepository::singleton()
+          ->getActivityReferenceCount($dao->name);
+        if ($count > 0) {
+          $result[] = array(
+            'name' => 'casetypexml:activities',
+            'type' => 'casetypexml',
+            'count' => $count,
+          );
+        }
+      }
+    }
+    elseif ($dao instanceof CRM_Contact_DAO_RelationshipType) {
+      /** @var $dao CRM_Contact_DAO_RelationshipType */
+      $count = CRM_Case_XMLRepository::singleton()
+        ->getRelationshipReferenceCount($dao->{CRM_Case_XMLProcessor::REL_TYPE_CNAME});
+      if ($count > 0) {
+        $result[] = array(
+          'name' => 'casetypexml:relationships',
+          'type' => 'casetypexml',
+          'count' => $count,
+        );
+      }
+    }
+    return $result;
+  }
+
   // docs inherited from interface
+  /**
+   * @return array
+   */
   public function getUserDashboardElement() {
     return array();
   }
 
   // docs inherited from interface
+  /**
+   * @return array
+   */
   public function registerTab() {
     return array('title' => ts('Cases'),
       'url' => 'case',
@@ -119,6 +159,9 @@ class CRM_Case_Info extends CRM_Core_Component_Info {
   }
 
   // docs inherited from interface
+  /**
+   * @return array
+   */
   public function registerAdvancedSearchPane() {
     return array('title' => ts('Cases'),
       'weight' => 50,
@@ -126,11 +169,17 @@ class CRM_Case_Info extends CRM_Core_Component_Info {
   }
 
   // docs inherited from interface
+  /**
+   * @return null
+   */
   public function getActivityTypes() {
     return NULL;
   }
 
   // add shortcut to Create New
+  /**
+   * @param $shortCuts
+   */
   public function creatNewShortcut(&$shortCuts) {
     if (CRM_Core_Permission::check('access all cases and activities') ||
       CRM_Core_Permission::check('add cases')