Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-06-25-23-42-42
[civicrm-core.git] / CRM / Utils / OpenFlashChart.php
index 2ad178f63a72f38bb0683382ea67e179adfb30a8..fe7285869b9e8dbeccdca5e29232517d351d83f8 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -64,7 +64,7 @@ class CRM_Utils_OpenFlashChart {
     if (empty($params)) {
       return $chart;
     }
-    if (!CRM_Utils_Array::value('multiValues', $params)) {
+    if (empty($params['multiValues'])) {
       $params['multiValues'] = array($params['values']);
     }
 
@@ -74,7 +74,7 @@ class CRM_Utils_OpenFlashChart {
     }
 
     // get the required data.
-    $chartTitle = CRM_Utils_Array::value('legend', $params) ? $params['legend'] : ts('Bar Chart');
+    $chartTitle = !empty($params['legend']) ? $params['legend'] : ts('Bar Chart');
 
     $xValues = $yValues = array();
     $xValues = array_keys($values[0]);
@@ -106,7 +106,7 @@ class CRM_Utils_OpenFlashChart {
         // FIXME: for bars > 2, we'll need to come out with other colors
         $bars[$barCount]->colour( '#BF3B69');
       }
-      
+
       if ($barKey = CRM_Utils_Array::value($barCount, CRM_Utils_Array::value('barKeys', $params))) {
         $bars[$barCount]->key($barKey,12);
       }
@@ -123,6 +123,11 @@ class CRM_Utils_OpenFlashChart {
 
     // create x axis label obj.
     $xLabels = new x_axis_labels();
+    // set_labels function requires xValues array of string or x_axis_label
+    // so type casting array values to string values
+    array_walk($xValues, function(&$value, $index) {
+        $value = (string)$value;
+      });
     $xLabels->set_labels($xValues);
 
     // set angle for labels.
@@ -198,7 +203,7 @@ class CRM_Utils_OpenFlashChart {
     foreach ($allValues as $label => $value) {
       $values[] = new pie_value((double)$value, $label);
     }
-    $graphTitle = CRM_Utils_Array::value('legend', $params) ? $params['legend'] : ts('Pie Chart');
+    $graphTitle = !empty($params['legend']) ? $params['legend'] : ts('Pie Chart');
 
     //get the currency.
     $config = CRM_Core_Config::singleton();
@@ -310,7 +315,7 @@ class CRM_Utils_OpenFlashChart {
       $count++;
     }
 
-    $chartTitle = CRM_Utils_Array::value('legend', $params) ? $params['legend'] : ts('Bar Chart');
+    $chartTitle = !empty($params['legend']) ? $params['legend'] : ts('Bar Chart');
 
     //set y axis parameters.
     $yMin = 0;
@@ -384,6 +389,13 @@ class CRM_Utils_OpenFlashChart {
     return $chart;
   }
 
+  /**
+   * @param $rows
+   * @param $chart
+   * @param $interval
+   *
+   * @return array
+   */
   static function chart($rows, $chart, $interval) {
     $chartData = $dateKeys = array();
 
@@ -429,7 +441,7 @@ class CRM_Utils_OpenFlashChart {
       foreach ($rows['multiValue'] as $key => $val) {
         $graph[$key] = array_combine($dateKeys, $rows['multiValue'][$key]);
       }
-      $chartData = 
+      $chartData =
         array(
           'legend' => "$legend " . CRM_Utils_Array::value('legend', $rows, ts('Contribution')) . ' ' . ts('Summary'),
           'values' => $graph[0],
@@ -440,7 +452,7 @@ class CRM_Utils_OpenFlashChart {
 
     // rotate the x labels.
     $chartData['xLabelAngle'] = CRM_Utils_Array::value('xLabelAngle', $rows, 0);
-    if (CRM_Utils_Array::value('tip', $rows)) {
+    if (!empty($rows['tip'])) {
       $chartData['tip'] = $rows['tip'];
     }
 
@@ -451,7 +463,7 @@ class CRM_Utils_OpenFlashChart {
     // carry some chart params if pass.
     foreach (array(
       'xSize', 'ySize', 'divName') as $f) {
-      if (CRM_Utils_Array::value($f, $rows)) {
+      if (!empty($rows[$f])) {
         $chartData[$f] = $rows[$f];
       }
     }
@@ -459,6 +471,14 @@ class CRM_Utils_OpenFlashChart {
     return self::buildChart($chartData, $chart);
   }
 
+  /**
+   * @param $rows
+   * @param $chart
+   * @param $interval
+   * @param $chartInfo
+   *
+   * @return array
+   */
   static function reportChart($rows, $chart, $interval, &$chartInfo) {
     foreach ($interval as $key => $val) {
       $graph[$val] = $rows['value'][$key];
@@ -473,14 +493,14 @@ class CRM_Utils_OpenFlashChart {
 
     // rotate the x labels.
     $chartData['xLabelAngle'] = CRM_Utils_Array::value('xLabelAngle', $chartInfo, 20);
-    if (CRM_Utils_Array::value('tip', $chartInfo)) {
+    if (!empty($chartInfo['tip'])) {
       $chartData['tip'] = $chartInfo['tip'];
     }
 
     // carry some chart params if pass.
     foreach (array(
       'xSize', 'ySize', 'divName') as $f) {
-      if (CRM_Utils_Array::value($f, $rows)) {
+      if (!empty($rows[$f])) {
         $chartData[$f] = $rows[$f];
       }
     }
@@ -488,6 +508,12 @@ class CRM_Utils_OpenFlashChart {
     return self::buildChart($chartData, $chart);
   }
 
+  /**
+   * @param $params
+   * @param $chart
+   *
+   * @return array
+   */
   static function buildChart(&$params, $chart) {
     $openFlashChart = array();
     if ($chart && is_array($params) && !empty($params)) {