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

  • AccountsGridViewProfileWidget
  • ActionMenu
  • ActionsGridViewProfileWidget
  • ActionsQuickCreateRelationshipBehavior
  • ActiveDateRangeInput
  • ApplicationConfigBehavior
  • Attachments
  • ChatBox
  • CommonControllerBehavior
  • ContactMapInlineTags
  • ContactsGridViewProfileWidget
  • CronForm
  • CSaveRelationsBehavior
  • DateRangeInputsWidget
  • DocsGridViewProfileWidget
  • DocViewer
  • DocViewerProfileWidget
  • EButtonColumnWithClearFilters
  • EmailDeliveryBehavior
  • EmailProgressControl
  • EncryptedFieldsBehavior
  • EventsChartProfileWidget
  • FileUploader
  • FontPickerInput
  • Formatter
  • FormView
  • GridViewWidget
  • History
  • IframeWidget
  • ImportExportBehavior
  • InlineActionForm
  • InlineEmailAction
  • InlineEmailForm
  • InlineEmailModelBehavior
  • InlineQuotes
  • JSONEmbeddedModelFieldsBehavior
  • JSONFieldsDefaultValuesBehavior
  • LeadRoutingBehavior
  • LeftWidget
  • LoginThemeHelper
  • LoginThemeHelperBase
  • MarketingGridViewProfileWidget
  • MediaBox
  • MessageBox
  • MobileFormatter
  • MobileFormLayoutRenderer
  • MobileLayoutRenderer
  • MobileLoginThemeHelper
  • MobileViewLayoutRenderer
  • ModelFileUploader
  • NewWebLeadsGridViewProfileWidget
  • NormalizedJSONFieldsBehavior
  • NoteBox
  • OnlineUsers
  • OpportunitiesGridViewProfileWidget
  • Panel
  • ProfileDashboardManager
  • ProfileGridViewWidget
  • ProfileLayoutEditor
  • ProfilesGridViewProfileWidget
  • Publisher
  • PublisherActionTab
  • PublisherCalendarEventTab
  • PublisherCallTab
  • PublisherCommentTab
  • PublisherEventTab
  • PublisherSmallCalendarEventTab
  • PublisherTab
  • PublisherTimeTab
  • QuickContact
  • QuickCreateRelationshipBehavior
  • QuotesGridViewProfileWidget
  • RecordAliasesWidget
  • RecordViewLayoutManager
  • RecordViewWidgetManager
  • RememberPagination
  • Reminders
  • ResponseBehavior
  • ResponsiveHtml
  • SearchIndexBehavior
  • ServicesGridViewProfileWidget
  • SmallCalendar
  • SmartActiveDataProvider
  • SmartDataProviderBehavior
  • SmartSort
  • SocialForm
  • SortableWidgetManager
  • SortableWidgets
  • TagBehavior
  • TagCloud
  • TemplatesGridViewProfileWidget
  • TimeZone
  • TopContacts
  • TopSites
  • TransformedFieldStorageBehavior
  • TranslationLogger
  • TwitterFeed
  • TwoColumnSortableWidgetManager
  • UpdaterBehavior
  • UpdatesForm
  • UserIdentity
  • UsersChartProfileWidget
  • WorkflowBehavior
  • X2ActiveGridView
  • X2ActiveGridViewForSortableWidgets
  • X2AssetManager
  • X2AuthManager
  • X2ChangeLogBehavior
  • X2ClientScript
  • X2Color
  • X2DateUtil
  • X2FixtureManager
  • X2FlowFormatter
  • X2GridView
  • X2GridViewBase
  • X2GridViewForSortableWidgets
  • X2GridViewSortableWidgetsBehavior
  • X2LeadsGridViewProfileWidget
  • X2LinkableBehavior
  • X2ListView
  • X2PillBox
  • X2ProgressBar
  • X2SmartSearchModelBehavior
  • X2TimestampBehavior
  • X2TranslationBehavior
  • X2UrlRule
  • X2WebModule
  • X2Widget
  • X2WidgetList
  • 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.ChartWidget');
 38: 
 39: 
 40: /**
 41:  * @package application.components
 42:  */
 43: class UsersChartProfileWidget extends ChartWidget {
 44: 
 45:     public $canBeDeleted = true;
 46: 
 47:     public $relabelingEnabled = true;
 48: 
 49:     public $template = '<div class="submenu-title-bar widget-title-bar">{widgetLabel}{chartSubtypeSelector}{closeButton}{minimizeButton}{settingsMenu}</div>{widgetContents}';
 50: 
 51:     public $chartType = 'usersChart';
 52: 
 53:     private static $_JSONPropertiesStructure;
 54: 
 55:     public $defaultTitle = 'Users Summary';
 56: 
 57:     public static function getJSONPropertiesStructure () {
 58:         if (!isset (self::$_JSONPropertiesStructure)) {
 59:             self::$_JSONPropertiesStructure = array_merge (
 60:                 parent::getJSONPropertiesStructure (),
 61:                 array (
 62:                     'label' => 'User Events',
 63:                     'hidden' => true,
 64:                     'containerNumber' => 2,
 65:                     'chartSubtype' => 'pie', 
 66:                     'chartSettings' => array (
 67:                         'startDate' => null,
 68:                         'endDate' => null, 
 69:                         'binSize' => null,
 70:                         'firstMetric' => null, 
 71:                         'chartSetting' => null,
 72:                         'eventsFilter' => null,
 73:                         'socialSubtypesFilter' => null,
 74:                         'visibilityFilter' => null,
 75:                         'dateRange' => null,
 76:                     ),
 77:                 )
 78:             );
 79:         }
 80:         return self::$_JSONPropertiesStructure;
 81:     }
 82: 
 83: 
 84:     /**
 85:      * Returns a data provider containing chart settings records with the specified type
 86:      */
 87:     public static function getChartSettingsProvider ($chartType) {
 88:         $chartSettingsDataProvider = new CActiveDataProvider('ChartSetting', array(
 89:             'criteria' => array(
 90:                 'condition' => 
 91:                     'userId='.Yii::app()->user->id.' AND '.
 92:                     'chartType="usersChart"',
 93:                 'order' => 'name ASC'
 94:             )
 95:         ));
 96:         return $chartSettingsDataProvider;
 97:     }
 98: 
 99:     /**
100:      * Retrieves all events between start and end timestamp. Query results are used to
101:      * populate the activity feed chart.
102:      */
103:     public static function getChartData ($startTimestamp, $endTimestamp){
104:         $command = Yii::app()->db->createCommand()
105:                 ->select(
106:                         'type, subtype, visibility, user,'.
107:                         'timestamp, COUNT(type) AS count,'.
108:                         'YEAR(FROM_UNIXTIME(timestamp)) AS year,'.
109:                         'MONTH(FROM_UNIXTIME(timestamp)) AS month,'.
110:                         'WEEK(FROM_UNIXTIME(timestamp)) AS week,'.
111:                         'DAY(FROM_UNIXTIME(timestamp)) AS day,'.
112:                         'HOUR(from_unixtime(timestamp)) as hour')
113:                 ->from('x2_events');
114:         $command->where(
115:                 'timestamp BETWEEN :startTimestamp AND :endTimestamp', 
116:                 array('startTimestamp' => $startTimestamp, 'endTimestamp' => $endTimestamp));
117:         $events = $command->group(
118:                         'HOUR(FROM_UNIXTIME(timestamp)),'.
119:                         'DAY(FROM_UNIXTIME(timestamp)),'.
120:                         'WEEK(FROM_UNIXTIME(timestamp)),'.
121:                         'MONTH(FROM_UNIXTIME(timestamp)),'.
122:                         'YEAR(FROM_UNIXTIME(timestamp)),'.
123:                         'timestamp, type, subtype, visibility, user')
124:                 ->order('year DESC, month DESC, week DESC, day DESC, hour desc')
125:                 ->queryAll();
126:         return $events;
127:     }
128: 
129:     /**
130:      * Instantiates a subclass of X2Chart, passing it a function which allows it to save widget
131:      * settings.
132:      */
133:     public function getSetupScript () {
134:         if (!isset ($this->_setupScript)) {
135:             $widgetClass = get_called_class ();
136:             $chartData = $this->getInitialChartData ();
137:             $userNames = User::getNames ();
138:             $eventTypes = array ('all'=>Yii::t('app', 'All Events')) + Events::$eventLabels;
139:             $socialSubtypes = Dropdowns::getSocialSubtypes ();
140:             $visibilityFilters = array (
141:                 '1'=>'Public',
142:                 '0'=>'Private',
143:             );
144:             $chartSettingsData = self::getChartSettingsProvider ($this->chartType)->data;
145:             $this->_setupScript = parent::getSetupScript ()."
146:                 $(function () {
147:                     var chartUID = '$this->chartType$this->widgetUID';
148:                     x2[chartUID] = {};
149:                     x2[chartUID].chart = X2Chart.instantiateTemporarySubtype (
150:                         X2UsersChart, {
151:                         ".(isset ($chartData) ?
152:                             "chartData :".CJSON::encode ($chartData)."," : '')."
153:                         actionParams: ".CJSON::encode (array (
154:                             'widgetType' => get_called_class (),
155:                         )).",
156:                         socialSubtypes:".CJSON::encode (array_keys ($socialSubtypes)).",
157:                         visibilityTypes:".CJSON::encode (array_keys ($visibilityFilters)).",
158:                         eventTypes:".CJSON::encode (array_keys ($eventTypes)).", 
159:                         translations: ".CJSON::encode ($this->getTranslations ()).",
160:                         getChartDataActionName: 'getEventsBetween',
161:                         saveChartSetting: function (key, value, callback) {
162:                             this.lastChartSettings[key] = value;
163:                             x2.$widgetClass$this->widgetUID.setProperty (
164:                                 'chartSettings', this.lastChartSettings, callback);
165:                         },
166:                         suppressDateRangeSelector: false,
167:                         suppressChartSettings: false,
168:                         lastChartSettings: ".CJSON::encode ($this->getChartSettings ()).",
169:                         widgetUID: '$this->widgetUID',
170:                         chartType: '$this->chartType',
171:                         chartSubtype: '".self::getJSONProperty (
172:                             $this->profile, 'chartSubtype', $this->widgetType, $this->widgetUID)."',
173:                         chartSettings: ".CJSON::encode (
174:                             count ($chartSettingsData) ? array_combine (
175:                                 array_map (function ($setting) {
176:                                     return $setting->name;
177:                                 }, $chartSettingsData),
178:                                 $chartSettingsData) : array ())."
179:                         });
180:                     $(document).trigger ('$this->chartType' + 'Ready');
181:                 });
182:             ";
183:         }
184:         return $this->_setupScript;
185:     }
186: 
187:     /**
188:      * Send the chart type to the widget content view 
189:      */
190:     public function getViewFileParams () {
191:         if (!isset ($this->_viewFileParams)) {
192:             $this->_viewFileParams = array_merge (
193:                 parent::getViewFileParams (),
194:                 array (
195:                     'chartType' => $this->chartType,
196:                     'chartSettingsDataProvider' => self::getChartSettingsProvider (
197:                         $this->chartType),
198:                     'eventTypes' =>
199:                         array ('all'=>Yii::t('app', 'All Events')) + Events::$eventLabels,
200:                     'socialSubtypes' => Dropdowns::getSocialSubtypes (),
201:                     'visibilityFilters' => array (
202:                         '1'=>'Public',
203:                         '0'=>'Private',
204:                     ),
205:                     'suppressChartSettings' => false,
206:                     'chartType' => 'usersChart',
207:                     'widgetUID' => $this->widgetUID,
208:                     'metricTypes' => User::getUserOptions (),
209:                 )
210:             );
211:         }
212:         return $this->_viewFileParams;
213:     }
214: 
215: 
216:     /**
217:      * overrides parent method. Adds JS file necessary to run the setup script.
218:      */
219:     public function getPackages () {
220:         if (!isset ($this->_packages)) {
221:             $this->_packages = array_merge (
222:                 parent::getPackages (),
223:                 array (
224:                     'UsersChartProfileWidgetJS' => array(
225:                         'baseUrl' => Yii::app()->request->baseUrl,
226:                         'js' => array(
227:                             'js/X2Chart/X2UsersChart.js',
228:                         ),
229:                         'depends' => array ('ChartWidgetJS')
230:                     ),
231:                 )
232:             );
233:         }
234:         return $this->_packages;
235:     }
236: 
237:     /**
238:      * @return array translations to pass to JS objects 
239:      */
240:     protected function getTranslations () {
241:         if (!isset ($this->_translations )) {
242:             $this->_translations = array_merge (
243:                 parent::getTranslations (),
244:                 array (
245:                     'event subtype(s) selected' => Yii::t('app', 'event subtype(s) selected'),
246:                     'visibility setting(s) selected' => Yii::t(
247:                         'app', 'visibility setting(s) selected'),
248:                     'metric1Label' => Yii::t('app', '{user}(s) selected', array(
249:                         '{user}' => strtolower(Modules::displayName(false, 'Users')),
250:                     )),
251:                     'event type(s) selected' => Yii::t('app', 'event type(s) selected'),
252:                 )
253:             );
254:         }
255:         return $this->_translations;
256:     }
257: 
258:     /**
259:      * Collect initial chart data so the client doesn't have to request it via ajax .
260:      * Decreases time before chart render after page is loaded.
261:      */
262:     protected function getInitialChartData () {
263:         
264:         /* 
265:         Chart data only needs to be sent with initial response if chart was
266:         left open.
267:         */
268:         if (self::getJSONProperty (
269:             $this->profile, 'minimized', $this->widgetType, $this->widgetUID)) {
270: 
271:             $tsDict = $this->getStartEndTimestamp (time () - self::SECPERWEEK, time ());
272:             $startDate = $tsDict[0];
273:             $endDate = $tsDict[1];
274:             $events = self::getChartData ($startDate, $endDate);
275:             return $events;
276:         }
277:     }
278: 
279:      
280: }
281: ?>
282: 
X2CRM Documentation API documentation generated by ApiGen 2.8.0