INFRA-132 - Docblock formatting fixes
[civicrm-core.git] / api / v3 / Note.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.6 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
10 | |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
19 | |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
27 */
28
29 /**
30 * File for the CiviCRM APIv3 note functions
31 *
32 * @package CiviCRM_APIv3
33 * @subpackage API_Note
34 *
35 * @copyright CiviCRM LLC (c) 2004-2014
36 * @version $Id: Note.php 30879 2010-11-22 15:45:55Z shot $
37 *
38 */
39
40 /**
41 * Create Note
42 *
43 * This API is used for creating a note.
44 * Required parameters : entity_id AND note
45 *
46 * @param array $params
47 * An associative array of name/value property values of civicrm_note.
48 * {@getfields note_create}
49 *
50 * @return array
51 * API result array
52 * @access public
53 * @example NoteCreate.php Create example
54 *
55 *
56 */
57 function civicrm_api3_note_create($params) {
58 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
59 }
60
61 /**
62 * Adjust Metadata for Create action
63 *
64 * The metadata is used for setting defaults, documentation & validation
65 * @param array $params
66 * Array or parameters determined by getfields.
67 */
68 function _civicrm_api3_note_create_spec(&$params) {
69 $params['entity_table']['api.default'] = "civicrm_contact";
70 $params['modified_date']['api.default'] = "now";
71 $params['note']['api.required'] = 1;
72 $params['entity_id']['api.required'] = 1;
73 }
74
75 /**
76 * Deletes an existing note
77 *
78 * This API is used for deleting a note
79 *
80 * @param array $params
81 * Including id of the note to be deleted.
82 * {@getfields note_delete}
83 *
84 * @return null
85 * @access public
86 */
87 function civicrm_api3_note_delete($params) {
88
89 $result = new CRM_Core_BAO_Note();
90 return $result->del($params['id']) ? civicrm_api3_create_success() : civicrm_api3_create_error('Error while deleting Note');
91 }
92
93 /**
94 * Retrieve a specific note, given a set of input params
95 *
96 * @param array $params
97 * Input parameters.
98 *
99 * @return array
100 * array of properties,
101 * if error an array with an error id and error message
102 * {@getfields note_get}
103 * @static void
104 * @access public
105 */
106 function civicrm_api3_note_get($params) {
107
108 return _civicrm_api3_basic_get('CRM_Core_BAO_Note', $params);
109 }
110
111 /**
112 * Adjust Metadata for Get action
113 *
114 * The metadata is used for setting defaults, documentation & validation
115 * @param array $params
116 * Array or parameters determined by getfields.
117 */
118 function _civicrm_api3_note_get_spec(&$params) {
119 $params['entity_table']['api.default'] = "civicrm_contact";
120 }
121
122 /**
123 * Get all descendents of given note
124 *
125 * @param array $params
126 * Associative array; only required 'id' parameter is used.
127 *
128 * @return array
129 * Nested associative array beginning with direct children of given note.
130 */
131 function &civicrm_api3_note_tree_get($params) {
132
133 civicrm_api3_verify_mandatory($params, NULL, array('id'));
134
135 if (!is_numeric($params['id'])) {
136 return civicrm_api3_create_error(ts("Invalid note ID"));
137 }
138 if (!isset($params['max_depth'])) {
139 $params['max_depth'] = 0;
140 }
141 if (!isset($params['snippet'])) {
142 $params['snippet'] = FALSE;
143 }
144 $noteTree = CRM_Core_BAO_Note::getNoteTree($params['id'], $params['max_depth'], $params['snippet']);
145 return civicrm_api3_create_success($noteTree, $params);
146 }