CiviCase - Add "manage case" link to metadata, make cid optional
authorcolemanw <coleman@civicrm.org>
Mon, 2 Oct 2023 04:54:28 +0000 (00:54 -0400)
committercolemanw <coleman@civicrm.org>
Wed, 4 Oct 2023 00:52:21 +0000 (20:52 -0400)
CRM/Case/DAO/Case.php
CRM/Case/Form/CaseView.php
CRM/Case/Page/Tab.php
xml/schema/Case/Case.xml

index 08d048818b67526a1d01a8dcb961be7e1adb1fcb..cc6544671c1ee26ae86f73504d32f15938a64e4f 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Generated from xml/schema/CRM/Case/Case.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:83be6db09d4f5220f74ccc72149dcab6)
+ * (GenCodeChecksum:b5dbbb96b15e9ff288890017d324b984)
  */
 
 /**
@@ -45,6 +45,15 @@ class CRM_Case_DAO_Case extends CRM_Core_DAO {
    */
   public static $_log = TRUE;
 
+  /**
+   * Paths for accessing this entity in the UI.
+   *
+   * @var string[]
+   */
+  protected static $_paths = [
+    'view' => 'civicrm/contact/view/case?action=view&reset=1&id=[id]',
+  ];
+
   /**
    * Unique Case ID
    *
index 24c0f4552c7abaf5dd91522723633e9f16b1e3f1..bf50e3ec6a4d932b5b98f838e1fa11115f1e535d 100644 (file)
@@ -49,6 +49,8 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form {
    */
   public $_contactID;
 
+  private $_caseClients;
+
   /**
    * ID of case being viewed
    *
@@ -100,9 +102,21 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form {
     $this->_hasAccessToAllCases = CRM_Core_Permission::check('access all cases and activities');
     $this->assign('hasAccessToAllCases', $this->_hasAccessToAllCases);
 
-    $this->assign('contactID', $this->_contactID = (int) $this->get('cid'));
     $this->assign('caseID', $this->_caseID = (int) $this->get('id'));
 
+    $this->_caseClients = CRM_Case_BAO_Case::getContactNames($this->_caseID);
+
+    $cid = $this->get('cid');
+
+    // If no cid supplied, use first case client
+    if (!$cid) {
+      $cid = array_keys($this->_caseClients)[0];
+    }
+    elseif (!isset($this->_caseClients[$cid])) {
+      CRM_Core_Error::statusBounce("Contact $cid not a client of case " . $this->_caseID);
+    }
+    $this->assign('contactID', $this->_contactID = (int) $cid);
+
     // Access check.
     if (!CRM_Case_BAO_Case::accessCase($this->_caseID, FALSE)) {
       CRM_Core_Error::statusBounce(ts('You do not have permission to access this case.'));
@@ -147,7 +161,7 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form {
       "action=view&reset=1&id={$this->_caseID}&cid={$this->_contactID}&context=home"
     );
 
-    $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactID);
+    $displayName = $this->_caseClients[$this->_contactID]['display_name'];
     $this->assign('displayName', $displayName);
 
     $this->setTitle($displayName . ' - ' . $caseType);
@@ -366,7 +380,7 @@ class CRM_Case_Form_CaseView extends CRM_Core_Form {
     $this->assign('caseRelationships', $caseRelationships);
 
     //also add client as role. CRM-4438
-    $caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($this->_caseID);
+    $caseRoles['client'] = $this->_caseClients;
 
     $this->assign('caseRoles', $caseRoles);
 
index 8c91b6ffb5eac58837606497200d02482de1a5dd..3dc37a7e6bb6145e5cd1f46b30b7cfa5b66886a7 100644 (file)
@@ -61,11 +61,6 @@ class CRM_Case_Page_Tab extends CRM_Core_Page {
         CRM_Contact_Page_View::checkUserPermission($this);
       }
     }
-    else {
-      if ($this->_action & CRM_Core_Action::VIEW) {
-        CRM_Core_Error::statusBounce(ts('Contact Id is required for view action.'));
-      }
-    }
 
     $activityTypes = CRM_Case_PseudoConstant::caseActivityType();
 
index d78de6fc224dbbb553f02317707e8ae355b0e171..3ca859baadeff569a37a2426790726140956bfd9 100644 (file)
@@ -10,6 +10,9 @@
   <icon>fa-folder-open</icon>
   <labelField>subject</labelField>
   <component>CiviCase</component>
+  <paths>
+    <view>civicrm/contact/view/case?action=view&amp;reset=1&amp;id=[id]</view>
+  </paths>
   <field>
     <name>id</name>
     <type>int unsigned</type>