Short array syntax - auto-convert api dir
[civicrm-core.git] / api / v3 / examples / OptionGroup / Create.php
CommitLineData
6a488035 1<?php
50fb255d 2/**
a828d7b8 3 * Test Generated example demonstrating the OptionGroup.create API.
50fb255d 4 *
50fb255d 5 * @return array
6 * API result array
7 */
8function option_group_create_example() {
cf8f0fff 9 $params = [
50fb255d 10 'sequential' => 1,
11 'name' => 'civicrm_event.amount.560',
12 'is_reserved' => 1,
13 'is_active' => 1,
cf8f0fff 14 'api.OptionValue.create' => [
6a488035
TO
15 'label' => 'workshop',
16 'value' => 35,
17 'is_default' => 1,
18 'is_active' => 1,
19 'format.only_id' => 1,
cf8f0fff
CW
20 ],
21 ];
6a488035 22
50fb255d 23 try{
a828d7b8 24 $result = civicrm_api3('OptionGroup', 'create', $params);
50fb255d 25 }
26 catch (CiviCRM_API3_Exception $e) {
27 // Handle error here.
28 $errorMessage = $e->getMessage();
29 $errorCode = $e->getErrorCode();
30 $errorData = $e->getExtraParams();
cf8f0fff 31 return [
5be22f39 32 'is_error' => 1,
33 'error_message' => $errorMessage,
50fb255d 34 'error_code' => $errorCode,
35 'error_data' => $errorData,
cf8f0fff 36 ];
50fb255d 37 }
6a488035 38
50fb255d 39 return $result;
6a488035
TO
40}
41
fb32de45 42/**
50fb255d 43 * Function returns array of result expected from previous function.
44 *
45 * @return array
46 * API result array
6a488035 47 */
50fb255d 48function option_group_create_expectedresult() {
6a488035 49
cf8f0fff 50 $expectedResult = [
50fb255d 51 'is_error' => 0,
52 'version' => 3,
53 'count' => 1,
1d8ee3d6 54 'id' => 92,
cf8f0fff
CW
55 'values' => [
56 '0' => [
1d8ee3d6 57 'id' => '92',
50fb255d 58 'name' => 'civicrm_event.amount.560',
59 'title' => '',
60 'description' => '',
1d8ee3d6 61 'data_type' => '',
50fb255d 62 'is_reserved' => '1',
63 'is_active' => '1',
64 'is_locked' => '',
1d8ee3d6 65 'api.OptionValue.create' => 849,
cf8f0fff
CW
66 ],
67 ],
68 ];
6a488035 69
fb32de45 70 return $expectedResult;
6a488035
TO
71}
72
a828d7b8 73/*
50fb255d 74* This example has been generated from the API test suite.
a828d7b8
CW
75* The test that created it is called "testGetOptionCreateSuccess"
76* and can be found at:
69d79249 77* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/OptionGroupTest.php
6a488035
TO
78*
79* You can see the outcome of the API tests at
69d79249 80* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
81*
82* To Learn about the API read
69d79249 83* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 84*
69d79249 85* Browse the api on your own site with the api explorer
41d4d31f 86* http://MYSITE.ORG/path/to/civicrm/api
6a488035
TO
87*
88* Read more about testing here
89* http://wiki.civicrm.org/confluence/display/CRM/Testing
90*
91* API Standards documentation:
92* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 93*/