Merge pull request #14928 from lcdservices/dev-core-1158
[civicrm-core.git] / api / v3 / Survey.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * This api exposes CiviCRM survey/petition records.
14 *
15 * @note Campaign component must be enabled.
16 * @note There is no "petition" api.
17 * Surveys and petitions are the same basic object and this api is used for both.
18 *
19 * @package CiviCRM_APIv3
20 */
21
22 /**
23 * Create or update a survey.
24 *
25 * @param array $params
26 * Array per getfields metadata.
27 *
28 * @return array
29 * api result array
30 */
31 function civicrm_api3_survey_create($params) {
32 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Survey');
33 }
34
35 /**
36 * Adjust Metadata for Create action.
37 *
38 * The metadata is used for setting defaults, documentation & validation.
39 *
40 * @param array $params
41 * Array of parameters determined by getfields.
42 */
43 function _civicrm_api3_survey_create_spec(&$params) {
44 $params['title']['api.required'] = 1;
45 }
46
47 /**
48 * Returns array of surveys matching a set of one or more group properties.
49 *
50 * @param array $params
51 * Array of properties. If empty, all records will be returned.
52 *
53 * @return array
54 * API result Array of matching surveys
55 */
56 function civicrm_api3_survey_get($params) {
57 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Survey');
58 }
59
60 /**
61 * Delete an existing survey.
62 *
63 * This method is used to delete any existing survey given its id.
64 *
65 * @param array $params
66 * [id]
67 *
68 * @return array
69 * api result array
70 */
71 function civicrm_api3_survey_delete($params) {
72 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
73 }
74
75 /**
76 * Set default getlist parameters.
77 *
78 * @see _civicrm_api3_generic_getlist_defaults
79 *
80 * @param array $request
81 *
82 * @return array
83 */
84 function _civicrm_api3_survey_getlist_defaults(&$request) {
85 return [
86 'description_field' => [
87 'campaign_id',
88 ],
89 'params' => [
90 'is_active' => 1,
91 ],
92 ];
93 }