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