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:  * @package application.components
 41:  */
 42: class EventsChartProfileWidget extends ChartWidget {
 43: 
 44:     public $canBeDeleted = true;
 45: 
 46:     public $defaultTitle = 'Events';
 47: 
 48:     public $relabelingEnabled = true;
 49: 
 50:     public $template = '<div class="submenu-title-bar widget-title-bar">{widgetLabel}{chartSubtypeSelector}{closeButton}{minimizeButton}{settingsMenu}</div>{widgetContents}';
 51: 
 52:     public $chartType = 'eventsChart';
 53: 
 54:     private static $_JSONPropertiesStructure;
 55: 
 56:     public static function getJSONPropertiesStructure () {
 57:         if (!isset (self::$_JSONPropertiesStructure)) {
 58:             self::$_JSONPropertiesStructure = array_merge (
 59:                 parent::getJSONPropertiesStructure (),
 60:                 array (
 61:                     'label' => 'Events',
 62:                     'chartSettings' => array (
 63:                         'startDate' => null,
 64:                         'endDate' => null, 
 65:                         'dateRange' => null,
 66:                         'dateRangeType' => null,
 67:                         'binSize' => null,
 68:                         'firstMetric' => null, 
 69:                         'showRelationships' => null,
 70:                         'chartSetting' => null,
 71:                         'usersFilter' => null,
 72:                         'socialSubtypesFilter' => null,
 73:                         'visibilityFilter' => null,
 74:                     ),
 75:                 )
 76:             );
 77:         }
 78:         return self::$_JSONPropertiesStructure;
 79:     }
 80: 
 81:     /**
 82:      * Retrieves all events between start and end timestamp. Query results are used to
 83:      * populate the activity feed chart.
 84:      */
 85:     public static function getChartData ($startTimestamp, $endTimestamp){
 86:         $command = Yii::app()->db->createCommand()
 87:                 ->select(
 88:                         'type, subtype, visibility, user,'.
 89:                         'timestamp, COUNT(type) AS count,'.
 90:                         'YEAR(FROM_UNIXTIME(timestamp)) AS year,'.
 91:                         'MONTH(FROM_UNIXTIME(timestamp)) AS month,'.
 92:                         'WEEK(FROM_UNIXTIME(timestamp)) AS week,'.
 93:                         'DAY(FROM_UNIXTIME(timestamp)) AS day,'.
 94:                         'HOUR(from_unixtime(timestamp)) as hour')
 95:                 ->from('x2_events');
 96:         $command->where(
 97:                 'timestamp BETWEEN :startTimestamp AND :endTimestamp', 
 98:                 array('startTimestamp' => $startTimestamp, 'endTimestamp' => $endTimestamp));
 99:         $events = $command->group(
100:                         'HOUR(FROM_UNIXTIME(timestamp)),'.
101:                         'DAY(FROM_UNIXTIME(timestamp)),'.
102:                         'WEEK(FROM_UNIXTIME(timestamp)),'.
103:                         'MONTH(FROM_UNIXTIME(timestamp)),'.
104:                         'YEAR(FROM_UNIXTIME(timestamp)),'.
105:                         'timestamp, type, subtype, visibility, user')
106:                 ->order('year DESC, month DESC, week DESC, day DESC, hour desc')
107:                 ->queryAll();
108:         return $events;
109:     }
110: 
111: 
112:     /**
113:      * Returns a data provider containing chart settings records with the specified type
114:      */
115:     public static function getChartSettingsProvider () {
116:         $chartSettingsDataProvider = new CActiveDataProvider('ChartSetting', array(
117:             'criteria' => array(
118:                 'condition' => 
119:                     'userId='.Yii::app()->user->id.' AND '.
120:                     'chartType="eventsChart"',
121:                 'order' => 'name ASC'
122:             )
123:         ));
124:         return $chartSettingsDataProvider;
125:     }
126: 
127:     /**
128:      * Instantiates a subclass of X2Chart, passing it a function which allows it to save widget
129:      * settings.
130:      */
131:     public function getSetupScript () {
132:         if (!isset ($this->_setupScript)) {
133:             $widgetClass = get_called_class ();
134:             $chartData = $this->getInitialChartData ();
135:             $userNames = User::getNames ();
136:             $socialSubtypes = Dropdowns::getSocialSubtypes ();
137:             $visibilityFilters = array (
138:                 '1'=>'Public',
139:                 '0'=>'Private',
140:             );
141:             $chartSettingsData = self::getChartSettingsProvider ($this->chartType)->data;
142:             $this->_setupScript = parent::getSetupScript ()."
143:                 $(function () {
144:                     var chartUID = '$this->chartType$this->widgetUID';
145:                     x2[chartUID] = {};
146:                     x2[chartUID].chart = X2Chart.instantiateTemporarySubtype (
147:                         X2EventsChart, {
148:                         ".(isset ($chartData) ?
149:                             "chartData :".CJSON::encode ($chartData)."," : '')."
150:                         actionParams: ".CJSON::encode (array (
151:                             'widgetType' => get_called_class (),
152:                         )).",
153:                         socialSubtypes:".CJSON::encode (array_keys ($socialSubtypes)).",
154:                         visibilityTypes:".CJSON::encode (array_keys ($visibilityFilters)).",
155:                         eventTypes:".CJSON::encode (array_keys ($userNames)).", 
156:                         translations: ".CJSON::encode ($this->getTranslations ()).",
157:                         getChartDataActionName: 'getEventsBetween',
158:                         saveChartSetting: function (key, value, callback) {
159:                             this.lastChartSettings[key] = value;
160:                             x2.$widgetClass$this->widgetUID.setProperty (
161:                                 'chartSettings', this.lastChartSettings, callback);
162:                         },
163:                         suppressDateRangeSelector: false,
164:                         suppressChartSettings: false,
165:                         lastChartSettings: ".CJSON::encode ($this->getChartSettings ()).",
166:                         widgetUID: '$this->widgetUID',
167:                         chartType: '$this->chartType',
168:                         chartSubtype: '".self::getJSONProperty (
169:                             $this->profile, 'chartSubtype', $this->widgetType, $this->widgetUID)."',
170:                         chartSettings: ".CJSON::encode (
171:                             count ($chartSettingsData) ? array_combine (
172:                                 array_map (function ($setting) {
173:                                     return $setting->name;
174:                                 }, $chartSettingsData),
175:                                 $chartSettingsData) : array ())."
176:                     });
177:                     $(document).trigger ('$this->chartType' + 'Ready');
178:                 });
179:             ";
180:         }
181:         return $this->_setupScript;
182:     }
183: 
184:     public function getViewFileParams () {
185:         if (!isset ($this->_viewFileParams)) {
186:             $this->_viewFileParams = array_merge (
187:                 parent::getViewFileParams (),
188:                 array (
189:                     'userNames' => User::getNames (),
190:                     'socialSubtypes' => Dropdowns::getSocialSubtypes (),
191:                     'visibilityFilters' => array (
192:                         '1'=>'Public',
193:                         '0'=>'Private',
194:                     ),
195:                     'chartSettingsDataProvider' => self::getChartSettingsProvider (
196:                         $this->chartType),
197:                     'suppressChartSettings' => false,
198:                     'metricTypes' => array (
199:                         'any'=>Yii::t('app', 'All Events'),
200:                         'notif'=>Yii::t('app', 'Notifications'),
201:                         'feed'=>Yii::t('app', 'Feed Events'),
202:                         'comment'=>Yii::t('app', 'Comments'),
203:                         'record_create'=>Yii::t('app', 'Records Created'),
204:                         'record_deleted'=>Yii::t('app', 'Records Deleted'),
205:                         'weblead_create'=>Yii::t('app', 'Webleads Created'),
206:                         'workflow_start'=>Yii::t('app', '{Process} Started', array(
207:                             '{Process}' => Modules::displayName(false, 'Workflow')
208:                         )),
209:                         'workflow_complete'=>Yii::t('app', '{Process} Complete', array(
210:                             '{Process}' => Modules::displayName(false, 'Workflow')
211:                         )),
212:                         'workflow_revert'=>Yii::t('app', '{Process} Reverted', array(
213:                             '{Process}' => Modules::displayName(false, 'Workflow')
214:                         )),
215:                         'email_sent'=>Yii::t('app', 'Emails Sent'),
216:                         'email_opened'=>Yii::t('app', 'Emails Opened'),
217:                         'web_activity'=>Yii::t('app', 'Web Activity'),
218:                         'case_escalated'=>Yii::t('app', 'Cases Escalated'),
219:                         'calendar_event'=>Yii::t('app', '{Calendar} Events', array(
220:                             '{Calendar}' => Modules::displayName(false, 'Calendar')
221:                         )),
222:                         'action_reminder'=>Yii::t('app', '{Action} Reminders', array(
223:                             '{Action}' => Modules::displayName(false, 'Actions')
224:                         )),
225:                         'action_complete'=>Yii::t('app', '{Actions} Completed', array(
226:                             '{Actions}' => Modules::displayName(true, 'Actions')
227:                         )),
228:                         'doc_update'=>Yii::t('app', 'Doc Updates'),
229:                         'email_from'=>Yii::t('app', 'Email Received'),
230:                         'voip_calls'=>Yii::t('app', 'VOIP Calls'),
231:                         'media'=>Yii::t('app', '{Media}', array(
232:                             '{Media}' => Modules::displayName(true, 'Media')
233:                         ))
234:                     ),
235:                     'chartType' => 'eventsChart',
236:                     'widgetUID' => $this->widgetUID,
237:                 )
238:             );
239:         }
240:         return $this->_viewFileParams;
241:     } 
242: 
243:     /**
244:      * overrides parent method. Adds JS file necessary to run the setup script.
245:      */
246:     public function getPackages () {
247:         if (!isset ($this->_packages)) {
248:             $this->_packages = array_merge (
249:                 parent::getPackages (),
250:                 array (
251:                     'EventsChartProfileWidgetJS' => array(
252:                         'baseUrl' => Yii::app()->request->baseUrl,
253:                         'js' => array(
254:                             'js/X2Chart/X2EventsChart.js',
255:                         ),
256:                         'depends' => array ('ChartWidgetJS')
257:                     ),
258:                 )
259:             );
260:         }
261:         return $this->_packages;
262:     }
263: 
264:     /**
265:      * @return array translations to pass to JS objects 
266:      */
267:     protected function getTranslations () {
268:         if (!isset ($this->_translations )) {
269:             $this->_translations = array_merge (
270:                 parent::getTranslations (),
271:                 array (
272:                     'metric1Label' => Yii::t('app', 'metric(s) selected'),
273:                     'user(s) selected' => Yii::t('app', 'user(s) selected'),
274:                     'event subtype(s) selected' => Yii::t('app', 'event subtype(s) selected'),
275:                     'visibility setting(s) selected' => Yii::t(
276:                         'app', 'visibility setting(s) selected'),
277:                 )
278:             );
279:         }
280:         return $this->_translations;
281:     }
282: 
283:     /**
284:      * Collect initial chart data so the client doesn't have to request it via ajax .
285:      * Decreases time before chart render after page is loaded.
286:      */
287:     protected function getInitialChartData () {
288:         /* 
289:         Chart data only needs to be sent with initial response if chart was
290:         left open.
291:         */
292:         if (self::getJSONProperty (
293:             $this->profile, 'minimized', $this->widgetType, $this->widgetUID)) {
294: 
295:             $tsDict = $this->getStartEndTimestamp (time () - self::SECPERWEEK, time ());
296:             $startDate = $tsDict[0];
297:             $endDate = $tsDict[1];
298:             $events = self::getChartData ($startDate, $endDate);
299:             return $events;
300:         }
301:     }
302: 
303: }
304: ?>
305: 
X2CRM Documentation API documentation generated by ApiGen 2.8.0