Merge pull request #10155 from totten/master-pdf-save2
[civicrm-core.git] / api / v3 / examples / ReportTemplate / Getrows.php
1 <?php
2 /**
3 * Test Generated example demonstrating the ReportTemplate.getrows API.
4 *
5 * Retrieve rows from a report template (optionally providing the instance_id).
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(
14 'metadata' => array(
15 '0' => 'labels',
16 '1' => 'title',
17 ),
18 ),
19 );
20
21 try{
22 $result = civicrm_api3('ReportTemplate', '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 'is_error' => 1,
31 'error_message' => $errorMessage,
32 'error_code' => $errorCode,
33 'error_data' => $errorData,
34 );
35 }
36
37 return $result;
38 }
39
40 /**
41 * Function returns array of result expected from previous function.
42 *
43 * @return array
44 * API result array
45 */
46 function report_template_getrows_expectedresult() {
47
48 $expectedResult = array(
49 'is_error' => 0,
50 'version' => 3,
51 'count' => 2,
52 'values' => array(
53 '0' => array(
54 'civicrm_contact_sort_name' => 'Second Domain',
55 'civicrm_contact_id' => '2',
56 'civicrm_contact_sort_name_link' => '/index.php?q=civicrm/report/contact/detail&amp;reset=1&amp;force=1&amp;id_op=eq&amp;id_value=2',
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&amp;reset=1&amp;force=1&amp;id_op=eq&amp;id_value=1',
63 'civicrm_contact_sort_name_hover' => 'View Contact Detail Report for this contact',
64 ),
65 ),
66 'metadata' => array(
67 'title' => 'ERROR: Title is not Set',
68 'labels' => array(
69 'civicrm_contact_sort_name' => 'Contact Name',
70 ),
71 ),
72 );
73
74 return $expectedResult;
75 }
76
77 /*
78 * This example has been generated from the API test suite.
79 * The test that created it is called "testReportTemplateGetRowsContactSummary"
80 * and can be found at:
81 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ReportTemplateTest.php
82 *
83 * You can see the outcome of the API tests at
84 * https://test.civicrm.org/job/CiviCRM-master-git/
85 *
86 * To Learn about the API read
87 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
88 *
89 * Browse the api on your own site with the api explorer
90 * http://MYSITE.ORG/path/to/civicrm/api
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 */