Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
ReportChartView.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
40  class ReportChartView extends View
41  {
45  protected $controllerId;
46 
50  protected $moduleId;
51 
55  protected $dataProvider;
56 
60  protected $uniqueLayoutId;
61 
65  protected static $maximumGroupsPerChart = 100;
66 
70  public static function setMaximumGroupsPerChart($value)
71  {
72  assert('is_int($value)');
73  self::$maximumGroupsPerChart = $value;
74  }
75 
82  public function __construct($controllerId, $moduleId, SummationReportDataProvider $dataProvider, $uniqueLayoutId)
83  {
84  assert('is_string($controllerId)');
85  assert('is_string($moduleId)');
86  assert('is_string($uniqueLayoutId)');
87  $this->controllerId = $controllerId;
88  $this->moduleId = $moduleId;
89  $this->dataProvider = $dataProvider;
90  $this->uniqueLayoutId = $uniqueLayoutId;
91  }
92 
96  public function renderContent()
97  {
98  if ($this->dataProvider->calculateTotalItemCount() > self::$maximumGroupsPerChart)
99  {
100  return $this->renderMaximumGroupsContent();
101  }
102  return $this->renderChartContent();
103  }
104 
108  protected function renderChartContent()
109  {
110  $reportDataProviderToAmChartMakerAdapter = $this->dataProvider->makeReportDataProviderToAmChartMakerAdapter();
111  Yii::import('ext.amcharts.AmChartMaker');
112  $amChart = new AmChartMaker();
114  $amChart->data = $reportDataProviderToAmChartMakerAdapter->getData();
115  $amChart->id = $this->uniqueLayoutId;
116  $amChart->type = $reportDataProviderToAmChartMakerAdapter->getType();
117  $amChart->xAxisName = $this->dataProvider->resolveFirstSeriesLabel();
118  $amChart->yAxisName = $this->dataProvider->resolveFirstRangeLabel();
119  $amChart->yAxisUnitContent = $this->resolveYAxisUnitContent();
120  if ($reportDataProviderToAmChartMakerAdapter->isStacked())
121  {
122  for ($i = 1; $i < ($reportDataProviderToAmChartMakerAdapter->getSecondSeriesValueCount() + 1); $i++)
123  {
124  $title = $reportDataProviderToAmChartMakerAdapter->getSecondSeriesDisplayLabelByKey($i);
130  ']] "';
131  $amChart->addSerialGraph(ReportDataProviderToAmChartMakerAdapter::resolveFirstSeriesValueName($i), 'column',
132  array('title' => '"' . CJavaScript::quote($title) . '"', 'balloonText' => $balloonText));
133  }
134  }
135  else
136  {
137  $amChart->addSerialGraph(ReportDataProviderToAmChartMakerAdapter::resolveFirstSeriesValueName(1), 'column');
138  }
139  $scriptContent = $amChart->javascriptChart();
140  Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $this->uniqueLayoutId, $scriptContent);
141  $cClipWidget = new CClipWidget();
142  $cClipWidget->beginClip("Chart" . $this->uniqueLayoutId);
143  $cClipWidget->widget('application.core.widgets.AmChart', array('id' => $this->uniqueLayoutId));
144  $cClipWidget->endClip();
145  return $cClipWidget->getController()->clips['Chart' . $this->uniqueLayoutId];
146  }
147 
151  protected function renderMaximumGroupsContent()
152  {
153  $content = '<div class="general-issue-notice"><span class="icon-notice"></span><p>';
154  $content .= Zurmo::t('ReportsModule', 'Your report has too many groups to plot. ' .
155  'Please adjust the filters to reduce the number below {maximum}.',
156  array('{maximum}' => self::$maximumGroupsPerChart));
157  $content .= '</p></div>';
158  return $content;
159  }
160 
165  protected function resolveYAxisUnitContent()
166  {
167  if ($this->dataProvider->getReport()->getCurrencyConversionType() ==
169  {
170  return null;
171  }
172  elseif ($this->dataProvider->getReport()->getCurrencyConversionType() ==
174  {
175  if ($this->dataProvider->resolveIsFirstRangeAttributeATypeOfCurrencyValue())
176  {
177  //Assumes base conversion is done using sql math
178  return Yii::app()->locale->getCurrencySymbol(Yii::app()->currencyHelper->getBaseCode());
179  }
180  else
181  {
182  return null;
183  }
184  }
185  elseif ($this->dataProvider->getReport()->getCurrencyConversionType() ==
187  {
188  if ($this->dataProvider->resolveIsFirstRangeAttributeATypeOfCurrencyValue())
189  {
190  //Assumes base conversion is done using sql math
191  return Yii::app()->locale->getCurrencySymbol(
192  $this->dataProvider->getReport()->getSpotConversionCurrencyCode());
193  }
194  else
195  {
196  return null;
197  }
198  }
199  else
200  {
201  throw new NotSupportedException();
202  }
203  }
204  }
205 ?>
const CURRENCY_CONVERSION_TYPE_SPOT
Definition: Report.php:82
const CURRENCY_CONVERSION_TYPE_BASE
Definition: Report.php:76
Definition: View.php:43
const CURRENCY_CONVERSION_TYPE_ACTUAL
Definition: Report.php:70
static setMaximumGroupsPerChart($value)
__construct($controllerId, $moduleId, SummationReportDataProvider $dataProvider, $uniqueLayoutId)
Generated on Tue Dec 1 2020 07:10:32
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.