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