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 | ||
45 | require_once 'CRM/Core/BAO/Note.php'; | |
46 | ||
47 | /** | |
48 | * Create Note | |
49 | * | |
50 | * This API is used for creating a note. | |
51 | * Required parameters : entity_id AND note | |
52 | * | |
53 | * @param array $params an associative array of name/value property values of civicrm_note | |
54 | * {@getfields note_create} | |
55 | * | |
56 | * @return array API result array | |
57 | * @access public | |
58 | * @example NoteCreate.php Create example | |
59 | * | |
60 | * | |
61 | */ | |
62 | function civicrm_api3_note_create($params) { | |
63 | ||
64 | $ids = array(); | |
65 | $ids = array('id' => CRM_Utils_Array::value('id', $params)); | |
66 | $noteBAO = CRM_Core_BAO_Note::add($params, $ids); | |
67 | ||
68 | if (is_a($noteBAO, 'CRM_Core_Error')) { | |
69 | $error = civicrm_api3_create_error("Note could not be created"); | |
70 | return $error; | |
71 | } | |
72 | else { | |
73 | $note = array(); | |
74 | _civicrm_api3_object_to_array($noteBAO, $note[$noteBAO->id]); | |
75 | } | |
76 | $result = civicrm_api3_create_success($note, $params); | |
77 | return civicrm_api3_create_success($note, $params); | |
78 | } | |
11e09c59 TO |
79 | |
80 | /** | |
6a488035 TO |
81 | * Adjust Metadata for Create action |
82 | * | |
83 | * The metadata is used for setting defaults, documentation & validation | |
84 | * @param array $params array or parameters determined by getfields | |
85 | */ | |
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; | |
91 | } | |
92 | ||
93 | /** | |
94 | * Deletes an existing note | |
95 | * | |
96 | * This API is used for deleting a note | |
97 | * | |
98 | * @params array $paramsarray including id of the note to be deleted | |
99 | * {@getfields note_delete} | |
100 | * | |
101 | * @return null | |
102 | * @access public | |
103 | */ | |
104 | function civicrm_api3_note_delete($params) { | |
105 | ||
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'); | |
108 | } | |
109 | ||
110 | /** | |
111 | * Retrieve a specific note, given a set of input params | |
112 | * | |
113 | * @param array $params input parameters | |
114 | * | |
115 | * @return array array of properties, | |
116 | * if error an array with an error id and error message | |
117 | * {@getfields note_get} | |
118 | * @static void | |
119 | * @access public | |
120 | */ | |
121 | function civicrm_api3_note_get($params) { | |
122 | ||
123 | return _civicrm_api3_basic_get('CRM_Core_BAO_Note', $params); | |
124 | } | |
11e09c59 TO |
125 | |
126 | /** | |
6a488035 TO |
127 | * Adjust Metadata for Get action |
128 | * | |
129 | * The metadata is used for setting defaults, documentation & validation | |
130 | * @param array $params array or parameters determined by getfields | |
131 | */ | |
132 | function _civicrm_api3_note_get_spec(&$params) { | |
133 | $params['entity_table']['api.default'] = "civicrm_contact"; | |
134 | } | |
135 | ||
136 | /** | |
137 | * Get all descendents of given note | |
138 | * | |
139 | * @param array $params Associative array; only required 'id' parameter is used | |
140 | * | |
141 | * @return array Nested associative array beginning with direct children of given note. | |
142 | */ | |
143 | function &civicrm_api3_note_tree_get($params) { | |
144 | ||
145 | civicrm_api3_verify_mandatory($params, NULL, array('id')); | |
146 | ||
147 | if (!is_numeric($params['id'])) { | |
148 | return civicrm_api3_create_error(ts("Invalid note ID")); | |
149 | } | |
150 | if (!isset($params['max_depth'])) { | |
151 | $params['max_depth'] = 0; | |
152 | } | |
153 | if (!isset($params['snippet'])) { | |
154 | $params['snippet'] = FALSE; | |
155 | } | |
156 | $noteTree = CRM_Core_BAO_Note::getNoteTree($params['id'], $params['max_depth'], $params['snippet']); | |
157 | return civicrm_api3_create_success($noteTree, $params); | |
158 | } | |
159 |