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