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