Merge pull request #23015 from ginkgomzd/php8-unsupported-operand
[civicrm-core.git] / CRM / Contact / Page / View / Note.php
index 2930341be709a478f7985f6821fdda58494fd9bc..64e8101128948eda129703e042c2cdb63b0b75bc 100644 (file)
@@ -1,34 +1,18 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 5                                                  |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2019                                |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM.                                    |
- |                                                                    |
- | CiviCRM is free software; you can copy, modify, and distribute it  |
- | under the terms of the GNU Affero General Public License           |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ | Copyright CiviCRM LLC. All rights reserved.                        |
  |                                                                    |
- | CiviCRM is distributed in the hope that it will be useful, but     |
- | WITHOUT ANY WARRANTY; without even the implied warranty of         |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
- | See the GNU Affero General Public License for more details.        |
- |                                                                    |
- | You should have received a copy of the GNU Affero General Public   |
- | License and the CiviCRM Licensing Exception along                  |
- | with this program; if not, contact CiviCRM LLC                     |
- | at info[AT]civicrm[DOT]org. If you have questions about the        |
- | GNU Affero General Public License or the licensing of CiviCRM,     |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ | This work is published under the GNU AGPLv3 license with some      |
+ | permitted exceptions and without any warranty. For full license    |
+ | and copyright information, see https://civicrm.org/licensing       |
  +--------------------------------------------------------------------+
  */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2019
+ * @copyright CiviCRM LLC https://civicrm.org/licensing
  */
 
 /**
 class CRM_Contact_Page_View_Note extends CRM_Core_Page {
 
   /**
-   * The action links for notes that we need to display for the browse screen
-   *
-   * @var array
-   */
-  public static $_links = NULL;
-
-  /**
-   * The action links for comments that we need to display for the browse screen
-   *
+   * Notes found running the browse function
    * @var array
    */
-  public static $_commentLinks = NULL;
+  public $values = [];
 
   /**
    * View details of a note.
@@ -57,14 +33,13 @@ class CRM_Contact_Page_View_Note extends CRM_Core_Page {
     $note = new CRM_Core_DAO_Note();
     $note->id = $this->_id;
     if ($note->find(TRUE)) {
-      $values = [];
 
-      CRM_Core_DAO::storeValues($note, $values);
-      $values['privacy'] = CRM_Core_PseudoConstant::getLabel('CRM_Core_BAO_Note', 'privacy', $values['privacy']);
-      $this->assign('note', $values);
+      CRM_Core_DAO::storeValues($note, $this->values);
+      $this->values['privacy'] = CRM_Core_PseudoConstant::getLabel('CRM_Core_BAO_Note', 'privacy', $this->values['privacy']);
+      $this->assign('note', $this->values);
     }
 
-    $comments = CRM_Core_BAO_Note::getNoteTree($values['id'], 1);
+    $comments = CRM_Core_BAO_Note::getNoteTree($this->values['id'], 1);
     if (!empty($comments)) {
       $this->assign('comments', $comments);
     }
@@ -96,16 +71,15 @@ class CRM_Contact_Page_View_Note extends CRM_Core_Page {
 
     $this->assign('canAddNotes', CRM_Core_Permission::check('add contact notes'));
 
-    $values = [];
     $links = self::links();
     $action = array_sum(array_keys($links)) & $mask;
 
     $note->find();
     while ($note->fetch()) {
       if (!CRM_Core_BAO_Note::getNotePrivacyHidden($note)) {
-        CRM_Core_DAO::storeValues($note, $values[$note->id]);
+        CRM_Core_DAO::storeValues($note, $this->values[$note->id]);
 
-        $values[$note->id]['action'] = CRM_Core_Action::formLink($links,
+        $this->values[$note->id]['action'] = CRM_Core_Action::formLink($links,
           $action,
           [
             'id' => $note->id,
@@ -122,17 +96,16 @@ class CRM_Contact_Page_View_Note extends CRM_Core_Page {
           $contact->id = $note->contact_id;
           $contact->find();
           $contact->fetch();
-          $values[$note->id]['createdBy'] = $contact->display_name;
+          $this->values[$note->id]['createdBy'] = $contact->display_name;
         }
-        $values[$note->id]['comment_count'] = CRM_Core_BAO_Note::getChildCount($note->id);
+        $this->values[$note->id]['comment_count'] = CRM_Core_BAO_Note::getChildCount($note->id);
 
         // paper icon view for attachments part
         $paperIconAttachmentInfo = CRM_Core_BAO_File::paperIconAttachment('civicrm_note', $note->id);
-        $values[$note->id]['attachment'] = $paperIconAttachmentInfo;
+        $this->values[$note->id]['attachment'] = $paperIconAttachmentInfo;
       }
     }
-
-    $this->assign('notes', $values);
+    $this->assign('notes', $this->values);
 
     $commentLinks = self::commentLinks();
 
@@ -171,7 +144,7 @@ class CRM_Contact_Page_View_Note extends CRM_Core_Page {
     $session->pushUserContext($url);
 
     if (CRM_Utils_Request::retrieve('confirmed', 'Boolean')) {
-      CRM_Core_BAO_Note::del($this->_id);
+      $this->delete();
       CRM_Utils_System::redirect($url);
     }
 
@@ -246,82 +219,74 @@ class CRM_Contact_Page_View_Note extends CRM_Core_Page {
   }
 
   /**
-   * Delete the note object from the db.
+   * Delete the note object from the db and set a status msg.
    */
   public function delete() {
-    CRM_Core_BAO_Note::del($this->_id);
+    CRM_Core_BAO_Note::deleteRecord(['id' => $this->_id]);
+    $status = ts('Selected Note has been deleted successfully.');
+    CRM_Core_Session::setStatus($status, ts('Deleted'), 'success');
   }
 
   /**
    * Get action links.
    *
-   * @return array
-   *   (reference) of action links
+   * @return array[]
    */
-  public static function &links() {
-    if (!(self::$_links)) {
-      $deleteExtra = ts('Are you sure you want to delete this note?');
-
-      self::$_links = [
-        CRM_Core_Action::VIEW => [
-          'name' => ts('View'),
-          'url' => 'civicrm/contact/view/note',
-          'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
-          'title' => ts('View Note'),
-        ],
-        CRM_Core_Action::UPDATE => [
-          'name' => ts('Edit'),
-          'url' => 'civicrm/contact/view/note',
-          'qs' => 'action=update&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
-          'title' => ts('Edit Note'),
-        ],
-        CRM_Core_Action::ADD => [
-          'name' => ts('Comment'),
-          'url' => 'civicrm/contact/view/note',
-          'qs' => 'action=add&reset=1&cid=%%cid%%&parentId=%%id%%&selectedChild=note',
-          'title' => ts('Add Comment'),
-        ],
-        CRM_Core_Action::DELETE => [
-          'name' => ts('Delete'),
-          'url' => 'civicrm/contact/view/note',
-          'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
-          'title' => ts('Delete Note'),
-        ],
-      ];
-    }
-    return self::$_links;
+  public static function links() {
+    return [
+      CRM_Core_Action::VIEW => [
+        'name' => ts('View'),
+        'url' => 'civicrm/contact/view/note',
+        'qs' => 'action=view&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
+        'title' => ts('View Note'),
+      ],
+      CRM_Core_Action::UPDATE => [
+        'name' => ts('Edit'),
+        'url' => 'civicrm/contact/view/note',
+        'qs' => 'action=update&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
+        'title' => ts('Edit Note'),
+      ],
+      CRM_Core_Action::ADD => [
+        'name' => ts('Comment'),
+        'url' => 'civicrm/contact/view/note',
+        'qs' => 'action=add&reset=1&cid=%%cid%%&parentId=%%id%%&selectedChild=note',
+        'title' => ts('Add Comment'),
+      ],
+      CRM_Core_Action::DELETE => [
+        'name' => ts('Delete'),
+        'url' => 'civicrm/contact/view/note',
+        'qs' => 'action=delete&reset=1&cid=%%cid%%&id=%%id%%&selectedChild=note',
+        'title' => ts('Delete Note'),
+      ],
+    ];
   }
 
   /**
    * Get action links for comments.
    *
-   * @return array
-   *   (reference) of action links
+   * @return array[]
    */
-  public static function &commentLinks() {
-    if (!(self::$_commentLinks)) {
-      self::$_commentLinks = [
-        CRM_Core_Action::VIEW => [
-          'name' => ts('View'),
-          'url' => 'civicrm/contact/view/note',
-          'qs' => 'action=view&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
-          'title' => ts('View Comment'),
-        ],
-        CRM_Core_Action::UPDATE => [
-          'name' => ts('Edit'),
-          'url' => 'civicrm/contact/view/note',
-          'qs' => 'action=update&reset=1&cid=%%cid%%&id={id}&parentId=%%pid%%&selectedChild=note',
-          'title' => ts('Edit Comment'),
-        ],
-        CRM_Core_Action::DELETE => [
-          'name' => ts('Delete'),
-          'url' => 'civicrm/contact/view/note',
-          'qs' => 'action=delete&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
-          'title' => ts('Delete Comment'),
-        ],
-      ];
-    }
-    return self::$_commentLinks;
+  public static function commentLinks() {
+    return [
+      CRM_Core_Action::VIEW => [
+        'name' => ts('View'),
+        'url' => 'civicrm/contact/view/note',
+        'qs' => 'action=view&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
+        'title' => ts('View Comment'),
+      ],
+      CRM_Core_Action::UPDATE => [
+        'name' => ts('Edit'),
+        'url' => 'civicrm/contact/view/note',
+        'qs' => 'action=update&reset=1&cid=%%cid%%&id={id}&parentId=%%pid%%&selectedChild=note',
+        'title' => ts('Edit Comment'),
+      ],
+      CRM_Core_Action::DELETE => [
+        'name' => ts('Delete'),
+        'url' => 'civicrm/contact/view/note',
+        'qs' => 'action=delete&reset=1&cid=%%cid%%&id={id}&selectedChild=note',
+        'title' => ts('Delete Comment'),
+      ],
+    ];
   }
 
 }