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

  • ActionFormModel
  • ArrayUtil
  • ArrayValidator
  • AssociatedMediaBehavior
  • AuxLib
  • Changelog
  • DetailView
  • EncryptUtilTmp
  • EventsWidgetFieldFormatter
  • FailedLogins
  • FieldFormatter
  • FieldFormatterBase
  • FieldInputRenderer
  • FileFieldBehavior
  • FiltersForm
  • FilterUtil
  • FineDiff
  • FineDiffCopyOp
  • FineDiffDeleteOp
  • FineDiffInsertOp
  • FineDiffOp
  • FineDiffOps
  • FineDiffReplaceOp
  • GlobalCSSFormModel
  • GlobalImportFormModel
  • GoogleAuthenticator
  • JSONFieldsBehavior
  • JSONResponse
  • MediaFieldFormatter
  • MediaSelector
  • MobileActiveRecordFieldFormatter
  • MobileActivityFeed
  • MobileChartDashboard
  • MobileFieldFormatter
  • MobileFieldInputRenderer
  • ModuleModelNameValidator
  • MultiChildNode
  • MultiTypeAutocomplete
  • PasswordUtil
  • ProductFeature
  • ProfileWidgetLayout
  • QueryParamGenerator
  • RecordLimitBehavior
  • RecordView
  • RecordViewWidgetLayout
  • RelationshipsGridModel
  • RelationshipsJoin
  • RepairUserDataCommand
  • RequestUtil
  • RequiredIfNotSetValidator
  • ResponseUtil
  • RunMigrationScriptCommand
  • ServiceWebFormDesigner
  • Settings
  • StringUtil
  • TestEmailAction
  • TestEmailActionForm
  • ThemeGenerator
  • TimerUtil
  • TopicsFieldFormatter
  • TopicsWidgetLayout
  • TransactionalViewFieldFormatter
  • UrlUtil
  • ValidLinkValidator
  • WebFormDesigner
  • WebLeadFormDesigner
  • X2ActiveRecordBehavior
  • X2ActiveRecordFieldFormatter
  • X2ButtonColumn
  • X2ConditionList
  • X2ConsoleCommand
  • X2ControllerBehavior
  • X2DataColumn
  • X2DuplicateBehavior
  • X2Flashes
  • X2GridViewFieldFormatter
  • X2IPAddress
  • X2LeadsDataColumn
  • X2MergeableBehavior
  • X2MessageSource
  • X2MobileControllerBehavior
  • X2MobileProfileControllerBehavior
  • X2MobileQuotesControllerBehavior
  • X2MobileSiteControllerBehavior
  • X2MobileTopicsControllerBehavior
  • X2ModelConversionBehavior
  • X2ModelConversionWidget
  • X2ModelForeignKeyValidator
  • X2ModelUniqueIndexValidator
  • X2NonWebUser
  • X2StaticDropdown
  • X2StaticField
  • X2StaticFieldsBehavior
  • X2UrlManager
  • X2Validator
  • X2WidgetBehavior

Interfaces

  • AdminOwnedCredentials

Exceptions

  • CampaignMailingException
  • CodeExchangeException
  • GetCredentialsException
  • NoRefreshTokenException
  • NoUserIdException
  • StringUtilException

Functions

  • checkCurrency
  • checkDNS
  • checkServerVar
  • checkTimezone
  • decodeQuotes
  • echoIcons
  • encodeQuotes
  • exceptionForError
  • getField
  • getLanguageName
  • getModuleTitle
  • handleReqError
  • handleReqException
  • installer_t
  • installer_tr
  • isAllowedDir
  • mediaMigrationRrmdir
  • migrateMediaDir
  • printGraph
  • printR
  • renderFields
  • reqShutdown
  • RIP
  • translateOptions
  • tryGetRemote
  • 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:  * Handles rendering of X2Model fields 
 39:  */
 40: 
 41: class FieldFormatter extends FieldFormatterBase {
 42: 
 43:     /**
 44:      * @var X2Model $owner
 45:      */
 46:     public $owner; 
 47: 
 48:     private $_validFieldTypes;
 49:     public function getValidFieldTypes () {
 50:         if (!isset ($this->_validFieldTypes)) {
 51:             $this->_validFieldTypes = array_keys (Fields::getFieldTypes ());
 52:         }
 53:         return $this->_validFieldTypes;
 54:     }
 55: 
 56:     public function renderAttribute(
 57:         $fieldName, $makeLinks = true, $textOnly = true, $encode = true) {
 58: 
 59:         $field = $this->owner->getField($fieldName);
 60:         if (!isset($field))
 61:             return null;
 62: 
 63:         if (!YII_UNIT_TESTING && Yii::app()->params->noSession) {
 64:             $webRequestAttributes = array(
 65:                 'rating', // Uses a Yii widget, which requires access to the controller
 66:                 'assignment', // Depends on getUserLinks, which depends on the user session
 67:                 'optionalAssignment', // Same as above
 68:                 'url', // Renders an actual link
 69:                 'text', // Uses convertUrls, which is in x2base
 70:             );
 71:             if (in_array($field->type, $webRequestAttributes))
 72:                 return $this->render($this->owner->$fieldName, $encode);
 73:         }
 74: 
 75:         $renderByNameFn = 'render'.ucfirst ($field->fieldName);
 76:         $renderByTypeFn = 'render'.ucfirst ($field->type);
 77:         // first check for field-specific renderer. Exclude field names that match an existing
 78:         // type 
 79:         if (method_exists ($this, $renderByNameFn) && 
 80:             !in_array ($field->fieldName, $this->getValidFieldTypes ())) {
 81: 
 82:             return $this->$renderByNameFn ($field, $makeLinks, $textOnly, $encode);
 83:         } elseif (method_exists ($this, $renderByTypeFn)) {
 84:             return $this->$renderByTypeFn ($field, $makeLinks, $textOnly, $encode);
 85:         } else {
 86:             return $this->render ($this->owner->$fieldName, $encode);
 87:         }
 88:     }
 89: 
 90:     /**
 91:      * Used to render user alias, instead of username 
 92:      */
 93:     protected function renderUpdatedBy ($field, $makeLinks, $textOnly, $encode) {
 94:         $fieldName = $field->fieldName;
 95:         $val = $this->owner->$fieldName;
 96:         $val = empty ($val) ? $val : User::getUserLinks ($val, false, false);
 97:         return $encode ? CHtml::encode($val) : $val;
 98:     }
 99: 
100:     protected function renderDate ($field, $makeLinks, $textOnly, $encode) {
101:         $fieldName = $field->fieldName;
102:         if (empty($this->owner->$fieldName))
103:             return ' ';
104:         elseif (is_numeric($this->owner->$fieldName))
105:             return Formatter::formatLongDate($this->owner->$fieldName);
106:         else
107:             return $this->render ($this->owner->$fieldName, $encode);
108:     }
109: 
110:     protected function renderDateTime ($field, $makeLinks, $textOnly, $encode) {
111:         $fieldName = $field->fieldName;
112:         if (empty($this->owner->$fieldName))
113:             return ' ';
114:         elseif (is_numeric($this->owner->$fieldName))
115:             return Formatter::formatCompleteDate($this->owner->$fieldName);
116:         else
117:             return $this->render ($this->owner->$fieldName, $encode);
118:     }
119: 
120:     protected function renderRating ($field, $makeLinks, $textOnly, $encode) {
121:         $fieldName = $field->fieldName;
122:         if ($textOnly) {
123:             return $this->render ($this->owner->$fieldName, $encode);
124:         } else {
125:             return Yii::app()->controller->widget('CStarRating', array(
126:                 'model' => $this->owner,
127:                 'name' => str_replace(
128:                     ' ', '-', get_class($this->owner) . '-' . $this->owner->id . '-rating-' . 
129:                     $field->fieldName),
130:                 'attribute' => $field->fieldName,
131:                 'readOnly' => true,
132:                 // If not required, render the "cancel" button to clear the rating
133:                 'allowEmpty' => !$field->required,
134:                 'minRating' => 1, //minimal valuez
135:                 'maxRating' => 5, //max value
136:                 'starCount' => 5, //number of stars
137:                 'cssFile' => Yii::app()->theme->getBaseUrl() .
138:                 '/css/rating/jquery.rating.css',
139:             ), true);
140:         }
141:     }
142: 
143:     protected function renderAssignment ($field, $makeLinks, $textOnly, $encode) {
144:         $fieldName = $field->fieldName;
145:         return User::getUserLinks($this->owner->$fieldName, $makeLinks);
146:     }
147: 
148:     protected function renderOptionalAssignment ($field, $makeLinks, $textOnly, $encode) {
149:         $fieldName = $field->fieldName;
150:         if ($this->owner->$fieldName == '')
151:             return '';
152:         else
153:             return User::getUserLinks($this->owner->$fieldName);
154:     }
155: 
156:     protected function renderVisibility ($field, $makeLinks, $textOnly, $encode) {
157:         $fieldName = $field->fieldName;
158:         switch ($this->owner->$fieldName) {
159:             case '1':
160:                 return Yii::t('app', 'Public');
161:             case '0':
162:                 return Yii::t('app', 'Private');
163:             case '2':
164:                 return Yii::t('app', 'User\'s Groups');
165:             default:
166:                 return '';
167:         }
168:     }
169: 
170:     protected function renderEmail ($field, $makeLinks, $textOnly, $encode) {
171:         $fieldName = $field->fieldName;
172:         if (empty($this->owner->$fieldName)) {
173:             return '';
174:         } else {
175:             $mailtoLabel = (isset($this->owner->name) && !is_numeric($this->owner->name)) ? 
176:                 '"' . $this->owner->name . '" <' . $this->owner->$fieldName . '>' : 
177:                 $this->owner->$fieldName;
178:             return $makeLinks ? 
179:                 CHtml::mailto(CHtml::encode($this->owner->$fieldName), $mailtoLabel) : 
180:                 $this->render ($this->owner->$fieldName, $encode);
181:         }
182:     }
183: 
184:     protected function renderPhone ($field, $makeLinks, $textOnly, $encode) {
185:         $fieldName = $field->fieldName;
186:         $value = X2Model::getPhoneNumber(
187:             $fieldName, get_class($this->owner), $this->owner->id, $encode, $makeLinks,
188:             $this->owner->$fieldName);
189:         return $value;
190:     }
191: 
192:     protected function renderUrl ($field, $makeLinks, $textOnly, $encode) {
193:         $fieldName = $field->fieldName;
194:         if (!$makeLinks)
195:             return CHtml::encode($this->owner->$fieldName);
196: 
197:         if (empty($this->owner->$fieldName)) {
198:             $text = '';
199:         } elseif (!empty($field->linkType)) {
200:             switch ($field->linkType) {
201:                 case 'skype':
202:                     $text = '<a href="callto:' . $this->render ($this->owner->$fieldName, $encode) . '">' . 
203:                         $this->render ($this->owner->$fieldName, $encode) . '</a>';
204:                     break;
205:                 case 'googleplus':
206:                     $text = '<a href="http://plus.google.com/' . 
207:                         $this->render ($this->owner->$fieldName, $encode) . '">' . $this->render($this->owner->$fieldName, $encode) . 
208:                         '</a>';
209:                     break;
210:                 case 'twitter':
211:                     $text = '<a href="http://www.twitter.com/#!/' . 
212:                         $this->render ($this->owner->$fieldName, $encode) . '">' . $this->render($this->owner->$fieldName, $encode) . 
213:                         '</a>';
214:                     break;
215:                 case 'linkedin':
216:                     $text = '<a href="http://www.linkedin.com/in/' . 
217:                         $this->render ($this->owner->$fieldName, $encode) . '">' . $this->render($this->owner->$fieldName, $encode) . 
218:                         '</a>';
219:                     break;
220:                 default:
221:                     $text = '<a href="http://www.' . $field->linkType . '.com/' . 
222:                         $this->render ($this->owner->$fieldName, $encode) . '">' . 
223:                             $this->render ($this->owner->$fieldName, $encode) . 
224:                         '</a>';
225:             }
226:         } else {
227:             $text = trim(preg_replace(
228:                 array(
229:                     '/<a([^>]*)target="?[^"\']+"?/i',
230:                     '/<a([^>]+)>/i',
231:                 ), array(
232:                     '<a\\1 target="_blank"',
233:                     '<a\\1 target="_blank">',
234:                 ), $this->render ($this->owner->$fieldName, $encode)
235:             ));
236:             $oldText = $text;
237:             if (!function_exists('linkReplaceCallback')) {
238: 
239:                 function linkReplaceCallback($matches) {
240:                     return stripslashes(
241:                         (strlen($matches[2]) > 0 ? 
242:                             '<a href=\"' . $matches[2] . '\" target=\"_blank\">' . 
243:                                 $matches[0] . '</a>' : 
244:                             $matches[0]));
245:                 }
246: 
247:             }
248: 
249:             $text = trim(preg_replace_callback(
250:                 array(
251:                     '/(?(?=<a[^>]*>.+<\/a>)(?:<a[^>]*>.+<\/a>)|([^="\']?)((?:https?|ftp|bf2|):\/\/[^<> \n\r]+))/ix',
252:                 ), 'linkReplaceCallback', $this->render ($this->owner->$fieldName, $encode)
253:             ));
254:             if ($text == trim($oldText)) {
255:                 if (!function_exists('linkReplaceCallback2')) {
256: 
257:                     function linkReplaceCallback2($matches) {
258:                         return stripslashes(
259:                             (strlen($matches[2]) > 0 ? 
260:                                 '<a href=\"http://' . $matches[2] . 
261:                                     '\" target=\"_blank\">' . $matches[0] . '</a>' : 
262:                             $matches[0]));
263:                     }
264: 
265:                 }
266: 
267:                 $text = trim(preg_replace_callback(
268:                     array(
269:                         '/(^|\s|>)(www.[^<> \n\r]+)/ix',
270:                     ), 'linkReplaceCallback2', $this->render ($this->owner->$fieldName, $encode)
271:                 ));
272:             }
273:         }
274:         return $text;
275:     }
276: 
277:     protected function renderLink ($field, $makeLinks, $textOnly, $encode) {
278:         $fieldName = $field->fieldName;
279:         $linkedModel = $this->owner->getLinkedModel($fieldName, false);
280:         if ($linkedModel === null) {
281:             return $this->render ($this->owner->$fieldName, $encode);
282:         } else {
283:             return $makeLinks ? $linkedModel->getLink() : $linkedModel->name;
284:         }
285:     }
286: 
287:     /**
288:      * renders boolean fields in view layouts as icons, instead of as unchecked checkboxes.
289:      */
290:     protected function renderBoolean ($field, $makeLinks, $textOnly, $encode) {
291:         $fieldName = $field->fieldName;
292:         $bool = $this->owner->$fieldName;
293:         if ($textOnly) {
294:             $text = $bool ? Yii::t('app', 'Yes') : Yii::t('app', 'No');
295:             return $this->render ($text, $encode);
296:         }
297: 
298:         $html = $bool ? 
299:             X2Html::fa ('check', array('class'=> 'field-checked')) : 
300:             X2Html::fa ('times', array('class' => 'field-unchecked'));
301:         return $html;
302:     }
303: 
304: //    protected function renderBoolean ($field, $makeLinks, $textOnly, $encode) {
305: //        $fieldName = $field->fieldName;
306: //        return $textOnly ? 
307: //            $this->render (
308: //                $this->owner->$fieldName ? 
309: //                    Yii::t('app', 'Yes') : Yii::t('app', 'No'), $encode) : 
310: //            CHtml::checkbox(
311: //                '', $this->owner->$fieldName, 
312: //                array('onclick' => 'return false;', 'onkeydown' => 'return false;'));
313: //    }
314: 
315: 
316:     protected function renderCurrency ($field, $makeLinks, $textOnly, $encode) {
317:         $fieldName = $field->fieldName;
318:         if ($this->owner instanceof Product) { // products have their own currency
319:             $currency = Yii::app()->locale->numberFormatter->formatCurrency(
320:                 $this->owner->$fieldName, $this->owner->currency);
321:         } else {
322:             $currency = empty($this->owner->$fieldName) ?
323:                 '' : Yii::app()->locale->numberFormatter->formatCurrency(
324:                     $this->owner->$fieldName, Yii::app()->params['currency']);
325:         }
326:         if ($encode)
327:             return CHtml::encode($currency);
328:         else
329:             return $currency;
330:     }
331: 
332:     protected function renderPercentage ($field, $makeLinks, $textOnly, $encode) {
333:         $fieldName = $field->fieldName;
334:         return $this->owner->$fieldName !== null && $this->owner->$fieldName !== '' ? 
335:             (string) ($this->render ($this->owner->$fieldName, $encode)) . "%" : null;
336:     }
337: 
338:     protected function renderDropdown ($field, $makeLinks, $textOnly, $encode) {
339:         $fieldName = $field->fieldName;
340:         return $this->render($field->getDropdownValue ($this->owner->$fieldName), $encode);
341:     }
342: 
343:     protected function renderParentCase ($field, $makeLinks, $textOnly, $encode) {
344:         $fieldName = $field->fieldName;
345:         return $this->render (
346:             Yii::t(strtolower(Yii::app()->controller->id), $this->owner->$fieldName), $encode);
347:     }
348: 
349:     protected function renderText ($field, $makeLinks, $textOnly, $encode) {
350:         $fieldName = $field->fieldName;
351:         return Yii::app()->controller->convertUrls(
352:             $this->render ($this->owner->$fieldName, false));
353:     }
354: 
355:     protected function renderCredentials ($field, $makeLinks, $textOnly, $encode) {
356:         $fieldName = $field->fieldName;
357:         $sysleg = Yii::t('app', 'System default (legacy)');
358:         if ($this->owner->$fieldName == -1) {
359:             return $sysleg;
360:         } else {
361:             $creds = Credentials::model()->findByPk($this->owner->$fieldName);
362:             if (!empty($creds))
363:                 return $this->render ($creds->name, $encode);
364:             else
365:                 return $sysleg;
366:         }
367:     }
368: 
369:     protected function renderTimerSum ($field, $makeLinks, $textOnly, $encode) {
370:         $fieldName = $field->fieldName;
371:         $t_seconds = $this->owner->$fieldName;
372:         $t[] = floor($t_seconds / 3600); // Hours
373:         $t[] = floor($t_seconds / 60) % 60; // Minutes
374:         $t[] = $t_seconds % 60; // Seconds
375:         $pad = function($t) {
376:             return str_pad((string) $t, 2, '0', STR_PAD_LEFT);
377:         };
378:         return implode(':', array_map($pad, $t));
379:     }
380: 
381:     protected function renderInt ($field, $makeLinks, $textOnly, $encode) {
382:         $fieldName = $field->fieldName;
383:         if ($fieldName != 'id')
384:             return Yii::app()->locale->numberFormatter->formatDecimal($this->owner->$fieldName);
385:         else
386:             return $this->owner->$fieldName;
387:     }
388: 
389:     protected function renderFloat ($field, $makeLinks, $textOnly, $encode) {
390:         return $this->renderInt ($field, $makeLinks, $textOnly, $encode);
391:     }
392: 
393:     protected function renderCustom ($field, $makeLinks, $textOnly, $encode) {
394:         $fieldName = $field->fieldName;
395:         if ($field->linkType == 'display') {
396:             // Interpret as HTML. Restore curly braces in href
397:             // attributes that HTMLPurifier has replaced:
398:             $fieldText = preg_replace(
399:                     '/%7B([\w\.]+)%7D/', '{$1}', $field->data);
400:             return Formatter::replaceVariables($fieldText, $this->owner, '', false);
401:         } elseif ($field->linkType == 'formula') {
402:             $evald = Formatter::parseFormula($field->data, array(
403:                 'model' => $this->owner,
404:             ));
405:             if ($evald[0]) {
406:                 return $this->render ($evald[1], $encode);
407:             } else {
408:                 return Yii::t('app', 'Error parsing formula.') . ' ' . $evald[1];
409:             }
410:         } else {
411:             return $this->render ($this->owner->$fieldName, $encode);
412:         }
413:     }
414: }
415: 
416: ?>
417: 
X2CRM Documentation API documentation generated by ApiGen 2.8.0