CRM-16367 (Backoffice Contribution Form) centralisation & testing of setting premium...
[civicrm-core.git] / CRM / Core / BAO / Note.php
index 557f5cedcf0285b935279296d50ab114c3728c86..038dbf77447c936bcd1448192ae887ec99c40a47 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -39,7 +39,7 @@
 class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
 
   /**
-   * Const the max number of notes we display at any given time
+   * Const the max number of notes we display at any given time.
    * @var int
    */
   const MAX_NOTES = 3;
@@ -50,9 +50,9 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
    * @param int $id
    *   Id of the note to retrieve.
    *
-   * @return string   the note text or NULL if note not found
+   * @return string
+   *   the note text or NULL if note not found
    *
-   * @static
    */
   public static function getNoteText($id) {
     return CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Note', $id, 'note');
@@ -64,9 +64,9 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
    * @param int $id
    *   Id of the note to retrieve.
    *
-   * @return string   the note subject or NULL if note not found
+   * @return string
+   *   the note subject or NULL if note not found
    *
-   * @static
    */
   public static function getNoteSubject($id) {
     return CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Note', $id, 'subject');
@@ -78,9 +78,9 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
    * @param object $note
    *   Either the id of the note to retrieve, or the CRM_Core_DAO_Note object itself.
    *
-   * @return boolean TRUE if the note should be displayed, otherwise FALSE
+   * @return bool
+   *   TRUE if the note should be displayed, otherwise FALSE
    *
-   * @static
    */
   public static function getNotePrivacyHidden($note) {
     if (CRM_Core_Permission::check('view all notes')) {
@@ -125,7 +125,7 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
   }
 
   /**
-   * Takes an associative array and creates a note object
+   * Takes an associative array and creates a note object.
    *
    * the function extract all the params it needs to initialize the create a
    * note object. the params array could contain additional unused name/value
@@ -136,10 +136,10 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
    * @param array $ids
    *   (deprecated) associated array with note id - preferably set $params['id'].
    *
-   * @return object $note CRM_Core_BAO_Note object
-   * @static
+   * @return object
+   *   $note CRM_Core_BAO_Note object
    */
-  public static function &add(&$params, $ids = array()) {
+  public static function add(&$params, $ids = array()) {
     $dataExists = self::dataExists($params);
     if (!$dataExists) {
       return CRM_Core_DAO::$_nullObject;
@@ -218,13 +218,12 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
   }
 
   /**
-   * Check if there is data to create the object
+   * Check if there is data to create the object.
    *
    * @param array $params
    *   (reference ) an assoc array of name/value pairs.
    *
-   * @return boolean
-   * @static
+   * @return bool
    */
   public static function dataExists(&$params) {
     // return if no data present
@@ -245,15 +244,15 @@ 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
-   * @static
+   * @return object
+   *   $notes  Object of CRM_Core_BAO_Note
    */
   public static function &getValues(&$params, &$values, $numNotes = self::MAX_NOTES) {
     if (empty($params)) {
       return NULL;
     }
-    $note               = new CRM_Core_BAO_Note();
-    $note->entity_id    = $params['contact_id'];
+    $note = new CRM_Core_BAO_Note();
+    $note->entity_id = $params['contact_id'];
     $note->entity_table = 'civicrm_contact';
 
     // get the total count of notes
@@ -282,20 +281,20 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
   }
 
   /**
-   * Delete the notes
+   * Delete the notes.
    *
    * @param int $id
    *   Note id.
    * @param bool $showStatus
    *   Do we need to set status or not.
    *
-   * @return mixed|NULL $return no of deleted notes on success, FALSE otherwise@access public
-   * @static
+   * @return int|NULL
+   *   no of deleted notes on success, null otherwise
    */
   public static function del($id, $showStatus = TRUE) {
-    $return   = NULL;
-    $recent   = array($id);
-    $note     = new CRM_Core_DAO_Note();
+    $return = NULL;
+    $recent = array($id);
+    $note = new CRM_Core_DAO_Note();
     $note->id = $id;
     $note->find();
     $note->fetch();
@@ -333,20 +332,19 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
   }
 
   /**
-   * Delete all records for this contact id
+   * Delete all records for this contact id.
    *
    * @param int $id
    *   ID of the contact for which note needs to be deleted.
    *
    * @return void
    *
-   * @static
    */
   public static function deleteContact($id) {
     // need to delete for both entity_id
-    $dao               = new CRM_Core_DAO_Note();
+    $dao = new CRM_Core_DAO_Note();
     $dao->entity_table = 'civicrm_contact';
-    $dao->entity_id    = $id;
+    $dao->entity_id = $id;
     $dao->delete();
 
     // and the creator contact id
@@ -363,9 +361,9 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note {
    *
    * @param string $entityTable
    *
-   * @return array $viewNote array of note properties
+   * @return array
+   *   array of note properties
    *
-   * @static
    */
   public static function &getNote($id, $entityTable = 'civicrm_relationship') {
     $viewNote = array();
@@ -390,17 +388,17 @@ ORDER BY  modified_date desc";
   }
 
   /**
-   * Get log record count for a Contact
+   * Get log record count for a Contact.
    *
    * @param int $contactID
    *
-   * @return int $count count of log records
+   * @return int
+   *   $count count of log records
    *
-   * @static
    */
   public static function getContactNoteCount($contactID) {
-    $note               = new CRM_Core_DAO_Note();
-    $note->entity_id    = $contactID;
+    $note = new CRM_Core_DAO_Note();
+    $note->entity_id = $contactID;
     $note->entity_table = 'civicrm_contact';
     $note->find();
     $count = 0;
@@ -413,7 +411,7 @@ ORDER BY  modified_date desc";
   }
 
   /**
-   * Get all descendent notes of the note with given ID
+   * Get all descendent notes of the note with given ID.
    *
    * @param int $parentId
    *   ID of the note to start from.
@@ -422,28 +420,28 @@ ORDER BY  modified_date desc";
    * @param bool $snippet
    *   If TRUE, returned values will be pre-formatted for display in a table of notes.
    *
-   * @return array Nested associative array beginning with direct children of given note.
+   * @return array
+   *   Nested associative array beginning with direct children of given note.
    *
-   * @static
    */
   public static function getNoteTree($parentId, $maxDepth = 0, $snippet = FALSE) {
     return self::buildNoteTree($parentId, $maxDepth, $snippet);
   }
 
   /**
-   * Get total count of direct children visible to the current user
+   * Get total count of direct children visible to the current user.
    *
    * @param int $id
    *   Note ID.
    *
-   * @return int $count Number of notes having the give note as parent
+   * @return int
+   *   $count Number of notes having the give note as parent
    *
-   * @static
    */
   public static function getChildCount($id) {
-    $note               = new CRM_Core_DAO_Note();
+    $note = new CRM_Core_DAO_Note();
     $note->entity_table = 'civicrm_note';
-    $note->entity_id    = $id;
+    $note->entity_id = $id;
     $note->find();
     $count = 0;
     while ($note->fetch()) {
@@ -455,7 +453,7 @@ ORDER BY  modified_date desc";
   }
 
   /**
-   * Recursive function to get all descendent notes of the note with given ID
+   * Recursive function to get all descendent notes of the note with given ID.
    *
    * @param int $parentId
    *   ID of the note to start from.
@@ -468,8 +466,8 @@ ORDER BY  modified_date desc";
    * @param int $depth
    *   Depth of current iteration within the descendent tree (used for comparison against maxDepth).
    *
-   * @return array Nested associative array beginning with direct children of given note.
-   * @static
+   * @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) {
     if ($maxDepth && $depth > $maxDepth) {
@@ -477,9 +475,9 @@ ORDER BY  modified_date desc";
     }
 
     // get direct children of given parentId note
-    $note               = new CRM_Core_DAO_Note();
+    $note = new CRM_Core_DAO_Note();
     $note->entity_table = 'civicrm_note';
-    $note->entity_id    = $parentId;
+    $note->entity_id = $parentId;
     $note->orderBy('modified_date asc');
     $note->find();
     while ($note->fetch()) {
@@ -488,7 +486,7 @@ ORDER BY  modified_date desc";
         CRM_Core_DAO::storeValues($note, $tree[$note->id]);
 
         // get name of user that created this note
-        $contact     = new CRM_Contact_DAO_Contact();
+        $contact = new CRM_Contact_DAO_Contact();
         $createdById = $note->contact_id;
         $contact->id = $createdById;
         $contact->find();
@@ -532,13 +530,14 @@ ORDER BY  modified_date desc";
    * @param array $ids
    *   (reference) one-dimensional array to store found descendent ids.
    *
-   * @return array $ids One-dimensional array containing ids of all desendent notes
+   * @return array
+   *   One-dimensional array containing ids of all desendent notes
    */
   public static function getDescendentIds($parentId, &$ids = array()) {
     // get direct children of given parentId note
-    $note               = new CRM_Core_DAO_Note();
+    $note = new CRM_Core_DAO_Note();
     $note->entity_table = 'civicrm_note';
-    $note->entity_id    = $parentId;
+    $note->entity_id = $parentId;
     $note->find();
     while ($note->fetch()) {
       // foreach child, add to ids list, and recurse
@@ -549,13 +548,12 @@ ORDER BY  modified_date desc";
   }
 
   /**
-   * Delete all note related to contact when contact is deleted
+   * Delete all note related to contact when contact is deleted.
    *
    * @param int $contactID
    *   Contact id whose notes to be deleted.
    *
    * @return void
-   * @static
    */
   public static function cleanContactNotes($contactID) {
     $params = array(1 => array($contactID, 'Integer'));
@@ -582,4 +580,5 @@ WHERE participant.contact_id = %1 AND  note.entity_table = 'civicrm_participant'
       self::del($contactNoteId->id, FALSE);
     }
   }
+
 }