Merge pull request #5550 from civicrm/4.5
[civicrm-core.git] / api / v3 / examples / Survey / Get.php
CommitLineData
6a488035 1<?php
50fb255d 2/**
a828d7b8 3 * Test Generated example demonstrating the Survey.get API.
50fb255d 4 *
50fb255d 5 * @return array
6 * API result array
7 */
8function survey_get_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', 'get', $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_get_expectedresult() {
6a488035 41
fbda92d3 42 $expectedResult = array(
50fb255d 43 'is_error' => 0,
44 'version' => 3,
45 'count' => 1,
46 'id' => 2,
47 'values' => array(
48 '2' => array(
49 'id' => '2',
50 'title' => 'survey title',
51 'activity_type_id' => '30',
52 'instructions' => 'Call people, ask for money',
53 'max_number_of_contacts' => '12',
54 'is_active' => '1',
55 'is_default' => 0,
56 'created_date' => '2013-07-28 08:49:19',
57 'bypass_confirm' => 0,
58 'is_share' => '1',
59 ),
6a488035 60 ),
50fb255d 61 );
6a488035 62
fb32de45 63 return $expectedResult;
6a488035
TO
64}
65
a828d7b8 66/*
50fb255d 67* This example has been generated from the API test suite.
a828d7b8
CW
68* The test that created it is called "testGetSurvey"
69* and can be found at:
69d79249 70* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/SurveyTest.php
6a488035
TO
71*
72* You can see the outcome of the API tests at
69d79249 73* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
74*
75* To Learn about the API read
69d79249 76* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 77*
69d79249 78* Browse the api on your own site with the api explorer
41d4d31f 79* http://MYSITE.ORG/path/to/civicrm/api
6a488035
TO
80*
81* Read more about testing here
82* http://wiki.civicrm.org/confluence/display/CRM/Testing
83*
84* API Standards documentation:
85* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 86*/