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