| 1 | <?php |
| 2 | /** |
| 3 | * Test Generated example demonstrating the Survey.create API. |
| 4 | * |
| 5 | * @return array |
| 6 | * API result array |
| 7 | */ |
| 8 | function 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 | ); |
| 15 | |
| 16 | try{ |
| 17 | $result = civicrm_api3('Survey', 'create', $params); |
| 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; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Function returns array of result expected from previous function. |
| 36 | * |
| 37 | * @return array |
| 38 | * API result array |
| 39 | */ |
| 40 | function survey_create_expectedresult() { |
| 41 | |
| 42 | $expectedResult = array( |
| 43 | 'is_error' => 0, |
| 44 | 'version' => 3, |
| 45 | 'count' => 1, |
| 46 | 'id' => 1, |
| 47 | 'values' => array( |
| 48 | '1' => array( |
| 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 | ), |
| 70 | ), |
| 71 | ); |
| 72 | |
| 73 | return $expectedResult; |
| 74 | } |
| 75 | |
| 76 | /* |
| 77 | * This example has been generated from the API test suite. |
| 78 | * The test that created it is called "testCreateSurvey" |
| 79 | * and can be found at: |
| 80 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/SurveyTest.php |
| 81 | * |
| 82 | * You can see the outcome of the API tests at |
| 83 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
| 84 | * |
| 85 | * To Learn about the API read |
| 86 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
| 87 | * |
| 88 | * Browse the api on your own site with the api explorer |
| 89 | * http://MYSITE.ORG/path/to/civicrm/api |
| 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 |
| 96 | */ |