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: /**
 38:  * Widget class for the relationships form.
 39:  *
 40:  * Relationships lists the relationships a model has with other models,
 41:  * and provides a way to add existing models to the models relationships.
 42:  *
 43:  * @package application.components.sortableWidget
 44:  */
 45: class InlineRelationshipsWidget extends GridViewWidget {
 46: 
 47:      
 48: 
 49:     public $viewFile = '_inlineRelationshipsWidget';
 50: 
 51:     public $model;
 52: 
 53:     public $template = '<div class="submenu-title-bar widget-title-bar">{widgetLabel}{titleBarButtons}{closeButton}{minimizeButton}{settingsMenu}</div>{widgetContents}';
 54: 
 55:     /**
 56:      * Used to prepopulate create relationship forms
 57:      * @var array (<model class> => <array of default values indexed by attr name>)
 58:      */
 59:     public $defaultsByRelatedModelType = array ();
 60: 
 61:     protected $compactResultsPerPage = true; 
 62: 
 63:     private $_relatedModels;
 64: 
 65:     private static $_JSONPropertiesStructure;
 66: 
 67:     public static function getJSONPropertiesStructure () {
 68:         if (!isset (self::$_JSONPropertiesStructure)) {
 69:             self::$_JSONPropertiesStructure = array_merge (
 70:                 parent::getJSONPropertiesStructure (),
 71:                 array (
 72:                     'label' => 'Relationships',
 73:                     'hidden' => false,
 74:                     'resultsPerPage' => 10, 
 75:                     'showHeader' => false,
 76:                     'displayMode' => 'grid', // grid | graph
 77:                     'height' => '200',
 78:                     'hideFullHeader' => true, 
 79:                 )
 80:             );
 81:         }
 82:         return self::$_JSONPropertiesStructure;
 83:     }
 84: 
 85:     private $_filterModel;
 86:     public function getFilterModel () {
 87:         if (!isset ($this->_filterModel)) {
 88:             $model = $this->model;
 89:             $filterModel = new RelationshipsGridModel ('search');
 90:             $filterModel->myModel = $model;
 91:             $filterModel->init ();
 92:             $this->_filterModel = $filterModel;
 93:         }
 94:         return $this->_filterModel;
 95:     }
 96: 
 97:     public function getDataProvider () {
 98:         $model = $this->model;
 99:         $filterModel = $this->getFilterModel ();
100: 
101:         // convert related models into grid models
102:         $gridModels = array ();
103:         foreach ($model->visibleRelatedX2Models as $relatedModel) {
104:             $gridModel = Yii::createComponent (array (
105:                 'class' => 'RelationshipsGridModel', 
106:                 'relatedModel' => $relatedModel,
107:                 'myModel' => $model,
108:             ));
109:             $gridModel->init ();
110:             $gridModels[] = $gridModel;
111:         }
112: 
113:         // use filter model to filter grid models based on GET params
114:         $gridModels = $filterModel->filterModels ($gridModels);
115:         //$gridModels = $filterModel->sortModels ($gridModels, $this->widgetKey.'_sort');
116: 
117:         $sort = Yii::createComponent (array (
118:             'class' => 'SmartSort',
119:             'uniqueId' => $this->widgetKey,
120:             'sortVar' => $this->widgetKey.'_sort',
121:             'attributes'=>array('name','relatedModelName','label','createDate','assignedTo'),
122:             'defaultOrder' => 'id desc',
123:             'alwaysApplyDefaultOrder' => true
124:         ));
125: 
126:         $relationshipsDataProvider = new CArrayDataProvider($gridModels, array(
127:             'id' => 'relationships-gridview',
128:             'sort' => $sort,
129:             'pagination' => array('pageSize'=>$this->getWidgetProperty ('resultsPerPage'))
130:         ));
131:         return $relationshipsDataProvider;
132:     }
133: 
134:     public function renderTitleBarButtons () {
135:         echo '<div class="x2-button-group">';
136:         if ($this->checkModuleUpdatePermissions ()) {
137:             echo 
138:                 "<a class='x2-button rel-title-bar-button' id='new-relationship-button' 
139:                   title='".CHtml::encode (Yii::t('app', 'Create a new relationship'))."'>".
140:                     X2Html::fa ('fa-plus', array (), ' ', 'span').
141:                 "</a>";
142:         }
143:          
144:         echo '</div>';
145:     }
146: 
147:     public function renderWidgetLabel () {
148:         $label = $this->getWidgetLabel ();
149:         $relationshipCount = count ($this->model->getVisibleRelatedX2Models ());
150:         echo "<div class='widget-title'>".
151:             htmlspecialchars($label).
152:             "&nbsp(<span id='relationship-count'>$relationshipCount</span>)</div>";
153:     }
154: 
155:     public function getSetupScript () {
156:         if (!isset ($this->_setupScript)) {
157:             $widgetClass = get_called_class ();
158:             if (isset ($_GET['ajax'])) {
159:                 $this->_setupScript = "";
160:             } else {
161:                 $modelsWhichSupportQuickCreate = 
162:                     QuickCreateRelationshipBehavior::getModelsWhichSupportQuickCreate ();
163: 
164:                 // get create action urls for each linkable model
165:                 $createUrls = QuickCreateRelationshipBehavior::getCreateUrlsForModels (
166:                     $modelsWhichSupportQuickCreate);
167: 
168:                 // get create relationship tooltips for each linkable model
169:                 $tooltips = QuickCreateRelationshipBehavior::getDialogTooltipsForModels (
170:                     $modelsWhichSupportQuickCreate, get_class ($this->model));
171: 
172:                 // get create relationship dialog titles for each linkable model
173:                 $dialogTitles = QuickCreateRelationshipBehavior::getDialogTitlesForModels (
174:                     $modelsWhichSupportQuickCreate);
175:                 $this->_setupScript = "
176:                     $(function () {
177:                         x2.inlineRelationshipsWidget = new x2.InlineRelationshipsWidget (".
178:                             CJSON::encode (array_merge ($this->getJSSortableWidgetParams (), array (
179:                                 'displayMode' => $this->getWidgetProperty ('displayMode'),
180:                                 'widgetClass' => $widgetClass,
181:                                 'setPropertyUrl' => Yii::app()->controller->createUrl (
182:                                     '/profile/setWidgetSetting'),
183:                                 'cssSelectorPrefix' => $this->widgetType,
184:                                 'widgetType' => $this->widgetType,
185:                                 'widgetUID' => $this->widgetUID,
186:                                 'enableResizing' => true,
187:                                 'height' => $this->getWidgetProperty ('height'),
188:                                 'recordId' => $this->model->id,
189:                                 'recordType' => get_class ($this->model),
190:                                 'defaultsByRelatedModelType' => 
191:                                     $this->defaultsByRelatedModelType,
192:                                 'createUrls' => $createUrls,
193:                                 'dialogTitles' => $dialogTitles,
194:                                 'tooltips' => $tooltips,
195:                                 'modelsWhichSupportQuickCreate' => 
196:                                     array_values ($modelsWhichSupportQuickCreate),
197:                                 'ajaxGetModelAutocompleteUrl' => 
198:                                     Yii::app()->controller->createUrl ('ajaxGetModelAutocomplete'),
199:                                 'createRelationshipUrl' => 
200:                                     Yii::app()->controller->createUrl (
201:                                         '/relationships/addRelationship'),
202:                                 'hasUpdatePermissions' => $this->checkModuleUpdatePermissions (),
203:                             )))."
204:                         );
205:                     });
206:                 ";
207:             }
208:         }
209:         return $this->_setupScript;
210:     }
211: 
212:     /**
213:      * overrides parent method. Adds JS file necessary to run the setup script.
214:      */
215:     public function getPackages () {
216:         if (!isset ($this->_packages)) {
217:             $this->_packages = array_merge (
218:                 parent::getPackages (),
219:                 array (
220:                     'InlineRelationshipsJSExt' => array(
221:                         'baseUrl' => Yii::app()->getTheme ()->getBaseUrl ().'/css/gridview/',
222:                         'js' => array (
223:                             'jquery.yiigridview.js',
224:                         ),
225:                         'depends' => array ('auxlib')
226:                     ),
227:                     'InlineRelationshipsJS' => array(
228:                         'baseUrl' => Yii::app()->request->baseUrl,
229:                         'js' => array (
230:                             'js/sortableWidgets/InlineRelationshipsWidget.js',
231:                         ),
232:                         'depends' => array ('SortableWidgetJS')
233:                     ),
234:                 )
235:             );
236:         }
237:         return $this->_packages;
238:     }
239: 
240:     public function getViewFileParams () {
241:         if (!isset ($this->_viewFileParams)) {
242:             $linkableModels = Relationships::getRelationshipTypeOptions ();
243:             asort ($linkableModels);
244:              
245: 
246:             // used to instantiate html dropdown
247:             $linkableModelsOptions = $linkableModels;
248: 
249:             $hasUpdatePermissions = $this->checkModuleUpdatePermissions ();
250: 
251:             $this->_viewFileParams = array_merge (
252:                 parent::getViewFileParams (),
253:                 array (
254:                     'model' => $this->model,
255:                     'modelName' => get_class ($this->model),
256:                     'linkableModelsOptions' => $linkableModelsOptions,
257:                     'hasUpdatePermissions' => $hasUpdatePermissions,
258:                      
259:                     'height' => $this->getWidgetProperty ('height'),
260:                 )
261:             );
262:         }
263:         return $this->_viewFileParams;
264:     } 
265: 
266:     protected function getSettingsMenuContentEntries () {
267:         return 
268:             '<li class="expand-detail-views">'.
269:                 X2Html::fa('fa-toggle-down').
270:                 Yii::t('profile', 'Toggle Detail Views').
271:             '</li>'.
272:             parent::getSettingsMenuContentEntries ();
273:     }
274: 
275: 
276:     private $_moduleUpdatePermissions;
277:     private function checkModuleUpdatePermissions () {
278:         if (!isset ($this->_moduleUpdatePermissions)) {
279:             $this->_moduleUpdatePermissions = 
280:                 Yii::app()->controller->checkPermissions ($this->model, 'edit');
281:         }
282:         return $this->_moduleUpdatePermissions;
283:     }
284: 
285:     public function init ($skipGridViewInit=false) {
286:         return parent::init (true);
287:     }
288: }
289: 
290: ?>
291: 
X2CRM Documentation API documentation generated by ApiGen 2.8.0