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