Merge pull request #5216 from atif-shaikh/CRM-15792
[civicrm-core.git] / api / v3 / examples / Survey / Create.php
CommitLineData
6a488035 1<?php
50fb255d 2/**
a828d7b8 3 * Test Generated example demonstrating the Survey.create API.
50fb255d 4 *
50fb255d 5 * @return array
6 * API result array
7 */
8function survey_create_example() {
9 $params = array(
10 'title' => 'survey title',
11 'activity_type_id' => '30',
12 'max_number_of_contacts' => 12,
13 'instructions' => 'Call people, ask for money',
14 );
6a488035 15
50fb255d 16 try{
a828d7b8 17 $result = civicrm_api3('Survey', 'create', $params);
50fb255d 18 }
19 catch (CiviCRM_API3_Exception $e) {
20 // Handle error here.
21 $errorMessage = $e->getMessage();
22 $errorCode = $e->getErrorCode();
23 $errorData = $e->getExtraParams();
24 return array(
25 'error' => $errorMessage,
26 'error_code' => $errorCode,
27 'error_data' => $errorData,
28 );
29 }
30
31 return $result;
6a488035
TO
32}
33
fb32de45 34/**
50fb255d 35 * Function returns array of result expected from previous function.
36 *
37 * @return array
38 * API result array
6a488035 39 */
50fb255d 40function survey_create_expectedresult() {
6a488035 41
fbda92d3 42 $expectedResult = array(
50fb255d 43 'is_error' => 0,
44 'version' => 3,
45 'count' => 1,
46 'id' => 1,
47 'values' => array(
fbda92d3 48 '1' => array(
50fb255d 49 'id' => '1',
50 'title' => 'survey title',
51 'campaign_id' => '',
52 'activity_type_id' => '30',
53 'recontact_interval' => '',
54 'instructions' => 'Call people, ask for money',
55 'release_frequency' => '',
56 'max_number_of_contacts' => '12',
57 'default_number_of_contacts' => '',
58 'is_active' => '',
59 'is_default' => '',
60 'created_id' => '',
61 'created_date' => '2013-07-28 08:49:19',
62 'last_modified_id' => '',
63 'last_modified_date' => '',
64 'result_id' => '',
65 'bypass_confirm' => '',
66 'thankyou_title' => '',
67 'thankyou_text' => '',
68 'is_share' => '',
69 ),
6a488035 70 ),
50fb255d 71 );
6a488035 72
fb32de45 73 return $expectedResult;
6a488035
TO
74}
75
a828d7b8 76/*
50fb255d 77* This example has been generated from the API test suite.
a828d7b8
CW
78* The test that created it is called "testCreateSurvey"
79* and can be found at:
69d79249 80* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/SurveyTest.php
6a488035
TO
81*
82* You can see the outcome of the API tests at
69d79249 83* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
84*
85* To Learn about the API read
69d79249 86* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 87*
69d79249 88* Browse the api on your own site with the api explorer
41d4d31f 89* http://MYSITE.ORG/path/to/civicrm/api
6a488035
TO
90*
91* Read more about testing here
92* http://wiki.civicrm.org/confluence/display/CRM/Testing
93*
94* API Standards documentation:
95* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 96*/