Merge pull request #5192 from colemanw/CRM-15988
[civicrm-core.git] / api / v3 / examples / Website / GetWithMetadata.php
CommitLineData
dc5a7701 1<?php
50fb255d 2/**
a828d7b8 3 * Test Generated example demonstrating the Website.get API.
50fb255d 4 *
5 * Demonostrates returning field metadata
6 *
7 * @return array
8 * API result array
9 */
10function website_get_example() {
11 $params = array(
12 'options' => array(
dc5a7701 13 'metadata' => array(
50fb255d 14 '0' => 'fields',
15 ),
dc5a7701 16 ),
50fb255d 17 );
dc5a7701 18
50fb255d 19 try{
a828d7b8 20 $result = civicrm_api3('Website', 'get', $params);
50fb255d 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 }
dc5a7701 33
50fb255d 34 return $result;
dc5a7701
E
35}
36
37/**
50fb255d 38 * Function returns array of result expected from previous function.
39 *
40 * @return array
41 * API result array
dc5a7701 42 */
50fb255d 43function website_get_expectedresult() {
dc5a7701
E
44
45 $expectedResult = array(
50fb255d 46 'is_error' => 0,
47 'version' => 3,
48 'count' => 0,
49 'values' => array(),
50 'metadata' => array(
dc5a7701 51 'fields' => array(
50fb255d 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 ),
dc5a7701 60 ),
50fb255d 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 ),
dc5a7701 95 ),
50fb255d 96 );
dc5a7701
E
97
98 return $expectedResult;
99}
100
a828d7b8 101/*
50fb255d 102* This example has been generated from the API test suite.
a828d7b8
CW
103* The test that created it is called "testGetMetadata"
104* and can be found at:
69d79249 105* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/WebsiteTest.php
dc5a7701
E
106*
107* You can see the outcome of the API tests at
69d79249 108* https://test.civicrm.org/job/CiviCRM-master-git/
dc5a7701
E
109*
110* To Learn about the API read
69d79249 111* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
dc5a7701 112*
69d79249 113* Browse the api on your own site with the api explorer
41d4d31f 114* http://MYSITE.ORG/path/to/civicrm/api
dc5a7701
E
115*
116* Read more about testing here
117* http://wiki.civicrm.org/confluence/display/CRM/Testing
118*
119* API Standards documentation:
120* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
121*/