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: /*****************************************************************************************
  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:  * CModelBehavior class for route lookups on classes.
 40:  *
 41:  * X2LinkableBehavior is a CModelBehavior which allows consistent lookup of Yii
 42:  * routes, HTML links and autcomplete sources.
 43:  *
 44:  * @package application.components
 45:  * @property string $module The module this record "belongs" to
 46:  * @property string $baseRoute The default module/controller path for this record's module
 47:  * @property string $viewRoute The default action to view this record
 48:  * @property string $autoCompleteSource The action to user for autocomplete data
 49:  */
 50: class X2LinkableBehavior extends CActiveRecordBehavior {
 51: 
 52:     public $baseRoute;
 53:     public $viewRoute;
 54:     public $autoCompleteSource;
 55:     public $icon;
 56: 
 57:     /**
 58:      * Stores {@link module}
 59:      * @var string
 60:      */
 61:     private $_module;
 62:     
 63:     /**
 64:      * Attaches the behavior object to the model.
 65:      *
 66:      * @param string $owner The component to which the behavior will be applied
 67:      */
 68:     public function attach($owner) {
 69: 
 70:         parent::attach($owner);
 71: 
 72:         if ($this->getModule() === null){
 73:             // Resolve the module
 74:             if(isset($this->baseRoute)){
 75:                 // Try to extract it from $baseRoute (old custom modules)
 76:                 $this->module = preg_replace(
 77:                         '/\/.*/', '', preg_replace('/^\//', '', $this->baseRoute));
 78:             }else{
 79:                 // Assume the model name is the same as the module/controller
 80:                 // (also true of custom modules)
 81:                 $this->module = strtolower(get_class($this->owner));
 82:             }
 83:         }
 84: 
 85:         if (!isset($this->baseRoute))
 86:             $this->baseRoute = '/' . $this->module;
 87: 
 88:         if (!isset($this->viewRoute)) {
 89:             $this->viewRoute = $this->baseRoute;
 90:         }
 91:         if (Yii::app()->params->isMobileApp) {
 92:             $this->viewRoute .= '/mobileView';
 93:         }
 94: 
 95: 
 96:         if(!isset($this->autoCompleteSource))
 97:             $this->autoCompleteSource = 
 98:                 $this->baseRoute.'/getItems?modelType='.get_class ($this->owner);
 99:     }
100: 
101:     /**
102:      * Gets the {@link module} property.
103:      * @return string|null
104:      */
105:     public function getModule() {
106:         if(isset($this->_module)) {
107:             return $this->_module;
108:         } else if(property_exists($this->owner,'module')) {
109:             return $this->owner->module;
110:         } else {
111:             return null;
112:         }
113:     }
114: 
115:     /**
116:      * Generates a url to the view of the object.
117:      *
118:      * @return string a url to the model
119:      */
120:     public function getUrl(){
121:         $url = null;
122:         // Use the controller
123:         if(Yii::app()->controller instanceof CController && !Yii::app()->controller instanceof ProfileController) {
124:             $url = Yii::app()->controller->createAbsoluteUrl($this->viewRoute, array('id' => $this->owner->id));
125:         }
126:         if(empty($url)) { // Construct an absolute URL; no web request data available.
127:             $url = Yii::app()->absoluteBaseUrl.'/index.php'.$this->viewRoute.'/'.$this->owner->id;
128:         }
129:         return $url;
130:     }
131: 
132:     /**
133:      * @return array keys corresponding to names of record types which are linkable from within 
134:      *  X2Touch
135:      */
136:     private static $_mobileLinkableRecordTypes;
137:     public static function getMobileLinkableRecordTypes () {
138:         if (!isset (self::$_mobileLinkableRecordTypes)) {
139:             self::$_mobileLinkableRecordTypes = array_flip (array_merge (array (
140:                 'Contacts',
141:                 'Accounts',
142:                 'X2Leads',
143:                 'Opportunity',
144:                 'User',
145:                 'Product',
146:                 'Quote',
147:                 'BugReports',
148:             ), Yii::app()->db->createCommand ("
149:                 select name
150:                 from x2_modules
151:                 where custom and name
152:             ")->queryColumn ()));
153:         }
154:         return self::$_mobileLinkableRecordTypes;
155:     }
156: 
157:     public static function isMobileLinkableRecordType ($type) {
158:         $mobileLinkableRecordTypes = self::getMobileLinkableRecordTypes ();
159:         return isset ($mobileLinkableRecordTypes[$type]);
160:     }
161: 
162:     /**
163:      * Generates a link to the view of the object.
164:      *
165:      * @return string a link to the model
166:      */
167:     public function getUrlLink($htmlOptions=array ()) {
168:         if (Yii::app()->params->isMobileApp && 
169:             !self::isMobileLinkableRecordType (get_class ($this->owner))) {
170: 
171:             return $this->owner->renderAttribute ('name');
172:         }
173: 
174:         $name = ($this->owner->hasAttribute('name') || $this->owner->canGetProperty('name') || 
175:             property_exists($this->owner, 'name')) ? $this->owner->name : '';
176:         if(trim($name) == '') {
177:             if ($this->owner->hasAttribute('fileName')) { // for media models
178:                 $name = $this->owner->fileName;
179:             }
180:             if(trim($name) == '') {
181:                 $name = $this->owner->hasAttribute('id') ? '#'.$this->owner->id : '';
182:             }
183:         }
184: 
185:         $url = $this->url;
186:         if($this->owner instanceof Contacts){
187:             return CHtml::link(
188:                 '<span>'.X2Html::encode($name).'</span>',
189:                 $url,
190:                 array_merge (array(
191:                     'class'=>'contact-name'
192:                 ), $htmlOptions)
193:             );
194:         }else{
195:             return CHtml::link(
196:                 '<span>'.X2Html::encode($name).'</span>',
197:                 $url,
198:                 $htmlOptions
199:             );
200:         }
201:     }
202: 
203:     /**
204:      * Generates a link to the view of the object.
205:      *
206:      * @return string a link to the model
207:      */
208:     public function getLink($htmlOptions=array ()) {
209:         return $this->getUrlLink ($htmlOptions);
210:     }
211: 
212:     /**
213:      * @return string a link to the model view, or just the name if no ID is set
214:      */
215:     public function createLink() {
216:         if(isset($this->owner->id))
217:             return $this->getLink();
218:         else
219:             return $this->owner->name;
220:     }
221: 
222:     /**
223:      * Accessor method for $autoCompleteSource
224:      *
225:      * @return string $autoCompleteSource
226:      */
227:     public function getAutoCompleteSource() {
228:         return $this->autoCompleteSource;
229:     }
230: 
231:     /**
232:      * Get autocomplete options 
233:      * @param string $term
234:      */
235:     public static function getItems($term, $valueAttr='name', $nameAttr='id', $modelClass=null) {
236:         if (!$modelClass)
237:             $modelClass = Yii::app()->controller->modelClass;
238:         $model = X2Model::model($modelClass);
239: 
240:         if (isset($model)) {
241:             $modelClass::checkThrowAttrError (array ($valueAttr, $nameAttr));
242:             $tableName = $model->tableName();
243:             $qterm = $term . '%';
244:             $params = array (
245:                 ':qterm' => $qterm,
246:             );
247:             $sql = "
248:                 SELECT $nameAttr as id, $valueAttr as value 
249:                 FROM " . $tableName . " as t
250:                 WHERE $valueAttr LIKE :qterm";
251:             if ($model->asa ('permissions')) {
252:                 list ($accessCond, $permissionsParams) = $model->getAccessSQLCondition ();
253:                 $sql .= ' AND '.$accessCond;
254:                 $params = array_merge ($params, $permissionsParams);
255:             }
256:                 
257:             $sql .= "ORDER BY $valueAttr ASC";
258:             $command = Yii::app()->db->createCommand($sql);
259:             $result = $command->queryAll(true, $params);
260:             echo CJSON::encode($result);
261:         }
262:         Yii::app()->end();
263:     }
264: 
265:     /**
266:      * Improved version of getItems which enables use of empty search string, pagination, and
267:      * configurable option values/names.
268:      * @param string $prefix name prefix of items to retrieve
269:      * @param int $page page number of results to retrieve (ignored if limit is -1)
270:      * @param int $limit max number of results to retrieve (-1 to disable limit)
271:      * @param string|array $valueAttr attribute(s) used to popuplate the option values. If an 
272:      *  array is passed, value will composed of values of each of the attributes specified, joined
273:      *  by commas
274:      * @param string $nameAttr attribute used to popuplate the option names
275:      * @return array name, value pairs
276:      */
277:     public function getItems2 (
278:         $prefix='', $page=0, $limit=20, $valueAttr='name', $nameAttr='name') {
279: 
280:         $modelClass = get_class ($this->owner);
281:         $model = CActiveRecord::model ($modelClass);
282:         $table = $model->tableName ();
283:         $offset = intval ($page) * intval ($limit);
284: 
285:         AuxLib::coerceToArray ($valueAttr);
286:         $modelClass::checkThrowAttrError (array_merge ($valueAttr, array ($nameAttr)));
287:         $params = array ();
288:         if ($prefix !== '') {
289:             $params[':prefix'] = $prefix . '%';
290:         }
291:         if ($limit !== -1) {
292:             $offset = abs ((int) $offset);
293:             $limit = abs ((int) $limit);
294:             $limitClause = "LIMIT $offset, $limit";
295:         } 
296: 
297:         if ($model->asa ('permissions')) {
298:             list ($accessCond, $permissionsParams) = $model->getAccessSQLCondition ();
299:             $params = array_merge ($params, $permissionsParams);
300:         }
301: 
302:         $command = Yii::app()->db->createCommand ("
303:             SELECT " . implode (',', $valueAttr) . ", $nameAttr as __name
304:             FROM $table as t
305:             WHERE " . ($prefix === '' ? 
306:                '1=1' : ($nameAttr . ' LIKE :prefix')
307:             ) . (isset ($accessCond) ? " AND $accessCond" : '') . "
308:             ORDER BY __name
309:             ". (isset ($limitClause) ? $limitClause : '') ."
310:         ");
311:         $rows = $command->queryAll (true, $params);
312: 
313:         $items = array ();
314:         foreach ($rows as $row) {
315:             $name = $row['__name'];
316:             unset ($row['__name']);
317:             $items[] = array ($name, $row);
318:         }
319: 
320:         return $items;
321:     }
322: 
323:     /**
324:      * Sets the {@link module} property
325:      * @param string $value
326:      */
327:     public function setModule($value) {
328:         $this->_module = $value;
329:     }
330: 
331: }
332: 
X2CRM Documentation API documentation generated by ApiGen 2.8.0