24c4467ddd2a3dcdf5be2222243343d775730cfa
[civicrm-core.git] / api / v3 / examples / Website / GetWithMetadata.php
1 <?php
2 /**
3 * Test Generated example demonstrating the 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 'is_error' => 1,
29 'error_message' => $errorMessage,
30 'error_code' => $errorCode,
31 'error_data' => $errorData,
32 );
33 }
34
35 return $result;
36 }
37
38 /**
39 * Function returns array of result expected from previous function.
40 *
41 * @return array
42 * API result array
43 */
44 function website_get_expectedresult() {
45
46 $expectedResult = array(
47 'is_error' => 0,
48 'version' => 3,
49 'count' => 0,
50 'values' => array(),
51 'metadata' => array(
52 'fields' => array(
53 'id' => array(
54 'name' => 'id',
55 'type' => '1',
56 'title' => 'Website ID',
57 'description' => 'Unique Website ID',
58 'required' => '1',
59 'table_name' => 'civicrm_website',
60 'entity' => 'Website',
61 'bao' => 'CRM_Core_BAO_Website',
62 'api.aliases' => array(
63 '0' => 'website_id',
64 ),
65 ),
66 'contact_id' => array(
67 'name' => 'contact_id',
68 'type' => '1',
69 'title' => 'Contact',
70 'description' => 'FK to Contact ID',
71 'table_name' => 'civicrm_website',
72 'entity' => 'Website',
73 'bao' => 'CRM_Core_BAO_Website',
74 'FKClassName' => 'CRM_Contact_DAO_Contact',
75 'FKApiName' => 'Contact',
76 ),
77 'url' => array(
78 'name' => 'url',
79 'type' => '2',
80 'title' => 'Website',
81 'description' => 'Website',
82 'maxlength' => '128',
83 'size' => '30',
84 'import' => '1',
85 'where' => 'civicrm_website.url',
86 'headerPattern' => '/Website/i',
87 'dataPattern' => '/^[A-Za-z][0-9A-Za-z]{20,}$/',
88 'export' => '1',
89 'table_name' => 'civicrm_website',
90 'entity' => 'Website',
91 'bao' => 'CRM_Core_BAO_Website',
92 'html' => array(
93 'type' => 'Text',
94 'maxlength' => '128',
95 'size' => '30',
96 ),
97 ),
98 'website_type_id' => array(
99 'name' => 'website_type_id',
100 'type' => '1',
101 'title' => 'Website Type',
102 'description' => 'Which Website type does this website belong to.',
103 'table_name' => 'civicrm_website',
104 'entity' => 'Website',
105 'bao' => 'CRM_Core_BAO_Website',
106 'html' => array(
107 'type' => 'Select',
108 'size' => '6',
109 'maxlength' => '14',
110 ),
111 'pseudoconstant' => array(
112 'optionGroupName' => 'website_type',
113 'optionEditPath' => 'civicrm/admin/options/website_type',
114 ),
115 ),
116 ),
117 ),
118 );
119
120 return $expectedResult;
121 }
122
123 /*
124 * This example has been generated from the API test suite.
125 * The test that created it is called "testGetMetadata"
126 * and can be found at:
127 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/WebsiteTest.php
128 *
129 * You can see the outcome of the API tests at
130 * https://test.civicrm.org/job/CiviCRM-master-git/
131 *
132 * To Learn about the API read
133 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
134 *
135 * Browse the api on your own site with the api explorer
136 * http://MYSITE.ORG/path/to/civicrm/api
137 *
138 * Read more about testing here
139 * http://wiki.civicrm.org/confluence/display/CRM/Testing
140 *
141 * API Standards documentation:
142 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
143 */