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: /*****************************************************************************************
  4:  * X2Engine Open Source Edition is a customer relationship management program developed by
  5:  * X2Engine, Inc. Copyright (C) 2011-2016 X2Engine Inc.
  6:  * 
  7:  * This program is free software; you can redistribute it and/or modify it under
  8:  * the terms of the GNU Affero General Public License version 3 as published by the
  9:  * Free Software Foundation with the addition of the following permission added
 10:  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
 11:  * IN WHICH THE COPYRIGHT IS OWNED BY X2ENGINE, X2ENGINE DISCLAIMS THE WARRANTY
 12:  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 13:  * 
 14:  * This program is distributed in the hope that it will be useful, but WITHOUT
 15:  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 16:  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
 17:  * details.
 18:  * 
 19:  * You should have received a copy of the GNU Affero General Public License along with
 20:  * this program; if not, see http://www.gnu.org/licenses or write to the Free
 21:  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 22:  * 02110-1301 USA.
 23:  * 
 24:  * You can contact X2Engine, Inc. P.O. Box 66752, Scotts Valley,
 25:  * California 95067, USA. or at email address contact@x2engine.com.
 26:  * 
 27:  * The interactive user interfaces in modified source and object code versions
 28:  * of this program must display Appropriate Legal Notices, as required under
 29:  * Section 5 of the GNU Affero General Public License version 3.
 30:  * 
 31:  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 32:  * these Appropriate Legal Notices must retain the display of the "Powered by
 33:  * X2Engine" logo. If the display of the logo is not reasonably feasible for
 34:  * technical reasons, the Appropriate Legal Notices must display the words
 35:  * "Powered by X2Engine".
 36:  *****************************************************************************************/
 37: 
 38: /**
 39:  * @package application.components.sortableWidget
 40:  */
 41: abstract class TransactionalViewWidget extends GridViewWidget {
 42: 
 43:     /**
 44:      * @var CActiveRecord 
 45:      */
 46:     public $model;
 47: 
 48:     /**
 49:      * @var TwoColumnSortableWidgetManager $widgetManager
 50:      */
 51:     public $widgetManager;
 52:     public $viewFile = '_transactionalViewWidget';
 53:     public $template = '<div class="submenu-title-bar widget-title-bar">{widgetLabel}{createButton}{closeButton}{minimizeButton}{settingsMenu}</div>{widgetContents}';
 54:     public $sortableWidgetJSClass = 'x2.TransactionalViewWidget';
 55: 
 56:     protected $compactResultsPerPage = true;
 57:     protected $createButtonLabel = '';
 58:     protected $labelIconClass = '';
 59:     protected $historyType;
 60:     protected $_dataProvider;
 61:     protected $_gridViewConfig;
 62:     protected $_searchModel;
 63:     protected $containerClass = 'sortable-widget-container x2-layout-island transactional-view-widget';
 64:     
 65: 
 66:     private static $_JSONPropertiesStructure;
 67: 
 68:     protected function getSearchModel() {
 69:         if (!isset($this->_searchModel)) {
 70:             $this->_searchModel = new Actions('search', $this->widgetKey);
 71:         }
 72:         return $this->_searchModel;
 73:     }
 74: 
 75:     public static function getJSONPropertiesStructure() {
 76:         if (!isset(self::$_JSONPropertiesStructure)) {
 77:             self::$_JSONPropertiesStructure = array_merge(
 78:                 parent::getJSONPropertiesStructure(), array(
 79:                     'showHeader' => false,
 80:                     'resultsPerPage' => 5,
 81:                     'hideFullHeader' => true, 
 82:                 )
 83:             );
 84:         }
 85:         return self::$_JSONPropertiesStructure;
 86:     }
 87: 
 88:     public function getPackages() {
 89:         if (!isset($this->_packages)) {
 90:             $this->_packages = array_merge(parent::getPackages(), array(
 91:                 'TransactionalViewWidgetJS' => array(
 92:                     'baseUrl' => Yii::app()->request->baseUrl,
 93:                     'js' => array(
 94:                         'js/sortableWidgets/TransactionalViewWidget.js',
 95:                     ),
 96:                 ),
 97:             ));
 98:         }
 99:         return $this->_packages;
100:     }
101: 
102:     public function getSharedCssFileNames() {
103:         if (!isset($this->_sharedCssFileNames)) {
104:             $this->_sharedCssFileNames = array_merge(parent::getSharedCssFileNames(), array(
105:                 'components/sortableWidget/recordViewWidgets/TransactionalViewWidget.css',
106:             ));
107:         }
108:         return $this->_sharedCssFileNames;
109:     }
110: 
111:     public function getIcon() {
112:         return X2Html::fa($this->labelIconClass, array(
113:                     'class' => 'widget-label-icon',
114:         ));
115:     }
116: 
117:     public function renderWidgetLabel() {
118:         $label = $this->getWidgetLabel();
119:         $count = $this->dataProvider->totalItemCount;
120:         echo 
121:             "<div class='widget-title'>" .
122:                 $this->getIcon() .
123:                 htmlspecialchars($label) .
124:                 "&nbsp(<span class='transaction-count'>" . $count . "</span>)
125:              </div>";
126:     }
127: 
128:     public function getCreateButtonTitle() {
129:         return '';
130:     }
131: 
132:     public function getCreateButtonText() {
133:         return '';
134:     }
135: 
136:     public function renderCreateButton() {
137:         echo
138:             "<button class='x2-button create-button'
139:               title='" . CHtml::encode($this->createButtonTitle) . "'>
140:                 <span class='fa fa-plus'></span>" .
141:                 CHtml::encode($this->createButtonText) . 
142:             "</button>";
143:     }
144: 
145:     /**
146:      * @return object Data provider object to be used for the grid view
147:      */
148:     public function getDataProvider() {
149:         if (!isset($this->_dataProvider)) {
150:             $resultsPerPage = $this->getWidgetProperty(
151:                     'resultsPerPage');
152:             $historyCmd = History::getCriteria(
153:                 $this->model->id, 
154:                 X2Model::getAssociationType(get_class($this->model)),
155:                 Yii::app()->params->profile->historyShowRels,
156:                 $this->historyType
157:             );
158: 
159:             $this->_dataProvider = new CSqlDataProvider($historyCmd['cmd'], array(
160:                 'totalItemCount' => $historyCmd['count'],
161:                 'params' => $historyCmd['params'],
162:                 'pagination' => array(
163:                     'pageSize' => $resultsPerPage,
164:                 ),
165:             ));
166: //            $this->_dataProvider = $this->getSearchModel()->search(
167: //                    History::getCriteria(
168: //                            $this->model->id, X2Model::getAssociationType(get_class($this->model)), $this->getWidgetProperty('showRelatedRecords'), $this->historyType), $resultsPerPage
169: //            );
170:             // clear order set by Actions::search and History::getCriteria
171:             //$this->_dataProvider->criteria->order = '';
172:         }
173:         return $this->_dataProvider;
174:     }
175: 
176:     protected function getActionDescriptionHeader() {
177:         return Yii::t(
178:             'actions', 
179:             '{action} Description', 
180:             array('{action}' => Modules::displayName(false, 'Actions')));
181:     }
182: 
183:     public function getAjaxUpdateRouteAndParams() {
184:         list ($updateRoute, $updateParams) = parent::getAjaxUpdateRouteAndParams();
185:         $updateParams = array_merge($updateParams, array(
186:             'modelId' => $this->model->id,
187:             'modelType' => get_class($this->model),
188:         ));
189:         return array($updateRoute, $updateParams);
190:     }
191: 
192: 
193:     /**
194:      * @param array $collapse each entry should be an array of integers, corresponding to the
195:      *  indexes of columns whose widths will be combined
196:      * Precondition: Columns cannot be combined if their widths are of different types (percent vs.
197:      *  integer)
198:      * @return array width of column sizes 
199:      */
200:     public function getColumnWidths (array $collapse=array ()) {
201:         if (!Yii::app()->params->profile->historyShowRels) {
202:             $columnWidths = array (
203:                 '52%', 
204:                 '22%', 
205:                 '12%', 
206:                 '106', 
207:                 '60', 
208:             );
209:         } else {
210:             $columnWidths = array (
211:                 '42%', 
212:                 '22%', 
213:                 '22%', 
214:                 '106', 
215:                 '60', 
216:             );
217:         }
218: 
219:         $addWidths = function ($widthA, $widthB) {
220:             if (preg_match ('/%/', $widthA) && preg_match ('/%/', $widthB)) {
221:                 return $widthA + $widthB . '%';
222:             } else if (!preg_match ('/%/', $widthA) && !preg_match ('/%/', $widthB)) {
223:                 return $widthA + $widthB;
224:             } else {
225:                 throw new CException ('Type mismatch: widths cannot be added');
226:             }
227:         };
228: 
229:         // combine columns, adding column widths
230:         foreach ($collapse as $cols) {
231:             $rest = $cols;
232:             unset ($rest[0]);
233:             $collapsedWidth = $columnWidths[$cols[0]];
234:             foreach ($rest as $otherCol) {
235:                 $collapsedWidth = $addWidths ($collapsedWidth, $columnWidths[$otherCol]);
236:                 unset ($columnWidths[$otherCol]);
237:             }
238:             $columnWidths[$cols[0]] = $collapsedWidth;
239:         }
240: 
241:         return $columnWidths;
242:     }
243: 
244:     /**
245:      * Build defaultGvSettings property for X2GridView
246:      */
247:     public function buildDefaultGvSettings ($attributes, array $combine = array ()) {
248:         return array_combine (
249:             $attributes,
250:             $this->getColumnWidths ($combine)
251:         );
252:     }
253: 
254:     /**
255:      * @return array the config array passed to widget ()
256:      */
257:     public function getGridViewConfig() {
258:         if (!isset($this->_gridViewConfig)) {
259:             $this->_gridViewConfig = array_merge(parent::getGridViewConfig(), array(
260:                 'possibleResultsPerPage' => array(5, 10, 20, 30, 40, 50, 75, 100),
261:                 'sortableWidget' => $this,
262:                 'moduleName' => 'Actions',
263:                 'sortableWidget' => $this,
264:                 'id' => get_called_class() . '_' . $this->widgetUID,
265:                 'fieldFormatter' => 'TransactionalViewFieldFormatter',
266:                 'enableColDragging' => false,
267:                 'evenPercentageWidthColumns' => true,
268:                 'enableGridResizing' => false,
269:                 'enableScrollOnPageChange' => false,
270:                 'buttons' => array('clearFilters', 'columnSelector', 'autoResize'),
271:                 'template' => '{summary}{items}{pager}',
272:                 'fixedHeader' => false,
273:                 'dataProvider' => $this->dataProvider,
274:                 //'filter' => $this->model,
275:                 'pager' => array('class' => 'CLinkPager', 'maxButtonCount' => 10),
276:                 'modelName' => 'Actions',
277:                 'viewName' => 'profile',
278:                 'gvSettingsName' => get_called_class() . $this->widgetUID,
279:                 'enableControls' => true,
280:                 //'filter' => new Actions('search', $this->widgetKey),
281:                 'fullscreen' => false,
282:                 'enableSelectAllOnAllPages' => false,
283:                 'hideSummary' => true,
284:                 'enableGvSettings' => false,
285:                 'defaultGvSettings' => $this->buildDefaultGvSettings (
286:                     array (
287:                         'actionDescription',
288:                         'assignedTo',
289:                         'createDate',
290:                     ), array (array (1, 2), array (3, 4))
291:                 ),
292:                 'specialColumns' => array(
293:                     'actionDescription' => array(
294:                         'header' => $this->getActionDescriptionHeader(),
295:                         'name' => 'actionDescription',
296:                         'value' => 'Actions::model()->findByPk($data["id"])->frameLink ()',
297:                         'type' => 'raw',
298:                         'filter' => false,
299:                         'htmlOptions' => array(
300:                             'title' => 'php:CHtml::encode(Formatter::trimText(Actions::model()->findByPk($data["id"])->actionDescription))',
301:                         )
302:                     ),
303:                 ),
304:             ));
305:             $this->_gridViewConfig['specialColumns']['associationName'] = array(
306:                     'header' => Yii::t('app', 'Association'),
307:                     'name' => 'associationName',
308:                     'value' => '$data->getAssociationLink ()',
309:                     'type' => 'raw',
310:                     'filter' => false,
311:                 );
312:             if (Yii::app()->params->profile->historyShowRels) {
313:                 $this->_gridViewConfig['defaultGvSettings'] = $this->buildDefaultGvSettings (
314:                     array (
315:                         'actionDescription',
316:                         'assignedTo',
317:                         'associationName',
318:                         'createDate',
319:                     ), array (array (3, 4)) 
320:                 );
321:             }
322:         }
323:         return $this->_gridViewConfig;
324:     }
325: 
326:     public function run() {
327:         $tabs = Yii::app()->settings->actionPublisherTabs;
328:         $actionTypeToTab = Publisher::$actionTypeToTab;
329: 
330:         if (isset($this->widgetManager) && $this->widgetManager->layoutManager->staticLayout) {
331:             // don't display transactional view widgets on legacy record view pages (e.g. on old
332:             // custom modules)
333:             return;
334:         }
335: 
336:         // don't display widget if corresponding tab isn't enabled
337:         if ($tabs && isset($actionTypeToTab[$this->historyType]) &&
338:             isset($tabs[$actionTypeToTab[$this->historyType]]) &&
339:             !$tabs[$actionTypeToTab[$this->historyType]]) {
340: 
341:             return;
342:         }
343:         // hide widget if transactional view is disabled
344:         if (!Yii::app()->params->profile->miscLayoutSettings['enableTransactionalView']) {
345:             $this->registerSharedCss();
346:             $this->render(
347:                 'application.components.sortableWidget.views.' . $this->sharedViewFile, 
348:                 array(
349:                     'widgetClass' => get_called_class(),
350:                     'profile' => $this->profile,
351:                     'hidden' => true,
352:                     'widgetUID' => $this->widgetUID,
353:                 ));
354:             return;
355:         }
356:         parent::run();
357:     }
358: 
359:     protected function getJSSortableWidgetParams() {
360:         if (!isset($this->_JSSortableWidgetParams)) {
361:             $this->_JSSortableWidgetParams = array_merge(
362:                 parent::getJSSortableWidgetParams(), 
363:                 array(
364:                     'actionType' => $this->historyType,
365:                     'modelName' => get_class($this->model),
366:                     'modelId' => $this->model->id,
367:                 )
368:             );
369:         }
370:         return $this->_JSSortableWidgetParams;
371:     }
372: 
373:     protected function getTranslations() {
374:         if (!isset($this->_translations)) {
375:             $this->_translations = array_merge(parent::getTranslations(), array(
376:                 'dialogTitle' => ucwords($this->createButtonTitle),
377:             ));
378:         }
379:         return $this->_translations;
380:     }
381: 
382:     protected function getSettingsMenuContentEntries () {
383:         return 
384:             parent::getSettingsMenuContentEntries ().
385:             '<li class="relationships-toggle x2-hint" title="'.
386:                 CHtml::encode (
387:                     Yii::t(
388:                         'app', 
389:                         'Click to toggle showing actions associated with related records.')).
390:             '">'.
391:                 X2Html::checkbox ('historyShowRels', Yii::app()->params->profile->historyShowRels).
392:                 '<span for="historyShowRels">'.
393:                     CHtml::encode (Yii::t('profile', 'Relationships')).'</span>'.
394:             '</li>';
395:     }
396: 
397: }
398: 
399: ?>
400: 
X2CRM Documentation API documentation generated by ApiGen 2.8.0