INFRA-132 - Remove @static annotation
[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 * File for the CiviCRM APIv3 note functions
30 *
31 * @package CiviCRM_APIv3
32 * @subpackage API_Note
33 *
34 * @copyright CiviCRM LLC (c) 2004-2014
35 * @version $Id: Note.php 30879 2010-11-22 15:45:55Z shot $
36 *
37 */
38
39 /**
40 * Create Note
41 *
42 * This API is used for creating a note.
43 * Required parameters : entity_id AND note
44 *
45 * @param array $params
46 * An associative array of name/value property values of civicrm_note.
47 * {@getfields note_create}
48 *
49 * @return array
50 * API result array
51 * @access public
52 * @example NoteCreate.php Create example
53 *
54 *
55 */
56 function civicrm_api3_note_create($params) {
57 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
58 }
59
60 /**
61 * Adjust Metadata for Create action
62 *
63 * The metadata is used for setting defaults, documentation & validation
64 * @param array $params
65 * Array or parameters determined by getfields.
66 */
67 function _civicrm_api3_note_create_spec(&$params) {
68 $params['entity_table']['api.default'] = "civicrm_contact";
69 $params['modified_date']['api.default'] = "now";
70 $params['note']['api.required'] = 1;
71 $params['entity_id']['api.required'] = 1;
72 }
73
74 /**
75 * Deletes an existing note
76 *
77 * This API is used for deleting a note
78 *
79 * @param array $params
80 * Including id of the note to be deleted.
81 * {@getfields note_delete}
82 *
83 * @return null
84 * @access public
85 */
86 function civicrm_api3_note_delete($params) {
87
88 $result = new CRM_Core_BAO_Note();
89 return $result->del($params['id']) ? civicrm_api3_create_success() : civicrm_api3_create_error('Error while deleting Note');
90 }
91
92 /**
93 * Retrieve a specific note, given a set of input params
94 *
95 * @param array $params
96 * Input parameters.
97 *
98 * @return array
99 * array of properties,
100 * if error an array with an error id and error message
101 * {@getfields note_get}
102 * @access public
103 */
104 function civicrm_api3_note_get($params) {
105
106 return _civicrm_api3_basic_get('CRM_Core_BAO_Note', $params);
107 }
108
109 /**
110 * Adjust Metadata for Get action
111 *
112 * The metadata is used for setting defaults, documentation & validation
113 * @param array $params
114 * Array or parameters determined by getfields.
115 */
116 function _civicrm_api3_note_get_spec(&$params) {
117 $params['entity_table']['api.default'] = "civicrm_contact";
118 }
119
120 /**
121 * Get all descendents of given note
122 *
123 * @param array $params
124 * Associative array; only required 'id' parameter is used.
125 *
126 * @return array
127 * Nested associative array beginning with direct children of given note.
128 */
129 function &civicrm_api3_note_tree_get($params) {
130
131 civicrm_api3_verify_mandatory($params, NULL, array('id'));
132
133 if (!is_numeric($params['id'])) {
134 return civicrm_api3_create_error(ts("Invalid note ID"));
135 }
136 if (!isset($params['max_depth'])) {
137 $params['max_depth'] = 0;
138 }
139 if (!isset($params['snippet'])) {
140 $params['snippet'] = FALSE;
141 }
142 $noteTree = CRM_Core_BAO_Note::getNoteTree($params['id'], $params['max_depth'], $params['snippet']);
143 return civicrm_api3_create_success($noteTree, $params);
144 }