Commit | Line | Data |
---|---|---|
fee15d2a | 1 | <?php |
50fb255d | 2 | /** |
a828d7b8 | 3 | * Test Generated example demonstrating the ReportTemplate.getrows API. |
50fb255d | 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{ |
a828d7b8 | 22 | $result = civicrm_api3('ReportTemplate', 'getrows', $params); |
50fb255d | 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( | |
1d8ee3d6 | 30 | 'is_error' => 1, |
31 | 'error_message' => $errorMessage, | |
50fb255d | 32 | 'error_code' => $errorCode, |
33 | 'error_data' => $errorData, | |
34 | ); | |
35 | } | |
fee15d2a | 36 | |
50fb255d | 37 | return $result; |
fee15d2a E |
38 | } |
39 | ||
40 | /** | |
50fb255d | 41 | * Function returns array of result expected from previous function. |
42 | * | |
43 | * @return array | |
44 | * API result array | |
fee15d2a | 45 | */ |
50fb255d | 46 | function report_template_getrows_expectedresult() { |
fee15d2a E |
47 | |
48 | $expectedResult = array( | |
50fb255d | 49 | 'is_error' => 0, |
50 | 'version' => 3, | |
51 | 'count' => 2, | |
52 | 'values' => array( | |
fee15d2a | 53 | '0' => array( |
50fb255d | 54 | 'civicrm_contact_sort_name' => 'Second Domain', |
55 | 'civicrm_contact_id' => '2', | |
c160fde8 | 56 | 'civicrm_contact_sort_name_link' => '/index.php?q=civicrm/report/contact/detail&reset=1&force=1&id_op=eq&id_value=2', |
1d8ee3d6 | 57 | 'civicrm_contact_sort_name_hover' => 'View Contact Detail Report for this contact', |
58 | ), | |
59 | '1' => array( | |
60 | 'civicrm_contact_sort_name' => 'Unit Test Organization', | |
61 | 'civicrm_contact_id' => '1', | |
62 | 'civicrm_contact_sort_name_link' => '/index.php?q=civicrm/report/contact/detail&reset=1&force=1&id_op=eq&id_value=1', | |
63 | 'civicrm_contact_sort_name_hover' => 'View Contact Detail Report for this contact', | |
50fb255d | 64 | ), |
fee15d2a | 65 | ), |
50fb255d | 66 | 'metadata' => array( |
781d91c8 EM |
67 | 'title' => 'ERROR: Title is not Set', |
68 | 'labels' => array( | |
50fb255d | 69 | 'civicrm_contact_sort_name' => 'Contact Name', |
50fb255d | 70 | ), |
7cab1323 | 71 | ), |
50fb255d | 72 | ); |
fee15d2a E |
73 | |
74 | return $expectedResult; | |
75 | } | |
76 | ||
a828d7b8 | 77 | /* |
50fb255d | 78 | * This example has been generated from the API test suite. |
a828d7b8 CW |
79 | * The test that created it is called "testReportTemplateGetRowsContactSummary" |
80 | * and can be found at: | |
69d79249 | 81 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ReportTemplateTest.php |
fee15d2a E |
82 | * |
83 | * You can see the outcome of the API tests at | |
69d79249 | 84 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
fee15d2a E |
85 | * |
86 | * To Learn about the API read | |
69d79249 | 87 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
fee15d2a | 88 | * |
69d79249 | 89 | * Browse the api on your own site with the api explorer |
41d4d31f | 90 | * http://MYSITE.ORG/path/to/civicrm/api |
fee15d2a E |
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 | */ |