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