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