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