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