X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FCore%2FBAO%2FNote.php;h=038dbf77447c936bcd1448192ae887ec99c40a47;hb=945f423dcc24c233767fc77be9f9bb2d3e4b7a8d;hp=65449e02966bfd36e99113542a424a7976c53b2d;hpb=681aa547248b9c7d92d368f4879f75f941eba90b;p=civicrm-core.git diff --git a/CRM/Core/BAO/Note.php b/CRM/Core/BAO/Note.php index 65449e0296..038dbf7744 100644 --- a/CRM/Core/BAO/Note.php +++ b/CRM/Core/BAO/Note.php @@ -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. | | | @@ -23,12 +23,12 @@ | 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; @@ -47,11 +47,12 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note { /** * Given a note id, retrieve the note text * - * @param int $id id of the note to retrieve + * @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'); @@ -60,11 +61,12 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note { /** * Given a note id, retrieve the note subject * - * @param int $id id of the note to retrieve + * @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'); @@ -73,11 +75,12 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note { /** * Given a note id, decide if the note should be displayed based on privacy setting * - * @param object $note Either the id of the note to retrieve, or the CRM_Core_DAO_Note object itself + * @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')) { @@ -122,19 +125,21 @@ 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 * pairs * - * @param array $params (reference) an assoc array of name/value pairs - * @param array $ids (deprecated) associated array with note id - preferably set $params['id'] + * @param array $params + * (reference) an assoc array of name/value pairs. + * @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; @@ -213,12 +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 + * @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 @@ -232,19 +237,22 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note { * Given the list of params in the params array, fetch the object * and store the values in the values array * - * @param array $params input parameters to find object - * @param array $values output values of the object - * @param int $numNotes the maximum number of notes to return (0 if all) + * @param array $params + * Input parameters to find object. + * @param array $values + * Output values of the object. + * @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 @@ -273,18 +281,20 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note { } /** - * Delete the notes + * Delete the notes. * - * @param int $id note id - * @param boolean $showStatus do we need to set status or not + * @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(); @@ -322,19 +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. + * @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 @@ -346,13 +356,14 @@ class CRM_Core_BAO_Note extends CRM_Core_DAO_Note { /** * Retrieve all records for this entity-id * - * @param int $id ID of the relationship for which records needs to be retrieved. + * @param int $id + * ID of the relationship for which records needs to be retrieved. * * @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(); @@ -377,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; @@ -400,33 +411,37 @@ 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 - * @param int $maxDepth Maximum number of levels to descend into the tree; if not given, will include all descendents. - * @param bool $snippet If TRUE, returned values will be pre-formatted for display in a table of notes. + * @param int $parentId + * ID of the note to start from. + * @param int $maxDepth + * Maximum number of levels to descend into the tree; if not given, will include all descendents. + * @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 + * @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()) { @@ -438,26 +453,31 @@ ORDER BY modified_date desc"; } /** - * Recursive function to get all descendent notes of the note with given ID - * - * @param int $parentId ID of the note to start from - * @param int $maxDepth Maximum number of levels to descend into the tree; if not given, will include all descendents. - * @param bool $snippet If TRUE, returned values will be pre-formatted for display in a table of notes. - * @param array $tree (Reference) Variable to store all found descendents - * @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 + * Recursive function to get all descendent notes of the note with given ID. + * + * @param int $parentId + * ID of the note to start from. + * @param int $maxDepth + * Maximum number of levels to descend into the tree; if not given, will include all descendents. + * @param bool $snippet + * If TRUE, returned values will be pre-formatted for display in a table of notes. + * @param array $tree + * (Reference) Variable to store all found descendents. + * @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. */ private static function buildNoteTree($parentId, $maxDepth = 0, $snippet = FALSE, &$tree = array(), $depth = 0) { if ($maxDepth && $depth > $maxDepth) { - return false; + return FALSE; } // 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()) { @@ -466,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(); @@ -505,16 +525,19 @@ ORDER BY modified_date desc"; /** * Given a note id, get a list of the ids of all notes that are descendents of that note * - * @param int $parentId Id of the given note - * @param array $ids (reference) one-dimensional array to store found descendent ids + * @param int $parentId + * Id of the given note. + * @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 @@ -525,12 +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 + * @param int $contactID + * Contact id whose notes to be deleted. * * @return void - * @static */ public static function cleanContactNotes($contactID) { $params = array(1 => array($contactID, 'Integer')); @@ -557,5 +580,5 @@ WHERE participant.contact_id = %1 AND note.entity_table = 'civicrm_participant' self::del($contactNoteId->id, FALSE); } } -} +}