Commit | Line | Data |
---|---|---|
fee15d2a E |
1 | <?php |
2 | /** | |
3 | * Test Generated example of using report_template getrows API | |
4 | * Retrieve rows from a report template (optionally providing the instance_id) * | |
5 | */ | |
6 | function report_template_getrows_example(){ | |
7 | $params = array( | |
8 | 'report_id' => 'contact/summary', | |
781d91c8 EM |
9 | 'options' => array( |
10 | 'metadata' => array( | |
11 | '0' => 'labels', | |
12 | '1' => 'title', | |
13 | ), | |
14 | ), | |
fee15d2a E |
15 | ); |
16 | ||
17 | try{ | |
18 | $result = civicrm_api3('report_template', 'getrows', $params); | |
19 | } | |
20 | catch (CiviCRM_API3_Exception $e) { | |
21 | // handle error here | |
22 | $errorMessage = $e->getMessage(); | |
23 | $errorCode = $e->getErrorCode(); | |
24 | $errorData = $e->getExtraParams(); | |
25 | return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData); | |
26 | } | |
27 | ||
28 | return $result; | |
29 | } | |
30 | ||
31 | /** | |
32 | * Function returns array of result expected from previous function | |
33 | */ | |
34 | function report_template_getrows_expectedresult(){ | |
35 | ||
36 | $expectedResult = array( | |
37 | 'is_error' => 0, | |
38 | 'version' => 3, | |
39 | 'count' => 2, | |
40 | 'values' => array( | |
41 | '0' => array( | |
42 | 'civicrm_contact_sort_name' => 'Default Organization', | |
43 | 'civicrm_contact_id' => '1', | |
44 | 'civicrm_address_street_address' => '', | |
45 | 'civicrm_address_city' => '', | |
46 | 'civicrm_country_name' => '', | |
47 | ), | |
48 | '1' => array( | |
49 | 'civicrm_contact_sort_name' => 'Second Domain', | |
50 | 'civicrm_contact_id' => '2', | |
51 | 'civicrm_address_street_address' => '15 Main St', | |
52 | 'civicrm_address_city' => 'Collinsville', | |
53 | 'civicrm_country_name' => 'United States', | |
54 | ), | |
55 | ), | |
781d91c8 EM |
56 | 'metadata' => array( |
57 | 'title' => 'ERROR: Title is not Set', | |
58 | 'labels' => array( | |
59 | 'civicrm_contact_sort_name' => 'Contact Name', | |
60 | 'civicrm_contact_id' => 'Internal Contact ID', | |
61 | 'civicrm_address_street_address' => 'Street Address', | |
62 | 'civicrm_address_city' => 'City', | |
63 | 'civicrm_country_name' => 'Country', | |
64 | ), | |
7cab1323 | 65 | ), |
fee15d2a E |
66 | ); |
67 | ||
68 | return $expectedResult; | |
69 | } | |
70 | ||
71 | ||
72 | /* | |
73 | * This example has been generated from the API test suite. The test that created it is called | |
74 | * | |
75 | * testReportTemplateGetRowsContactSummary and can be found in | |
69d79249 | 76 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ReportTemplateTest.php |
fee15d2a E |
77 | * |
78 | * You can see the outcome of the API tests at | |
69d79249 | 79 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
fee15d2a E |
80 | * |
81 | * To Learn about the API read | |
69d79249 | 82 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
fee15d2a | 83 | * |
69d79249 E |
84 | * Browse the api on your own site with the api explorer |
85 | * http://MYSITE.ORG/path/to/civicrm/api/explorer | |
fee15d2a E |
86 | * |
87 | * Read more about testing here | |
88 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
89 | * | |
90 | * API Standards documentation: | |
91 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
92 | */ |