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

  • BugReports
  • Templates
  • Topics
  • 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: Yii::import ('application.modules.topics.components.formatters.TopicsFieldFormatter');
 39: 
 40: /**
 41:  * This is the model class for table "x2_template".
 42:  * @package application.modules.template.models
 43:  */
 44: class Topics extends X2Model {
 45:     
 46:     const PAGE_SIZE = 20;
 47: 
 48:     public $upload;
 49: 
 50:     public $supportsFieldLevelPermissions = false;
 51:     
 52:     public $supportsWorkflow = false;
 53: 
 54:     protected $fieldFormatterClass = 'TopicsFieldFormatter';
 55: 
 56:     private $_originalPost;
 57:     private $_postTextChanged = false;
 58: 
 59:     /**
 60:      * Returns the static model of the specified AR class.
 61:      * @return Template the static model class
 62:      */
 63:     public static function model($className = __CLASS__) {
 64:         return parent::model($className);
 65:     }
 66:     
 67:     public static function getListViewHeader() {
 68:         $titleHeader = X2Html::tag(
 69:             'div', array('class' => 'topic-title'), Yii::t('topics', 'Topic Title'));
 70:         $replyCountHeader = X2Html::tag(
 71:             'div', array('class' => 'topic-reply-count'), Yii::t('topics', 'Replies'));
 72:         $lastUpdatedHeader = X2Html::tag(
 73:             'div', array('class' => 'topic-last-updated'), Yii::t('topics', 'Latest Post'));
 74:         $attributesHeader = X2Html::tag(
 75:             'div', array('class' => 'topic-attributes'), $replyCountHeader . $lastUpdatedHeader);
 76:         $header = X2Html::tag(
 77:             'div', array('class' => 'clear-fix'), $titleHeader . $attributesHeader);
 78: 
 79:         return X2Html::tag('div', array('class' => 'topics-header'), $header);
 80:     }
 81:     
 82:     public static function getSortLinks($order = null) {
 83:         $ret = X2Html::link(
 84:             Yii::t('topics','Sorting'), '#', 
 85:             array(
 86:                 'id' => 'topics-sort-toggle',
 87:                 'class' => 'x2-button',
 88:                 'style' => 'vertical-align:top;'));
 89:         $links = array(
 90:             X2Html::link(
 91:                 Yii::t('topics','Most Recent'), 
 92:                 Yii::app()->controller->createUrl(
 93:                     '/topics/topics/index', 
 94:                     array('order' => 'mostRecent')
 95:                 ), 
 96:                 array(
 97:                     'class' => 'x2-button' . (($order == 'mostRecent' || is_null($order)) ? 
 98:                         ' disabled disabled-link' : ''), 'style' => 'vertical-align:top;')
 99:             ),
100:             X2Html::link(
101:                 Yii::t('topics','Alphabetical'), 
102:                 Yii::app()->controller->createUrl(
103:                     '/topics/topics/index', 
104:                     array('order' => 'alphabetical')
105:                 ), 
106:                 array(
107:                     'class' => 'x2-button' . ($order == 'alphabetical' ? ' disabled disabled-link' : ''), 
108:                     'style' => 'vertical-align:top;')),
109:             X2Html::link(
110:                 Yii::t('topics','Create Date'), 
111:                 Yii::app()->controller->createUrl(
112:                     '/topics/topics/index', 
113:                     array('order' => 'firstCreated')
114:                 ), 
115:                 array('class' => 'x2-button' . ($order == 'firstCreated' ? ' disabled disabled-link' : ''), 
116:                 'style' => 'vertical-align:top;')),
117:             X2Html::link(
118:                 Yii::t('topics','Most Popular'), 
119:                 Yii::app()->controller->createUrl(
120:                     '/topics/topics/index', 
121:                     array('order' => 'mostPopular')), 
122:                 array(
123:                     'class' => 'x2-button' . ($order == 'mostPopular' ? ' disabled disabled-link' : ''), 
124:                     'style' => 'vertical-align:top;')),
125:         );
126:         $ret .= X2Html::tag(
127:             'div', array('id' => 'topics-sort-buttons', 'style' => 'display:none;'), 
128:             implode(' ', $links));
129:         return $ret;
130:     }
131: 
132:     /**
133:      * @return string the associated database table name
134:      */
135:     public function tableName() {
136:         return 'x2_topics';
137:     }
138: 
139:     public function behaviors() {
140:         $that = $this;
141:         return array_merge(parent::behaviors(), array(
142:             'AssociatedMediaBehavior' => array(
143:                 'class' => 'application.components.behaviors.AssociatedMediaBehavior',
144:                 'fileAttribute' => 'upload',
145:                 'associationType' => 'topicReply',
146:                 'getAssociationId' => function () use ($that) {
147:                     return $that->originalPost->id;
148:                 },
149:             ),
150:             'X2LinkableBehavior' => array(
151:                 'class' => 'X2LinkableBehavior',
152:                 'module' => 'topics'
153:             ),
154:             'ERememberFiltersBehavior' => array(
155:                 'class' => 'application.components.ERememberFiltersBehavior',
156:                 'defaults' => array(),
157:                 'defaultStickOnClear' => false
158:             ),
159:             'InlineEmailModelBehavior' => array(
160:                 'class' => 'application.components.InlineEmailModelBehavior',
161:             )
162:         ));
163:     }
164:     
165:     public function relations() {
166:         return array(
167:             'originalPostRelation' => array(self::HAS_ONE, 'TopicReplies',
168:                 'topicId', 'order' => 'originalPostRelation.createDate ASC'),
169:             'replies' => array(self::HAS_MANY, 'TopicReplies', 'topicId',
170:                 'order'=>'replies.createDate ASC'),
171:             'lastPost' => array(self::HAS_ONE, 'TopicReplies', 'topicId',
172:                 'order' => 'lastPost.createDate DESC'),
173:         );
174:     }
175: 
176:     public function renderAttribute (
177:         $fieldName, $makeLinks = true, $textOnly = true, $encode = true) { 
178: 
179:         switch ($fieldName) {
180:             case 'replyCount':
181:                 $val = Yii::t('topics', '1#{n} reply|n!=1#{n} replies', array (
182:                     $this->replyCount,
183:                 ));
184:                 return $encode ? CHtml::encode($val) : $val;
185:             default:
186:                 return call_user_func_array ('parent::'.__FUNCTION__, func_get_args ());
187:         }
188:     }
189: 
190:     private $_text;
191:     public function getText () {
192:         if (!isset ($this->_text) && $this->originalPost) {
193:             $this->_text = $this->originalPost->text;
194:         }
195:         return $this->_text;
196:     }
197: 
198:     public function setText ($text) {
199:         $this->_text = $text;
200:         $this->setOriginalPostText ($text);
201:     }
202:     
203:     public function afterSave(){
204:         if ($this->_originalPost->isNewRecord || $this->_postTextChanged) {
205:             if ($this->_originalPost->isNewRecord) {
206:                 $this->_originalPost->topicId = $this->id;
207:                 $this->_originalPost->assignedTo = Yii::app()->user->getName();
208:             }
209:             $this->_originalPost->updatedBy = Yii::app()->user->getName();
210:             $this->_originalPost->save();
211:         }
212:         return parent::afterSave();
213:     }
214: 
215:     /**
216:      * Retrieves a list of models based on the current search/filter conditions.
217:      * @return CActiveDataProvider the data provider that can return the models based on the 
218:      *  search/filter conditions.
219:      */
220:     public function search() {
221:         $criteria = new CDbCriteria;
222:         return $this->searchBase($criteria);
223:     }
224:     
225:     public function getOrder($order){
226:         $ret = 'sticky DESC, ';
227:         switch($order){
228:             case 'alphabetical':
229:                 $ret .= 't.name ASC';
230:                 break;
231:             case 'firstCreated':
232:                 $ret .= 't.createDate ASC';
233:                 break;
234:             case 'mostPopular':
235:                 $ret .= 'replyCount DESC';
236:                 break;
237:             case 'mostRecent':
238:             default:
239:                 $ret.='minCreateDate DESC';
240:         }
241:         return $ret;
242:     }
243:     
244:     public function getOriginalPost(){
245:         if(is_null($this->_originalPost)){
246:             $this->_originalPost = $this->originalPostRelation;
247:         }
248:         return $this->_originalPost;
249:     }
250:     
251:     public function setOriginalPostText($text){
252:         if(is_null($this->originalPost)){
253:             $this->_originalPost = new TopicReplies;
254:         }
255:         if($this->_originalPost->text !== $text){
256:             $this->_originalPost->text = $text;
257:             $this->_postTextChanged = true;
258:         }
259:     }
260:     
261:     public function getReplyCount(){
262:         return Yii::app()->db->createCommand()
263:             ->select('COUNT(id)')
264:             ->from('x2_topic_replies')
265:             ->where('topicId = :id',array(':id'=>$this->id))
266:             ->queryScalar() - 1;
267:     }
268: 
269:     private $_attachments;
270:     public function getAttachments () {
271:         if (!isset ($this->_attachments)) {
272:             $this->_attachments = $this->originalPost ? $this->originalPost->attachments : array ();
273:         }
274:         return $this->_attachments;
275:     }
276: 
277: }
278: 
X2CRM Documentation API documentation generated by ApiGen 2.8.0