Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • None
  • system
    • base
    • caching
    • console
    • db
      • ar
      • schema
    • validators
    • web
      • actions
      • auth
      • helpers
      • widgets
        • captcha
        • pagers
  • zii
    • widgets
      • grid

Classes

  • ActionsWidget
  • CallsWidget
  • ChartWidget
  • CommentsWidget
  • EmailsWidget
  • EventsWidget
  • InlineRelationshipsWidget
  • InlineTagsWidget
  • LoggedTimeWidget
  • PublisherWidget
  • QuotesWidget
  • SortableWidget
  • TransactionalViewWidget
  • TwitterFeedWidget
  • WebActivityWidget
  • WorkflowStageDetailsWidget
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /*****************************************************************************************
  3:  * X2Engine Open Source Edition is a customer relationship management program developed by
  4:  * X2Engine, Inc. Copyright (C) 2011-2016 X2Engine Inc.
  5:  * 
  6:  * This program 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 X2ENGINE, X2ENGINE DISCLAIMS THE WARRANTY
 11:  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 12:  * 
 13:  * This program 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 X2Engine, Inc. P.O. Box 66752, Scotts Valley,
 24:  * California 95067, USA. or at email address contact@x2engine.com.
 25:  * 
 26:  * The interactive user interfaces in modified source and object code 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 "Powered by
 32:  * X2Engine" logo. If the display of the logo is not reasonably feasible for
 33:  * technical reasons, the Appropriate Legal Notices must display the words
 34:  * "Powered by X2Engine".
 35:  *****************************************************************************************/
 36: 
 37:  Yii::import ('application.components.sortableWidget.SortableWidget');
 38: 
 39: /**
 40:  * @package application.components.sortableWidget
 41:  */
 42: abstract class ChartWidget extends SortableWidget {
 43: 
 44:     const SECPERDAY = 86400;
 45:     const SECPERWEEK = 604800;
 46: 
 47:     public $template = '<div class="submenu-title-bar widget-title-bar">{widgetLabel}{chartSubtypeSelector}{closeButton}{minimizeButton}{settingsMenu}</div>{widgetContents}';
 48: 
 49:     /**
 50:      * @var string the type of chart (e.g. 'eventsChart', 'usersChart')
 51:      */
 52:     public $chartType;
 53: 
 54:     public $viewFile = '_chartWidget';
 55: 
 56:     protected $containerClass = 'sortable-widget-container x2-layout-island sortable-chart-widget';
 57: 
 58:     protected $_translations;
 59: 
 60:     private static $_JSONPropertiesStructure;
 61: 
 62:     private $_chartSettings;
 63: 
 64:     public function getChartSettings () {
 65:         if (!isset ($this->_chartSettings)) {
 66:             $this->_chartSettings = array_merge (
 67:                 array_filter (self::getJSONProperty (
 68:                     $this->profile, 'chartSettings', $this->widgetType, $this->widgetUID),
 69:                     function ($setting) {
 70:                         return $setting !== null;
 71:                     }),
 72:                 array (
 73:                     'chartIsShown' => self::getJSONProperty (
 74:                         $this->profile, 'minimized', $this->widgetType, 
 75:                         $this->widgetUID),
 76:                 )
 77:             );
 78:         }
 79:         return $this->_chartSettings;
 80:     }
 81: 
 82:     public function getViewFileParams () {
 83:         if (!isset ($this->_viewFileParams)) {
 84:             $this->_viewFileParams = array_merge (
 85:                 parent::getViewFileParams (),
 86:                 array (
 87:                     'suppressDateRangeSelector' => false,
 88:                     'chartSubtype' => self::getJSONProperty (
 89:                         $this->profile, 'chartSubtype', $this->widgetType, $this->widgetUID),
 90:                     'widgetUID' => $this->widgetUID
 91:                 )
 92:             );
 93:         }
 94:         return $this->_viewFileParams;
 95:     } 
 96: 
 97:     /**
 98:      * overrides parent method
 99:      */
100:     public static function getJSONPropertiesStructure () {
101:         if (!isset (self::$_JSONPropertiesStructure)) {
102:             self::$_JSONPropertiesStructure = array_merge (
103:                 parent::getJSONPropertiesStructure (),
104:                 array (
105:                     'chartSubtype' => 'line', 
106:                     'chartSettings' => array (),
107:                 )
108:             );
109:         }
110:         return self::$_JSONPropertiesStructure;
111:     }
112: 
113:     /**
114:      * @param string $settingName
115:      */
116:     public function getChartSetting ($settingName) {
117:         $chartSettings = self::getJSONProperty (
118:             $this->profile, 'chartSettings', $this->widgetType, $this->widgetUID);
119: 
120:         if (in_array ($settingName, array_keys ($chartSettings))) {
121:             return $chartSettings[$settingName];
122:         } else {
123:             throw new CException (Yii::t('app', 'Invalid chart setting name.'));
124:         }
125:     }
126: 
127:     /**
128:      * overrides parent method. A sub prototype of SortableWidget.js is instantiated.
129:      */
130:     public function getSetupScript () {
131:         if (!isset ($this->_setupScript)) {
132:             $widgetClass = get_called_class ();
133:             $this->_setupScript = "
134:                 $(function () {
135:                     x2.".$widgetClass.$this->widgetUID." = new ChartWidget (".
136:                         CJSON::encode ($this->getJSSortableWidgetParams ()).
137:                     ");
138:                 });
139:             ";
140:         }
141:         return $this->_setupScript;
142:     }
143: 
144:     /**
145:      * overrides parent method. Adds JS file necessary to run the setup script.
146:      */
147:     public function getPackages () {
148:         if (!isset ($this->_packages)) {
149:             $this->_packages = array_merge (
150:                 parent::getPackages (),
151:                 array (
152:                     'ChartWidgetJS' => array(
153:                         'baseUrl' => Yii::app()->request->baseUrl,
154:                         'js' => array(
155:                             'js/jqplot/jquery.jqplot.js',
156:                             'js/jqplot/plugins/jqplot.pieRenderer.js',
157:                             'js/jqplot/plugins/jqplot.categoryAxisRenderer.js',
158:                             'js/jqplot/plugins/jqplot.pointLabels.js',
159:                             'js/jqplot/plugins/jqplot.dateAxisRenderer.js',
160:                             'js/jqplot/plugins/jqplot.highlighter.js',
161:                             'js/jqplot/plugins/jqplot.enhancedLegendRenderer.js',
162:                             'js/lib/moment-with-locales.min.js',
163:                             'js/sortableWidgets/ChartWidget.js',
164:                             'js/X2Chart/X2Chart.js',
165:                         ),
166:                         'depends' => array ('SortableWidgetJS')
167:                     ),
168:                     'ChartWidgetCss' => array(
169:                         'baseUrl' => Yii::app()->getTheme ()->getBaseUrl (),
170:                         'css' => array(
171:                             'css/x2chart.css',
172:                         )
173:                     ),
174:                     'ChartWidgetCssExt' => array(
175:                         'baseUrl' => Yii::app()->request->baseUrl,
176:                         'css' => array(
177:                             'js/jqplot/jquery.jqplot.css',
178:                         ),
179:                     ),
180:                 )
181:             );
182:             if (AuxLib::isIE8 ()) {
183:                 $this->_packages['ChartWidgetJS']['js'][] = 'js/jqplot/excanvas.js';
184:             }
185:         }
186:         return $this->_packages;
187:     }
188: 
189:     /**
190:      * Render the chart subtype selector
191:      */
192:     public function renderChartSubtypeSelector () {
193:         $subtype = self::getJSONProperty (
194:             $this->profile, 'chartSubtype', $this->widgetType, $this->widgetUID);
195: 
196:         echo 
197:             "<select class='x2-minimal-select chart-subtype-selector'>
198:                 <option ".($subtype === 'line' ? 'selected="selected" ' : '')."value='line'>".
199:                     Yii::t('app', 'Line Chart').
200:                 "</option>
201:                 <option ".($subtype === 'pie' ? 'selected="selected" ' : '')."value='pie'>".
202:                     Yii::t('app', 'Pie Chart').
203:                 "</option>
204:             </select>";
205:     }
206: 
207:     /**
208:      * Magic getter.
209:      */
210:     protected function getJSSortableWidgetParams () {
211:         if (!isset ($this->_JSSortableWidgetParams)) {
212:             $this->_JSSortableWidgetParams = array_merge (
213:                 parent::getJSSortableWidgetParams (), array (
214:                     'chartType' => $this->chartType,
215:                 ));
216:         }
217:         return $this->_JSSortableWidgetParams;
218:     }
219: 
220:     /**
221:      * @return array translations to pass to JS objects 
222:      */
223:     protected function getTranslations () {
224:         if (!isset ($this->_translations )) {
225:             $longMonthNames = Yii::app()->getLocale ()->getMonthNames ();
226:             $shortMonthNames = Yii::app()->getLocale ()->getMonthNames ('abbreviated');
227: 
228:             $translations = array (
229:                 'Create' => Yii::t('app','Create'),
230:                 'Cancel' => Yii::t('app','Cancel'),
231:                 'Create Chart Setting' => Yii::t('app','Create Chart Setting'),
232:                 'Check all' => Yii::t('app','Check all'),
233:                 'Uncheck all' => Yii::t('app','Uncheck all'),
234:                 'metric(s) selected' => Yii::t('app','metric(s) selected')
235:             );
236: 
237:             $englishMonthNames =
238:                 array ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August',
239:                 'September', 'October', 'November', 'December');
240:             $englishMonthAbbrs =
241:                 array ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov',
242:                 'Dec');
243: 
244:             foreach ($longMonthNames as $key=>$val) {
245:                 $translations[$englishMonthNames[$key - 1]] = $val;
246:             }
247:             foreach ($shortMonthNames as $key=>$val) {
248:                 $translations[$englishMonthAbbrs[$key - 1]] = $val;
249:             }
250: 
251:             $this->_translations = array_merge (
252:                 parent::getTranslations (),
253:                 $translations
254:             );
255:         }
256:         return $this->_translations;
257:     }
258: 
259:     /**
260:      * overrides parent method. Returns chart specific css
261:      */
262:     protected function getCss () {
263:         if (!isset ($this->_css)) {
264:             $this->_css = array_merge (
265:                 parent::getCss (),
266:                 array (
267:                 'sortableWidgetChartCss' => "
268:                     .sortable-widget-container .chart-subtype-selector {
269:                         margin: 1px 0px 4px 5px;
270:                         border: 1px solid #ddd;
271:                     }
272: 
273:                     .sortable-widget-container div.chart-container {
274:                         -moz-border-radius: 0px !important;
275:                         -o-border-radius: 0px !important;
276:                         -webkit-border-radius: 0px !important;
277:                         border-radius: 0px !important;
278:                     }
279: 
280:                     .sortable-chart-widget .chart-controls-container {
281:                         width: 604px;
282:                         padding: 3px;
283:                     }
284: 
285:                     .sortable-chart-widget .chart-widget-button-container .relabel-widget-button {
286:                         margin-right: 5px;
287:                     }
288: 
289:                     @media (max-width: 684px) {
290:                         .sortable-chart-widget .chart-controls-container {
291:                             width: 95%;
292:                             padding: 3px;
293:                         }
294:                         .sortable-chart-widget .popup-dropdown-menu.flipped:before {
295:                             right: 52px;
296:                         }
297:                         .sortable-chart-widget .popup-dropdown-menu {
298:                             left: 0 !important;
299:                             right: 0!important;
300:                             margin: auto;
301:                         }
302:                     }
303: 
304:                     @media (max-width: 529px) {
305:                         .sortable-chart-widget .chart-container .bin-size-button-set {
306:                             margin-top: 6px;
307:                         }
308:                     }
309: 
310:                     /* menu contents */
311:                     @media (max-width: 500px) {
312:                         .sortable-chart-widget .chart-container .chart-filters-container {
313:                             height: auto;
314:                         }
315:                         .sortable-chart-widget .ui-multiselect {
316:                             margin-top: 0 !important;
317:                         }
318:                     }
319:                 ")
320:             );
321:         }
322:         return $this->_css;
323:     }
324: 
325:     
326:     /**
327:      * Returns an array containing a start and end timestamp.
328:      * If a date range cookie is set, the timestamps get generated. Otherwise start and
329:      * end timestamp cookies are used. Specified default timestamps will be used when
330:      * cookies are not set.
331:      */
332:     protected function getStartEndTimestamp ($defaultStartTs, $defaultEndTs) {
333:         $startDate;
334:         $endDate;
335:         if ($this->getChartSetting ('dateRange') !== null &&
336:             $this->getChartSetting ('dateRange') !== 'Custom') {
337: 
338:             $dateRange = $this->getChartSetting ('dateRange');
339:             switch ($dateRange) {
340:                 case 'Today':
341:                     $startDate = time ();
342:                     $endDate = time ();
343:                     break;
344:                 case 'Yesterday':
345:                     $startDate = strtotime ('Yesterday');
346:                     $endDate = strtotime ('Yesterday');
347:                     break;
348:                 case 'This Week':
349:                     $startDate = strtotime ('Sunday this week');
350:                     $endDate = time ();
351:                     break;
352:                 case 'Last Week':
353:                     $startDate = strtotime ('-2 Sunday');
354:                     $endDate = strtotime ('-1 Saturday');
355:                     break;
356:                 case 'This Month':
357:                     $startDate = mktime (0, 0, 0, date ('m'), 1, date('o'));
358:                     $endDate = time ();
359:                     break;
360:                 case 'Last Six Months':
361:                     $startDate = mktime (0, 0, 0, date ('m') - 6, 1, date('o'));
362:                     $endDate = time ();
363:                     break;
364:                 case 'This Year':
365:                     $startDate = mktime (0, 0, 0, 1, 1, date('o'));
366:                     $endDate = time ();
367:                     break;
368:                 case 'Last Year':
369:                     $startDate = mktime (0, 0, 0, 1, 1, date('o') - 1);
370:                     $endDate = mktime (0, 0, 0, 11, 31, date('o') - 1);
371:                     break;
372:                 case 'Last Month':
373:                 default:
374:                     $startDate = mktime (0, 0, 0, date ('m') - 1, 1, date('o'));
375:                     $endDate = mktime (0, 0, 0, date ('m'), 1, date('o')) - self::SECPERDAY;
376:                     break;
377:                 /*case 'Data Domain':
378:                     break;*/
379:             }
380:         } else {
381:             if ($this->getChartSetting ('startDate') !== null) {
382:                 $startDate = $this->getChartSetting ('startDate') / 1000;
383:             } else {
384:                 $startDate = $defaultStartTs;
385:             }
386:             if ($this->getChartSetting ('endDate')) { 
387:                 $endDate = $this->getChartSetting ('endDate') / 1000;
388:             } else {
389:                 $endDate = $defaultEndTs;
390:             }
391:         }
392:         $endDate += self::SECPERDAY - 1;
393:         return array ($startDate, $endDate);
394:     }
395: 
396: 
397: }
398: ?>
399: 
X2CRM Documentation API documentation generated by ApiGen 2.8.0