Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2015-02-16-17-51-20
[civicrm-core.git] / api / v3 / examples / Profile / Apply.php
1 <?php
2 /**
3 * Test Generated example of using profile apply API.
4 *
5 *
6 * @return array
7 * API result array
8 */
9 function profile_apply_example() {
10 $params = array(
11 'profile_id' => 31,
12 'contact_id' => 3,
13 'first_name' => 'abc2',
14 'last_name' => 'xyz2',
15 'email-Primary' => 'abc2.xyz2@gmail.com',
16 'phone-1-1' => '022 321 826',
17 'country-1' => '1013',
18 'state_province-1' => '1000',
19 );
20
21 try{
22 $result = civicrm_api3('profile', 'apply', $params);
23 }
24 catch (CiviCRM_API3_Exception $e) {
25 // Handle error here.
26 $errorMessage = $e->getMessage();
27 $errorCode = $e->getErrorCode();
28 $errorData = $e->getExtraParams();
29 return array(
30 'error' => $errorMessage,
31 'error_code' => $errorCode,
32 'error_data' => $errorData,
33 );
34 }
35
36 return $result;
37 }
38
39 /**
40 * Function returns array of result expected from previous function.
41 *
42 * @return array
43 * API result array
44 */
45 function profile_apply_expectedresult() {
46
47 $expectedResult = array(
48 'is_error' => 0,
49 'version' => 3,
50 'count' => 11,
51 'values' => array(
52 'contact_type' => 'Individual',
53 'contact_sub_type' => '',
54 'contact_id' => 3,
55 'version' => 3,
56 'debug' => 1,
57 'profile_id' => 31,
58 'first_name' => 'abc2',
59 'last_name' => 'xyz2',
60 'email' => array(
61 '1' => array(
62 'location_type_id' => '1',
63 'is_primary' => 1,
64 'email' => 'abc2.xyz2@gmail.com',
65 ),
66 ),
67 'phone' => array(
68 '2' => array(
69 'location_type_id' => '1',
70 'is_primary' => 1,
71 'phone_type_id' => '1',
72 'phone' => '022 321 826',
73 ),
74 ),
75 'address' => array(
76 '1' => array(
77 'location_type_id' => '1',
78 'is_primary' => 1,
79 'country_id' => '1013',
80 'state_province_id' => '1000',
81 ),
82 ),
83 ),
84 );
85
86 return $expectedResult;
87 }
88
89 /**
90 * This example has been generated from the API test suite.
91 * The test that created it is called
92 * testProfileApply
93 * and can be found in
94 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ProfileTest.php
95 *
96 * You can see the outcome of the API tests at
97 * https://test.civicrm.org/job/CiviCRM-master-git/
98 *
99 * To Learn about the API read
100 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
101 *
102 * Browse the api on your own site with the api explorer
103 * http://MYSITE.ORG/path/to/civicrm/api
104 *
105 * Read more about testing here
106 * http://wiki.civicrm.org/confluence/display/CRM/Testing
107 *
108 * API Standards documentation:
109 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
110 */