Merge pull request #23015 from ginkgomzd/php8-unsupported-operand
[civicrm-core.git] / CRM / Contact / Page / View / CustomData.php
index 8e78b9064d2dc8c14462dc771354035ea3562443..8d8a5e9fefaa94ec07c781e8236241dc7bfd1a5a 100644 (file)
@@ -27,15 +27,6 @@ class CRM_Contact_Page_View_CustomData extends CRM_Core_Page {
    */
   public $_groupId;
 
-  /**
-   * Class constructor.
-   *
-   * @return CRM_Contact_Page_View_CustomData
-   */
-  public function __construct() {
-    parent::__construct();
-  }
-
   /**
    * Add a few specific things to view contact.
    */
@@ -83,18 +74,9 @@ class CRM_Contact_Page_View_CustomData extends CRM_Core_Page {
     $session = CRM_Core_Session::singleton();
     $session->pushUserContext(CRM_Utils_System::url($doneURL, 'action=browse&selectedChild=custom_' . $this->_groupId), FALSE);
 
-    // Get permission detail - view or edit.
-    // use a contact id specific function which gives us much better granularity
-    // CRM-12646
-    $editCustomData = CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT);
-    $this->assign('editCustomData', $editCustomData);
-
-    // Allow to edit own custom data CRM-5518.
-    $editOwnCustomData = FALSE;
-    if ($session->get('userID') == $this->_contactId) {
-      $editOwnCustomData = TRUE;
-    }
-    $this->assign('editOwnCustomData', $editOwnCustomData);
+    // Check permission to edit this contact
+    $editPermission = CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT);
+    $this->assign('editPermission', $editPermission);
 
     if ($this->_action == CRM_Core_Action::BROWSE) {
 
@@ -105,8 +87,7 @@ class CRM_Contact_Page_View_CustomData extends CRM_Core_Page {
 
       if ($this->_multiRecordDisplay != 'single') {
         $id = "custom_{$this->_groupId}";
-        $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_groupId, 'table_name');
-        $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $tableName);
+        $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId);
       }
 
       if ($displayStyle === 'Tab with table' && $this->_multiRecordDisplay != 'single') {
@@ -137,7 +118,7 @@ class CRM_Contact_Page_View_CustomData extends CRM_Core_Page {
           $groupTitle = CRM_Core_BAO_CustomGroup::getTitle($this->_groupId);
           CRM_Utils_System::setTitle(ts('View %1 Record', [1 => $groupTitle]));
           $groupTree = CRM_Core_BAO_CustomGroup::getTree($entityType, NULL, $this->_contactId,
-            $this->_groupId, $entitySubType, NULL, TRUE, NULL, FALSE, TRUE, $this->_cgcount
+            $this->_groupId, $entitySubType, NULL, TRUE, NULL, FALSE, CRM_Core_Permission::VIEW, $this->_cgcount
           );
 
           $recId = $this->_recId;
@@ -146,10 +127,10 @@ class CRM_Contact_Page_View_CustomData extends CRM_Core_Page {
         }
         else {
           $groupTree = CRM_Core_BAO_CustomGroup::getTree($entityType, NULL, $this->_contactId,
-            $this->_groupId, $entitySubType
+            $this->_groupId, $entitySubType, NULL, TRUE, NULL, FALSE, CRM_Core_Permission::VIEW
           );
         }
-        CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, $recId, $this->_contactId);
+        CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, $recId, $this->_contactId, TRUE);
       }
     }
     else {