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

  • ActionMetaData
  • ActionText
  • Admin
  • AmorphousModel
  • ApiHook
  • APIModel
  • ChartSetting
  • ContactForm
  • ContactList
  • Credentials
  • Criteria
  • Dropdowns
  • Events
  • EventsData
  • Fields
  • FormLayout
  • Imports
  • InlineEmail
  • LeadRouting
  • Locations
  • LoginForm
  • Maps
  • Modules
  • Notes
  • Notification
  • PhoneNumber
  • Profile
  • Record
  • Relationships
  • Roles
  • RoleToPermission
  • RoleToUser
  • RoleToWorkflow
  • Rules
  • Session
  • SessionLog
  • Social
  • Tags
  • TempFile
  • Tips
  • Tours
  • TrackEmail
  • TriggerLog
  • URL
  • ViewLog
  • Widgets
  • X2List
  • X2ListCriterion
  • X2ListItem
  • X2Model
  • 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:  * This is the model class for table "x2_notifications".
 39:  *
 40:  * @package application.models
 41:  */
 42: class Notification extends CActiveRecord {
 43:     /**
 44:      * Returns the static model of the specified AR class.
 45:      * @param string $className active record class name.
 46:      * @return Notification the static model class
 47:      */
 48:     public static function model($className=__CLASS__) {
 49:         return parent::model($className);
 50:     }
 51: 
 52:     /**
 53:      * @return string the associated database table name
 54:      */
 55:     public function tableName() {
 56:         return 'x2_notifications';
 57:     }
 58: 
 59:     /**
 60:      * @return array validation rules for model attributes.
 61:      */
 62:     public function rules() {
 63:         // NOTE: you should only define rules for those attributes that
 64:         // will receive user inputs.
 65:         return array(
 66:             array('type', 'required'),
 67:             array('modelId, createDate', 'numerical', 'integerOnly'=>true),
 68:             array('viewed', 'boolean'),
 69:             // array('record, modelType, fieldName', 'length', 'max'=>250),
 70:             array('user, createdBy, comparison, type', 'length', 'max'=>20),
 71:             array('type, value', 'length', 'max'=>250),
 72:             // array('text', 'safe'),
 73:             array('id, user, viewed, text, createDate, type, comparison, modelType, modelId, fieldName', 'safe', 'on'=>'search'),   //text, record,
 74:         );
 75:     }
 76: 
 77:     /**
 78:      * @return array relational rules.
 79:      */
 80:     public function relations() {
 81:         // NOTE: you may need to adjust the relation name and the related
 82:         // class name for the relations automatically generated below.
 83:         return array(
 84:             'event'=>array(self::HAS_ONE,'Events','associationId','condition'=>'associationType="Notification"'),
 85:         );
 86:     }
 87: 
 88:     /**
 89:      * @return array customized attribute labels (name=>label)
 90:      */
 91:     public function attributeLabels() {
 92:         return array(
 93:             'id' => 'ID',
 94:             // 'text' => 'Text',
 95:             // 'record' => 'Record',
 96:             'user' => 'User',
 97:             'createdBy' => 'Created By',
 98:             'viewed' => 'Viewed',
 99:             'createDate' => 'Create Date',
100:             'type' => 'Type',
101:             'comparison' => 'Comparison',
102:             'value' => 'Value',
103:             'text' => 'Text',
104:             'modelType' => 'Model Type',
105:             'modelId' => 'Model ID',
106:             'fieldName' => 'Field Name',
107:         );
108:     }
109: 
110:     /**
111:      * Retrieves a list of models based on the current search/filter conditions.
112:      * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
113:      */
114:     public function search() {
115:         // Warning: Please modify the following code to remove attributes that
116:         // should not be searched.
117: 
118:         $criteria=new CDbCriteria;
119: 
120:         $criteria->compare('id',$this->id);
121:         // $criteria->compare('text',$this->text,true);
122:         // $criteria->compare('record',$this->record,true);
123:         $criteria->compare('user',$this->user,true);
124:         $criteria->compare('createdBy',$this->createdBy,true);
125:         $criteria->compare('viewed',$this->viewed);
126:         $criteria->compare('createDate',$this->createDate,true);
127:         $criteria->compare('type',$this->type,true);
128:         $criteria->compare('comparison',$this->comparison,true);
129:         // $criteria->compare('value',$this->value,true);
130:         $criteria->compare('modelType',$this->modelType,true);
131:         $criteria->compare('modelId',$this->modelId,true);
132:         $criteria->compare('fieldName',$this->fieldName,true);
133: 
134:         return new CActiveDataProvider($this, array(
135:             'criteria'=>$criteria,
136:         ));
137:     }
138: 
139: 
140:     public function getMessage() {
141: 
142:         if(empty($this->modelId) || empty($this->modelType))    // skip if there is no association
143:             $record = null;
144:         else {
145:             if(class_exists($this->modelType)) {
146:                 $record = X2Model::model($this->modelType)->findByPk($this->modelId);
147:             } else {
148:                 return 'Error: unknown record <b>'.$this->modelType.'</b>';
149:             }
150:             if($record === null) {
151:                 $this->delete();
152:                 return null;
153:             }
154:         }
155: 
156:         if(!isset($record) && $this->type !== 'lead_failure' && $this->type !== 'custom') {
157:             // return var_dump($this->attributes);
158:             return null;
159:         }
160:         $passive = $this->createdBy === 'API' || empty($this->createdBy);
161: 
162:         switch($this->type) {
163: 
164:             case 'action_complete':
165:                 if($passive)
166:                     return Yii::t('actions','Action completed: {action}',array('{action}'=>$record->getLink()));
167:                 else
168:                     return Yii::t('actions','{user} completed an action: {action}',array('{user}'=>User::getUserLinks($record->completedBy),'{action}'=>$record->getLink(20)));
169: 
170:             case 'action_reminder':
171:                 return Yii::t('actions','<b>Reminder!</b> The following action is due: {action}',array('{action}'=>$record->getLink()));
172:             // case 'workflow_complete':
173:                 // if($passive)
174:                     // return Yii::t('actions','Stage {n}: {stage} was completed for {record}',array('{record}'=>$record->getLink()));
175:                 // else
176:                     // return Yii::t('actions','{user} completed stage {n}: {stage} was completed for {record}',array('{record}'=>$record->getLink()));
177: 
178:             case 'create':
179:                 return Yii::t('app','New record assigned to you: {link}.',array('{link}'=>$record->getLink()));
180: 
181:             case 'change':
182:                 if($this->comparison == 'change') {
183: 
184:                     $msg = $passive? '{record}\'s {field} was changed to {value}' : '{user} changed {record}\'s {field} to {value}';
185: 
186:                     return Yii::t('app',$msg,array(
187:                         '{field}'=>$record->getAttributeLabel($this->fieldName),
188:                         '{value}'=>$record->renderAttribute($this->fieldName,true,true),
189:                         '{record}'=>$record->getLink(),
190:                         '{user}'=>(Yii::app()->user->getName()==$this->createdBy)?CHtml::link('You',array('/profile/view','id'=>Yii::app()->user->getId())):User::getUserLinks($this->createdBy)
191:                     ));
192: 
193:                 } else {
194:                 // > < =
195:                     $msg = $passive? '{record}\'s {field} was changed to {value}' : '{user} changed {record}\'s {field} to {value}';
196: 
197:                     return Yii::t('app',$msg,array(
198:                         '{field}'=>$record->getAttributeLabel($this->fieldName),
199:                         '{value}'=>$record->renderAttribute($this->fieldName,true,true),
200:                         '{record}'=>$record->getLink(),
201:                         '{user}'=>(Yii::app()->user->getName()==$this->createdBy)?CHtml::link('You',array('/profile/view','id'=>Yii::app()->user->getId())):User::getUserLinks($this->createdBy)
202:                     ));
203: 
204: 
205:                 }
206: 
207:             case 'lead_failure':
208:                 return Yii::t('app','A lead failed to come through Lead Capture. Check {link} to recover it.',array(
209:                     '{link}'=>CHtml::link(Yii::t('app','here'),Yii::app()->controller->createUrl('/contacts/contacts/cleanFailedLeads'))
210:                 ));
211:             case 'assignment':
212:                 if($passive)
213:                     return Yii::t('app','You have been assigned a record: {record}',array('{record}'=>$record->getLink()));
214:                 else
215:                     return Yii::t('app','{user} assigned a record to you: {record}',array('{user}'=>User::getUserLinks($this->createdBy),'{record}'=>$record->getLink()));
216: 
217:             case 'delete':
218:                 if($passive)
219:                     return Yii::t('app','Record deleted: {record}',array('{record}'=>$this->modelType.' '.$this->modelId));
220:                 else
221:                     return Yii::t('app','{user} deleted a record: {record}',array('{user}'=>User::getUserLinks($this->createdBy),'{record}'=>$this->modelType.' '.$this->modelId));
222:             case 'event_broadcast':
223:                 return Yii::t('app','{user} broadcast an event: {event}',array('{user}'=>User::getUserLinks($record->user),'{event}'=>$record->getText()));
224:             case 'update':
225:                 if($passive)
226:                     return Yii::t('app','Record updated: {record}',array('{record}'=>$record->getLink()));
227:                 else
228:                     return Yii::t('app','{user} updated a record: {record}',array('{user}'=>User::getUserLinks($this->createdBy),'{record}'=>$record->getLink()));
229: 
230:             case 'dup_discard':
231:                 if($passive)
232:                     return Yii::t('app','A record has been marked as a duplicate and hidden to everyone but the admin: {record}',
233:                         array('{record}'=>$record->getLink()));
234:                 else
235:                     return Yii::t('app','{user} marked a record as a duplicate. This record is hidden to everyone but the admin: {record}',
236:                         array('{user}'=>User::getUserLinks($this->createdBy),'{record}'=>$record->getLink()));
237: 
238:             case 'email_clicked':
239:                 return Yii::t('app','{record} clicked an email link: {campaign}',array('{record}'=>$record->getLink(),'{campaign}'=>$this->value));
240: 
241:             case 'email_opened':
242:                 return Yii::t('app','{record} opened an email: {campaign}',array('{record}'=>$record->getLink(),'{campaign}'=>$this->value));
243: 
244:             case 'email_unsubscribed':
245:                 return Yii::t('app','{record} unsubscribed from a campaign: {campaign}',array('{record}'=>$record->getLink(),'{campaign}'=>$this->value));
246: 
247:             case 'social_post':
248:                 return Yii::t('app','{user} posted on {link}',array('{user}'=>User::getUserLinks($this->createdBy),'{link}'=>$record->getLink()));
249: 
250:             case 'social_comment':
251:                 return Yii::t('app','{user} replied on {link}',array('{user}'=>User::getUserLinks($this->createdBy),'{link}'=>$record->getLink()));
252: 
253:             case 'voip_call':
254:                 return Yii::t(
255:                     'app',
256:                     'Incoming call from <b>{phone}</b> ({record}) {time}',
257:                     array(
258:                         '{record}'=>$record->getLink(),
259:                         '{phone}'=>$this->value,
260:                         '{time}'=>Formatter::formatDateDynamic ($this->createDate)
261:                     )   
262:                 );  
263:             case 'weblead':
264:                 return Yii::t('app','New web lead: {link}.',array('{link}'=>$record->getLink()));
265: 
266:             case 'webactivity':
267:                 if($record instanceof Actions) {
268:                     if($link = $record->getAssociationLink())
269:                         return Yii::t('app','{name} is currently on {url}',array('{name}'=>$link,'{url}'=>$record->actionDescription));
270:                 } elseif($record instanceof Contacts) {
271:                     return Yii::t('app','{name} is currently on your website.',array('{name}'=>$record->getLink()));
272:                 }
273:                 return null;
274:             case 'escalateCase':
275:                 return Yii::t('app', '{user} escalated a Service Case to you: {record}', array(
276:                     '{user}'=>User::getUserLinks($this->createdBy),
277:                     '{record}'=>$record->createLink(),
278:                 ));
279:             case 'custom':
280:                 return $this->text;
281:             default:
282:                 return 'Error: unknown type <b>'.$this->type.'</b>';
283: 
284:         }
285:     }
286: }
287: 
X2CRM Documentation API documentation generated by ApiGen 2.8.0