getLoggedInContactID() is a static function
[civicrm-core.git] / CRM / Core / BAO / Note.php
index d210f6b60b50b6c87e3f30ad21f75c4b6e363bc7..c93215d235208acfa61f42e703e0ee12e06541f1 100644 (file)
@@ -35,8 +35,12 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
    * @return string
    *   the note text or NULL if note not found
    *
+   * @throws \CRM_Core_Exception
+   *
+   * @deprecated
    */
   public static function getNoteText($id) {
+    CRM_Core_Error::deprecatedFunctionWarning('unused function');
     return CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Note', $id, 'note');
   }
 
@@ -49,6 +53,7 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
    * @return string
    *   the note subject or NULL if note not found
    *
+   * @throws \CRM_Core_Exception
    */
   public static function getNoteSubject($id) {
     return CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Note', $id, 'subject');
@@ -69,8 +74,8 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
       return FALSE;
     }
 
-    $noteValues = array();
-    if (is_object($note) && get_class($note) == 'CRM_Core_DAO_Note') {
+    $noteValues = [];
+    if (is_object($note) && get_class($note) === 'CRM_Core_DAO_Note') {
       CRM_Core_DAO::storeValues($note, $noteValues);
     }
     else {
@@ -121,7 +126,7 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
    *   $note CRM_Core_BAO_Note object
    * @throws \CRM_Core_Exception
    */
-  public static function add(&$params, $ids = array()) {
+  public static function add(&$params, $ids = []) {
     $dataExists = self::dataExists($params);
     if (!$dataExists) {
       return NULL;
@@ -145,7 +150,7 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
         $note->contact_id = $params['entity_id'];
       }
     }
-    $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('id', $ids));
+    $id = $params['id'] ?? $ids['id'] ?? NULL;
     if ($id) {
       $note->id = $id;
     }
@@ -164,7 +169,7 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
 
       $noteActions = FALSE;
 
-      $loggedInContactID = CRM_Core_Session::singleton()->getLoggedInContactID();
+      $loggedInContactID = CRM_Core_Session::getLoggedInContactID();
       if ($loggedInContactID) {
         if ($loggedInContactID == $note->entity_id) {
           $noteActions = TRUE;
@@ -174,7 +179,7 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
         }
       }
 
-      $recentOther = array();
+      $recentOther = [];
       if ($noteActions) {
         $recentOther = array(
           'editUrl' => CRM_Utils_System::url('civicrm/contact/view/note',
@@ -229,8 +234,7 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
    * @param int $numNotes
    *   The maximum number of notes to return (0 if all).
    *
-   * @return object
-   *   $notes  Object of CRM_Core_BAO_Note
+   * @return array
    */
   public static function &getValues(&$params, &$values, $numNotes = self::MAX_NOTES) {
     if (empty($params)) {
@@ -248,10 +252,10 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
     $note->limit($numNotes);
     $note->find();
 
-    $notes = array();
+    $notes = [];
     $count = 0;
     while ($note->fetch()) {
-      $values['note'][$note->id] = array();
+      $values['note'][$note->id] = [];
       CRM_Core_DAO::storeValues($note, $values['note'][$note->id]);
       $notes[] = $note;
 
@@ -346,7 +350,7 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
    *
    */
   public static function &getNote($id, $entityTable = 'civicrm_relationship') {
-    $viewNote = array();
+    $viewNote = [];
 
     $query = "
   SELECT  id,
@@ -449,7 +453,7 @@ ORDER BY  modified_date desc";
    * @return array
    *   Nested associative array beginning with direct children of given note.
    */
-  private static function buildNoteTree($parentId, $maxDepth = 0, $snippet = FALSE, &$tree = array(), $depth = 0) {
+  private static function buildNoteTree($parentId, $maxDepth = 0, $snippet = FALSE, &$tree = [], $depth = 0) {
     if ($maxDepth && $depth > $maxDepth) {
       return FALSE;
     }
@@ -513,7 +517,7 @@ ORDER BY  modified_date desc";
    * @return array
    *   One-dimensional array containing ids of all desendent notes
    */
-  public static function getDescendentIds($parentId, &$ids = array()) {
+  public static function getDescendentIds($parentId, &$ids = []) {
     // get direct children of given parentId note
     $note = new CRM_Core_DAO_Note();
     $note->entity_table = 'civicrm_note';