Merge branch 4.5 into 4.6
[civicrm-core.git] / api / v3 / examples / ReportTemplate / Getstatistics.php
index 55f412f9a7e6284bf8b9e7ac7f02279275c0c160..93e6fc6d99b4b5e51dbb8656befc39d366fb8978 100644 (file)
@@ -1,65 +1,65 @@
 <?php
 /**
- * Test Generated example of using report_template getstatistics API
- * Get Statistics from a report (note there isn't much data to get in the test DB :-( *
+ * Test Generated example demonstrating the ReportTemplate.getstatistics API.
+ *
+ * Get Statistics from a report (note there isn't much data to get in the test DB).
+ *
+ * @return array
+ *   API result array
  */
-function report_template_getstatistics_example(){
-$params = array(
-  'report_id' => 'member/contributionDetail',
-);
+function report_template_getstatistics_example() {
+  $params = array(
+    'report_id' => 'contribute/recur',
+  );
 
-try{
-  $result = civicrm_api3('report_template', 'getstatistics', $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', 'getstatistics', $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_getstatistics_expectedresult(){
+function report_template_getstatistics_expectedresult() {
 
   $expectedResult = array(
-  'is_error' => 0,
-  'version' => 3,
-  'count' => 2,
-  'values' => array(
+    'is_error' => 0,
+    'version' => 3,
+    'count' => 2,
+    'values' => array(
       'counts' => array(
-          'rowCount' => array(
-              'title' => 'Row(s) Listed',
-              'value' => 0,
-            ),
-          'amount' => array(
-              'title' => 'Total Amount',
-              'value' => '',
-              'type' => 2,
-            ),
-          'avg' => array(
-              'title' => 'Average',
-              'value' => '',
-              'type' => 2,
-            ),
+        'rowCount' => array(
+          'title' => 'Row(s) Listed',
+          'value' => 0,
         ),
+      ),
       'filters' => array(),
     ),
-);
+  );
 
   return $expectedResult;
 }
 
-
 /*
-* This example has been generated from the API test suite. The test that created it is called
-*
-* testReportTemplateGetStatisticsAllReports and can be found in
+* This example has been generated from the API test suite.
+* The test that created it is called "testReportTemplateGetStatisticsAllReports"
+* 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
@@ -69,7 +69,7 @@ function report_template_getstatistics_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