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