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