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