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: 
 38: class TopicReplies extends X2ActiveRecord {
 39:     
 40:     public $module = 'topics';
 41:     public $upload;
 42:     
 43:     private $_attachments;
 44:     
 45:     /**
 46:      * Returns the static model of the specified AR class.
 47:      * @return Template the static model class
 48:      */
 49:     public static function model($className = __CLASS__) {
 50:         return parent::model($className);
 51:     }
 52: 
 53:     /**
 54:      * @return string the associated database table name
 55:      */
 56:     public function tableName() {
 57:         return 'x2_topic_replies';
 58:     }
 59:     
 60:     public function rules() {
 61:         return array(
 62:             array(
 63:                 'text','filter','filter'=>array($obj=new CHtmlPurifier(),'purify')
 64:             ),
 65:             array(
 66:                 'topicId', 'required'
 67:             ),
 68:             array(
 69:                 'text', 'application.components.validators.RequiredIfNotSetValidator',
 70:                 'otherAttr' => 'upload'
 71:             ),
 72:         );
 73:     }
 74: 
 75:     public function behaviors(){
 76:         $that = $this;
 77:         return array_merge(parent::behaviors(),array(
 78:             'AssociatedMediaBehavior' => array(
 79:                 'class' => 'application.components.behaviors.AssociatedMediaBehavior',
 80:                 'fileAttribute' => 'upload',
 81:                 'associationType' => 'topicReply',
 82:                 'getAssociationId' => function () use ($that) {
 83:                     return $that->id;
 84:                 },
 85:             ),
 86:             'X2StaticFieldsBehavior' => array(
 87:                 'class' => 'application.components.behaviors.X2StaticFieldsBehavior',
 88:                 'translationCategory' => 'topics',
 89:                 'fields' => array (
 90:                     array (
 91:                         'fieldName' => 'text',
 92:                         'attributeLabel' => 'Text',
 93:                         'type' => 'text',
 94:                     ),
 95:                 ),
 96:             ),
 97:             'X2TimestampBehavior' => array('class' => 'X2TimestampBehavior'),
 98:             'permissions' => array('class' => Yii::app()->params->modelPermissions),
 99:         ));
100:     }
101:     
102:     public function relations(){
103:         return array(
104:             'topic' => array(self::BELONGS_TO, 'Topics', 'topicId'),
105:             'profile' => array(self::HAS_ONE, 'Profile', 
106:                 array ('username' => 'assignedTo')),
107:         );
108:     }
109:     
110:     public function beforeSave(){
111:         if(empty($this->assignedTo)){
112:             $this->assignedTo = Yii::app()->user->getName();
113:         }
114:         $this->updatedBy = Yii::app()->user->getName();
115:         return parent::beforeSave();
116:     }
117: 
118:     public function afterSave () {
119:         parent::afterSave ();
120:         $event = new Events;
121:         $event->visibility = 1;
122:         $event->associationType = 'TopicRepies';
123:         $event->associationId = $this->id;
124:         $event->user = Yii::app()->user->getName();
125:         $event->type = 'topic_reply';
126:         $event->save();
127:     }
128:     
129:     public function getTopicPage(){
130:         $tableSchema = $this->getTableSchema();
131:         $criteria = new CDbCriteria();
132:         $criteria->select = 't.id';
133:         $criteria->compare('t.topicId',$this->topicId);
134:         $criteria->order = 't.createDate ASC';
135:         $searchConditions = Yii::app()->db->getCommandBuilder()
136:             ->createFindCommand($tableSchema, $criteria)->getText();
137:         $varPrefix = '@'; //Current prefix is MySQL specific
138:         $varName = $varPrefix.'rownum';
139:         $varText = 'SET '.$varName.' = 0'; // Current declaration is MySQL specific
140:         Yii::app()->db->createCommand()
141:                 ->setText($varText)
142:                 ->execute();
143:         $subQuery = Yii::app()->db->createCommand()
144:                 ->select('*, ('.$varName.':='.$varName.'+1) r')
145:                 ->from('('.$searchConditions.') t1')
146:                 ->getText();
147:         $rowNumberQuery = Yii::app()->db->createCommand()
148:                 ->select('(r-1)')
149:                 ->from('('.$subQuery.') t2')
150:                 ->where('t2.id=:t2_id');
151:         $rowNumberQuery->params = array_merge(array(':t2_id'=>$this->id),$criteria->params);
152:         $rowNumber = $rowNumberQuery->queryScalar();
153:         return (int)($rowNumber / Topics::PAGE_SIZE);
154:     }
155:     
156:     public function getAuthorId(){
157:         return Yii::app()->db->createCommand()
158:                 ->select('id')
159:                 ->from('x2_profile')
160:                 ->where('username=:user', array(':user' => $this->assignedTo))
161:                 ->queryScalar();
162:     }
163:     
164:     public function isOriginalPost(){
165:         return $this->id === $this->topic->originalPost->id;
166:     }
167:     
168:     public function isEditable(){
169:         return Yii::app()->controller->checkPermissions($this, 'edit');
170:     }
171:     
172:     public function isDeletable(){
173:         return !$this->isOriginalPost() && Yii::app()->controller->checkPermissions($this, 'delete');
174:     }
175:     
176:     public function isEdited(){
177:         return $this->createDate !== $this->lastUpdated;
178:     }
179:     
180:     public function getAttachments() {
181:         if (is_null($this->_attachments)) {
182:             $this->_attachments = Media::model()->findAllByAttributes(array('associationType' => 'topicReply',
183:                 'associationId' => $this->id));
184:         }
185:         return $this->_attachments;
186:     }
187: 
188: }
189: 
X2CRM Documentation API documentation generated by ApiGen 2.8.0