Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
a30c801b | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
a30c801b TO |
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 | | |
6a488035 TO |
9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
12 | /** | |
b081365f CW |
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. | |
6a488035 TO |
18 | * |
19 | * @package CiviCRM_APIv3 | |
6a488035 TO |
20 | */ |
21 | ||
6a488035 | 22 | /** |
2e66abf8 | 23 | * Create or update a survey. |
6a488035 | 24 | * |
cf470720 | 25 | * @param array $params |
2e66abf8 | 26 | * Array per getfields metadata. |
6a488035 | 27 | * |
a6c01b45 | 28 | * @return array |
72b3a70c | 29 | * api result array |
6a488035 TO |
30 | */ |
31 | function civicrm_api3_survey_create($params) { | |
bf38705f | 32 | return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'Survey'); |
6a488035 | 33 | } |
11e09c59 TO |
34 | |
35 | /** | |
0aa0303c EM |
36 | * Adjust Metadata for Create action. |
37 | * | |
38 | * The metadata is used for setting defaults, documentation & validation. | |
6a488035 | 39 | * |
cf470720 | 40 | * @param array $params |
b081365f | 41 | * Array of parameters determined by getfields. |
6a488035 TO |
42 | */ |
43 | function _civicrm_api3_survey_create_spec(&$params) { | |
44 | $params['title']['api.required'] = 1; | |
45 | } | |
46 | ||
47 | /** | |
2e66abf8 | 48 | * Returns array of surveys matching a set of one or more group properties. |
6a488035 | 49 | * |
cf470720 | 50 | * @param array $params |
b081365f | 51 | * Array of properties. If empty, all records will be returned. |
6a488035 | 52 | * |
a6c01b45 | 53 | * @return array |
72b3a70c | 54 | * API result Array of matching surveys |
6a488035 TO |
55 | */ |
56 | function civicrm_api3_survey_get($params) { | |
bf38705f | 57 | return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, TRUE, 'Survey'); |
6a488035 TO |
58 | } |
59 | ||
60 | /** | |
2e66abf8 | 61 | * Delete an existing survey. |
6a488035 | 62 | * |
244bbdd8 | 63 | * This method is used to delete any existing survey given its id. |
6a488035 | 64 | * |
cf470720 | 65 | * @param array $params |
c28e1768 | 66 | * [id] |
6a488035 | 67 | * |
a6c01b45 | 68 | * @return array |
72b3a70c | 69 | * api result array |
6a488035 TO |
70 | */ |
71 | function civicrm_api3_survey_delete($params) { | |
72 | return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params); | |
73 | } | |
b233e1b4 CW |
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) { | |
cf8f0fff CW |
85 | return [ |
86 | 'description_field' => [ | |
b233e1b4 | 87 | 'campaign_id', |
cf8f0fff CW |
88 | ], |
89 | 'params' => [ | |
b233e1b4 | 90 | 'is_active' => 1, |
cf8f0fff CW |
91 | ], |
92 | ]; | |
b233e1b4 | 93 | } |