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

  • ActionToRecord
  • ContactsNameBehavior
  • ERememberFiltersBehavior
  • FileSystemObjectBehavior
  • MobileLayouts
  • RecordAliases
  • RelationshipsBehavior
  • TopicReplies
  • X2ActiveRecord
  • X2Flow
  • 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: class RecordAliases extends CActiveRecord {
 38: 
 39:     /**
 40:      * @var array $types
 41:      */
 42:     public static $types = array (
 43:         'email', 'phone', 'skype', 'googlePlus', 'linkedIn', 'twitter', 'facebook', 'other');
 44: 
 45:     public static function model ($className=__CLASS__) {
 46:         return parent::model ($className);
 47:     }
 48: 
 49:     public static function getActions () {
 50:         return array (
 51:             'createRecordAlias' => 
 52:                 'application.components.recordAliases.RecordAliasesCreateAction',
 53:             'deleteRecordAlias' => 
 54:                 'application.components.recordAliases.RecordAliasesDeleteAction',
 55:         );
 56:     }
 57: 
 58:     public static function getAliases (X2Model $model, $aliasType = null) {
 59:         $params =  array (
 60:             ':type' => get_class ($model),
 61:             ':recordId' => $model->id,
 62:         );
 63:         if ($aliasType) {
 64:             $params[':aliasType'] = $aliasType;
 65:         }
 66:         $aliases = RecordAliases::model ()->findAll (array (
 67:             'condition' => 'recordType=:type AND recordId=:recordId'.
 68:                 ($aliasType ? ' AND aliasType=:aliasType' : ''),
 69:             'order' => 'aliasType ASC, alias ASC',
 70:             'params' => $params,
 71:         ));
 72:         return $aliases;
 73:     }
 74: 
 75:     public function tableName () {
 76:         return 'x2_record_aliases';
 77:     }
 78: 
 79:     /**
 80:      * @return array validation rules for model attributes.
 81:      */
 82:     public function rules () {
 83:         return array(
 84:             array('recordId, aliasType, alias', 'required'),
 85:             array('aliasType', 'validateAliasType'),
 86:             array('recordId', 'validateRecordId'),
 87:             array('alias', 'validateRecordAlias'),
 88:             array('alias', 'validateAliasUniqueness', 'on' => 'insert'),
 89:             array('label', 'safe'),
 90:         );
 91:     }
 92: 
 93:     public function getModel () {
 94:         $recordType = $this->recordType;
 95:         return $recordType::model ()->findByPk ($this->recordId);
 96:     }
 97: 
 98:     public function validateAliasType ($attribute) {
 99:         $value = $this->$attribute;
100:         if (!in_array ($value, self::$types)) {
101:             throw new CHttpException (400, Yii::t('app', 'Invalid alias type'));
102:         }
103:     }
104: 
105:     public function validateRecordId () {
106:         if (!$this->getModel ()) {
107:             throw new CHttpException (400, Yii::t('app', 'Invalid record id or type')) ;
108:         }
109:     }
110: 
111:     public function renderAlias ($makeLinks=true) {
112:         if ($makeLinks) {
113:             switch ($this->aliasType) {
114:                 case 'email':
115:                     return X2Html::renderEmailLink ($this->alias);
116:                 case 'phone':
117:                     return X2Html::renderPhoneLink ($this->alias);
118:                 case 'googlePlus':
119:                     return CHtml::encode ($this->label ? $this->label : $this->alias);
120:                 default:
121:                     return CHtml::encode ($this->alias);
122:             }
123:         } else {
124:             switch ($this->aliasType) {
125:                 case 'googlePlus':
126:                     return CHtml::encode ($this->label ? $this->label : $this->alias);
127:                 default:
128:                     return CHtml::encode ($this->alias);
129:             }
130:         }
131:     }
132: 
133:     public function validateAliasUniqueness () {
134:         if (self::findByAttributes (array_diff_key ($this->getAttributes (), array (
135:             'id' => true)))) {
136: 
137:             $this->addError (
138:                 'alias', 
139:                 Yii::t('app', 'This record already has a {aliasType} alias with the '.
140:                     'name "{alias}"', array (
141:                     '{aliasType}' => $this->renderAliasType (false),
142:                     '{alias}' => $this->renderAlias (false),
143:                 )));
144:         }
145:     }
146: 
147:     public function validateRecordAlias ($attribute) {
148:         $value = $this->$attribute;
149:         switch ($this->aliasType) {
150:             case 'email':
151:                 $emailValidator = CValidator::createValidator ('email', $this, 'alias');
152:                 $emailValidator->validate ($this, 'email');
153:                 break;
154:         }
155:     }
156: 
157:     public function attributeLabels () {
158:         return array (
159:             'aliasType' => Yii::t('app', 'Alias Type'),
160:             'alias' => Yii::t('app', 'Alias'),
161:         );
162:     }
163: 
164:     public function getAllIcons () {
165:         $icons = array ();
166:         foreach (self::$types as $type) {
167:             $icons[$type] = $this->getIcon (false, false, $type);
168:         }
169:         return $icons;
170:     }
171: 
172:     public function getIcon ($includeTitle=false, $large=false, $aliasType=null) {
173:         if ($aliasType === null) {
174:             $aliasType = $this->aliasType;
175:         }
176:         
177:         $class = '';
178:         switch ($aliasType) {
179:             case 'email':
180:                 $class = 'fa-at';
181:                 break;
182:             case 'phone':
183:                 $class = 'fa-phone';
184:                 break;
185:             case 'skype':
186:                 $class = 'fa-skype';
187:                 break;
188:             case 'googlePlus':
189:                 $class = 'fa-google-plus';
190:                 break;
191:             case 'linkedIn':
192:                 $class = 'fa-linkedin';
193:                 break;
194:             case 'twitter':
195:                 $class = 'fa-twitter';
196:                 break;
197:             case 'facebook':
198:                 $class = 'fa-facebook';
199:                 break;
200:         }
201:         if ($includeTitle) $aliasOptions = $this->getAliasTypeOptions ();
202:         if ($large) $class .= ' fa-lg';
203:         return 
204:             '<span '.($includeTitle ? 
205:                 'title="'.CHtml::encode ($aliasOptions[$aliasType]).'" ' : '')
206:             .'class="fa '.$class.'"></span>';
207:     }
208: 
209:     public function renderAliasType ($encode=true) {
210:         $options = $this->getAliasTypeOptions ();
211:         $html = isset ($options[$this->aliasType]) ? $options[$this->aliasType] : '';
212:         if ($encode) $html = CHtml::encode ($html);
213:         return $html;
214:     }
215: 
216:     private $_aliasTypeOptions;
217:     public function getAliasTypeOptions () {
218:         if (!isset ($this->_aliasTypeOptions)) {
219:             $this->_aliasTypeOptions = array ( 
220:                 'email' => Yii::t('app', 'email'),
221:                 'phone' => Yii::t('app', 'phone'),
222:                 'skype' => 'Skype',
223:                 'googlePlus' => 'Google+',
224:                 'linkedIn' => 'LinkedIn',
225:                 'twitter' => 'Twitter',
226:                 'facebook' => 'Facebook',
227:                 'other' => 'Other',
228:             );
229:         }
230:         return $this->_aliasTypeOptions;
231:     }
232: 
233: }
234: 
235: ?>
236: 
X2CRM Documentation API documentation generated by ApiGen 2.8.0