5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
31 * File for the CiviCRM APIv3 note functions
33 * @package CiviCRM_APIv3
34 * @subpackage API_Note
36 * @copyright CiviCRM LLC (c) 2004-2013
37 * @version $Id: Note.php 30879 2010-11-22 15:45:55Z shot $
42 * Files required for this package
45 require_once 'CRM/Core/BAO/Note.php';
50 * This API is used for creating a note.
51 * Required parameters : entity_id AND note
53 * @param array $params an associative array of name/value property values of civicrm_note
54 * {@getfields note_create}
56 * @return array API result array
58 * @example NoteCreate.php Create example
62 function civicrm_api3_note_create($params) {
65 $ids = array('id' => CRM_Utils_Array
::value('id', $params));
66 $noteBAO = CRM_Core_BAO_Note
::add($params, $ids);
68 if (is_a($noteBAO, 'CRM_Core_Error')) {
69 $error = civicrm_api3_create_error("Note could not be created");
74 _civicrm_api3_object_to_array($noteBAO, $note[$noteBAO->id
]);
76 $result = civicrm_api3_create_success($note, $params);
77 return civicrm_api3_create_success($note, $params);
81 * Adjust Metadata for Create action
83 * The metadata is used for setting defaults, documentation & validation
84 * @param array $params array or parameters determined by getfields
86 function _civicrm_api3_note_create_spec(&$params) {
87 $params['entity_table']['api.default'] = "civicrm_contact";
88 $params['modified_date']['api.default'] = "now";
89 $params['note']['api.required'] = 1;
90 $params['entity_id']['api.required'] = 1;
94 * Deletes an existing note
96 * This API is used for deleting a note
98 * @params array $paramsarray including id of the note to be deleted
99 * {@getfields note_delete}
104 function civicrm_api3_note_delete($params) {
106 $result = new CRM_Core_BAO_Note();
107 return $result->del($params['id']) ?
civicrm_api3_create_success() : civicrm_api3_create_error('Error while deleting Note');
111 * Retrieve a specific note, given a set of input params
113 * @param array $params input parameters
115 * @return array array of properties,
116 * if error an array with an error id and error message
117 * {@getfields note_get}
121 function civicrm_api3_note_get($params) {
123 return _civicrm_api3_basic_get('CRM_Core_BAO_Note', $params);
127 * Adjust Metadata for Get action
129 * The metadata is used for setting defaults, documentation & validation
130 * @param array $params array or parameters determined by getfields
132 function _civicrm_api3_note_get_spec(&$params) {
133 $params['entity_table']['api.default'] = "civicrm_contact";
137 * Get all descendents of given note
139 * @param array $params Associative array; only required 'id' parameter is used
141 * @return array Nested associative array beginning with direct children of given note.
143 function &civicrm_api3_note_tree_get($params) {
145 civicrm_api3_verify_mandatory($params, NULL, array('id'));
147 if (!is_numeric($params['id'])) {
148 return civicrm_api3_create_error(ts("Invalid note ID"));
150 if (!isset($params['max_depth'])) {
151 $params['max_depth'] = 0;
153 if (!isset($params['snippet'])) {
154 $params['snippet'] = FALSE;
156 $noteTree = CRM_Core_BAO_Note
::getNoteTree($params['id'], $params['max_depth'], $params['snippet']);
157 return civicrm_api3_create_success($noteTree, $params);