Merge remote-tracking branch 'upstream/4.5' into 4.5-master-2015-03-03-23-44-14
[civicrm-core.git] / api / v3 / examples / ReportTemplate / Getrows.php
index 298439eca70297b1542afc264d58b81ef8002973..50d64613338d0e724a4f2af91ffdf41d107c9e70 100644 (file)
@@ -1,78 +1,79 @@
 <?php
 /**
- * Test Generated example of using report_template getrows API
- * Retrieve rows from a report template (optionally providing the instance_id) *
+ * Test Generated example demonstrating the ReportTemplate.getrows API.
+ *
+ * Retrieve rows from a report template (optionally providing the instance_id).
+ *
+ * @return array
+ *   API result array
  */
-function report_template_getrows_example(){
-$params = array(
-  'report_id' => 'contact/summary',
-  'options' => array(
+function report_template_getrows_example() {
+  $params = array(
+    'report_id' => 'contact/summary',
+    'options' => array(
       'metadata' => array(
-          '0' => 'labels',
-          '1' => 'title',
-        ),
+        '0' => 'labels',
+        '1' => 'title',
+      ),
     ),
-);
+  );
 
-try{
-  $result = civicrm_api3('report_template', 'getrows', $params);
-}
-catch (CiviCRM_API3_Exception $e) {
-  // handle error here
-  $errorMessage = $e->getMessage();
-  $errorCode = $e->getErrorCode();
-  $errorData = $e->getExtraParams();
-  return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
-}
+  try{
+    $result = civicrm_api3('ReportTemplate', 'getrows', $params);
+  }
+  catch (CiviCRM_API3_Exception $e) {
+    // Handle error here.
+    $errorMessage = $e->getMessage();
+    $errorCode = $e->getErrorCode();
+    $errorData = $e->getExtraParams();
+    return array(
+      'error' => $errorMessage,
+      'error_code' => $errorCode,
+      'error_data' => $errorData,
+    );
+  }
 
-return $result;
+  return $result;
 }
 
 /**
- * Function returns array of result expected from previous function
+ * Function returns array of result expected from previous function.
+ *
+ * @return array
+ *   API result array
  */
-function report_template_getrows_expectedresult(){
+function report_template_getrows_expectedresult() {
 
   $expectedResult = array(
-  'is_error' => 0,
-  'version' => 3,
-  'count' => 2,
-  'values' => array(
+    'is_error' => 0,
+    'version' => 3,
+    'count' => 2,
+    'values' => array(
       '0' => array(
-          'civicrm_contact_sort_name' => 'Default Organization',
-          'civicrm_contact_id' => '1',
-          'civicrm_address_street_address' => '',
-          'civicrm_address_city' => '',
-          'civicrm_country_name' => '',
-        ),
+        'civicrm_contact_sort_name' => 'Default Organization',
+        'civicrm_contact_id' => '1',
+      ),
       '1' => array(
-          'civicrm_contact_sort_name' => 'Second Domain',
-          'civicrm_contact_id' => '2',
-          'civicrm_address_street_address' => '15 Main St',
-          'civicrm_address_city' => 'Collinsville',
-          'civicrm_country_name' => 'United States',
-        ),
+        'civicrm_contact_sort_name' => 'Second Domain',
+        'civicrm_contact_id' => '2',
+      ),
     ),
-  'metadata' => array(
+    'metadata' => array(
       'title' => 'ERROR: Title is not Set',
       'labels' => array(
-          'civicrm_contact_sort_name' => 'Contact Name',
-          'civicrm_contact_id' => 'Internal Contact ID',
-          'civicrm_address_street_address' => 'Street Address',
-          'civicrm_address_city' => 'City',
-          'civicrm_country_name' => 'Country',
-        ),
+        'civicrm_contact_sort_name' => 'Contact Name',
+        'civicrm_contact_id' => 'Internal Contact ID',
+      ),
     ),
-);
+  );
 
   return $expectedResult;
 }
 
-
 /*
-* This example has been generated from the API test suite. The test that created it is called
-*
-* testReportTemplateGetRowsContactSummary and can be found in
+* This example has been generated from the API test suite.
+* The test that created it is called "testReportTemplateGetRowsContactSummary"
+* and can be found at:
 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ReportTemplateTest.php
 *
 * You can see the outcome of the API tests at
@@ -82,7 +83,7 @@ function report_template_getrows_expectedresult(){
 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
 *
 * Browse the api on your own site with the api explorer
-* http://MYSITE.ORG/path/to/civicrm/api/explorer
+* http://MYSITE.ORG/path/to/civicrm/api
 *
 * Read more about testing here
 * http://wiki.civicrm.org/confluence/display/CRM/Testing