Merge pull request #5046 from totten/master-resolver
[civicrm-core.git] / api / v3 / examples / Website / GetWithMetadata.php
1 <?php
2 /**
3 * Test Generated example of using website get API.
4 *
5 * Demonostrates returning field metadata
6 *
7 * @return array
8 * API result array
9 */
10 function website_get_example() {
11 $params = array(
12 'options' => array(
13 'metadata' => array(
14 '0' => 'fields',
15 ),
16 ),
17 );
18
19 try{
20 $result = civicrm_api3('website', 'get', $params);
21 }
22 catch (CiviCRM_API3_Exception $e) {
23 // Handle error here.
24 $errorMessage = $e->getMessage();
25 $errorCode = $e->getErrorCode();
26 $errorData = $e->getExtraParams();
27 return array(
28 'error' => $errorMessage,
29 'error_code' => $errorCode,
30 'error_data' => $errorData,
31 );
32 }
33
34 return $result;
35 }
36
37 /**
38 * Function returns array of result expected from previous function.
39 *
40 * @return array
41 * API result array
42 */
43 function website_get_expectedresult() {
44
45 $expectedResult = array(
46 'is_error' => 0,
47 'version' => 3,
48 'count' => 0,
49 'values' => array(),
50 'metadata' => array(
51 'fields' => array(
52 'id' => array(
53 'name' => 'id',
54 'type' => '1',
55 'title' => 'Website ID',
56 'required' => '1',
57 'api.aliases' => array(
58 '0' => 'website_id',
59 ),
60 ),
61 'contact_id' => array(
62 'name' => 'contact_id',
63 'type' => '1',
64 'title' => 'Contact',
65 'FKClassName' => 'CRM_Contact_DAO_Contact',
66 'FKApiName' => 'Contact',
67 ),
68 'url' => array(
69 'name' => 'url',
70 'type' => '2',
71 'title' => 'Website',
72 'maxlength' => '128',
73 'size' => '30',
74 'import' => '1',
75 'where' => 'civicrm_website.url',
76 'headerPattern' => '/Website/i',
77 'dataPattern' => '/^[A-Za-z][0-9A-Za-z]{20,}$/',
78 'export' => '1',
79 'html' => array(
80 'type' => 'Text',
81 ),
82 ),
83 'website_type_id' => array(
84 'name' => 'website_type_id',
85 'type' => '1',
86 'title' => 'Website Type',
87 'html' => array(
88 'type' => 'Select',
89 ),
90 'pseudoconstant' => array(
91 'optionGroupName' => 'website_type',
92 ),
93 ),
94 ),
95 ),
96 );
97
98 return $expectedResult;
99 }
100
101 /**
102 * This example has been generated from the API test suite.
103 * The test that created it is called
104 * testGetMetadata
105 * and can be found in
106 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/WebsiteTest.php
107 *
108 * You can see the outcome of the API tests at
109 * https://test.civicrm.org/job/CiviCRM-master-git/
110 *
111 * To Learn about the API read
112 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
113 *
114 * Browse the api on your own site with the api explorer
115 * http://MYSITE.ORG/path/to/civicrm/api
116 *
117 * Read more about testing here
118 * http://wiki.civicrm.org/confluence/display/CRM/Testing
119 *
120 * API Standards documentation:
121 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
122 */