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

  • X2LeadsController
  • 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:  * @package application.modules.x2Leads.controllers
 39:  */
 40: class X2LeadsController extends x2base {
 41: 
 42:     public $modelClass = 'X2Leads';
 43: 
 44:     public function accessRules() {
 45:         return array(
 46:             array('allow',
 47:                 'actions'=>array('getItems'),
 48:                 'users'=>array('*'),
 49:             ),
 50:             array('allow', // allow authenticated user to perform 'create' and 'update' actions
 51:                 'actions'=>array('index','view','create','update','search',
 52:                     'saveChanges','delete','shareX2Leads','inlineEmail'),
 53:                 'users'=>array('@'),
 54:             ),
 55:             array('allow', // allow admin user to perform 'admin' and 'delete' actions
 56:                 'actions'=>array('admin','testScalability'),
 57:                 'users'=>array('admin'),
 58:             ),
 59:             array('deny',  // deny all users
 60:                 'users'=>array('*'),
 61:             ),
 62:         );
 63:     }
 64: 
 65:     public function behaviors(){
 66:         return array_merge(parent::behaviors(), array(
 67:             'X2MobileControllerBehavior' => array(
 68:                 'class' => 
 69:                     'application.modules.mobile.components.behaviors.X2MobileControllerBehavior'
 70:             ),
 71:             'QuickCreateRelationshipBehavior' => array(
 72:                 'class' => 'QuickCreateRelationshipBehavior',
 73:                 'attributesOfNewRecordToUpdate' => array (
 74:                     'Contacts' => array (
 75:                         'accountName' => 'company',
 76:                     ),
 77:                 )
 78:             ),
 79:         ));
 80:     }
 81: 
 82: 
 83:     public function actionGetItems($term){
 84:         X2LinkableBehavior::getItems ($term);
 85:     }
 86: 
 87:     /**
 88:      * Displays a particular model.
 89:      * @param integer $id the ID of the model to be displayed
 90:      * @param null|Opportunity Set by actionConvertLead in the case that conversion fails
 91:      */
 92:     public function actionView($id, $opportunity=null) {
 93:         $type = 'x2Leads';
 94:         $model = $this->loadModel($id);
 95:         if($this->checkPermissions($model,'view')){
 96: 
 97:             // add opportunity to user's recent item list
 98:             User::addRecentItem('l', $id, Yii::app()->user->getId()); 
 99: 
100:             parent::view($model, $type);
101:         }else{
102:             $this->redirect('index');
103:         }
104:     }
105: 
106:     /**
107:      * Creates a new model.
108:      * If creation is successful, the browser will be redirected to the 'view' page.
109:      */
110:     public function actionCreate() {
111:         $model = new X2Leads;
112:         $users = User::getNames();
113:         foreach(Groups::model()->findAll() as $group){
114:             $users[$group->id]=$group->name;
115:         }
116:         unset($users['admin']);
117:         unset($users['']);
118: 
119:         // Uncomment the following line if AJAX validation is needed
120:         // $this->performAjaxValidation($model);
121: 
122:         if(isset($_POST['X2Leads'])) {
123:             $temp=$model->attributes;
124: 
125:             $model->setX2Fields($_POST['X2Leads']);
126: 
127:             if(isset($_POST['x2ajax'])) {
128:                 $ajaxErrors = $this->quickCreate ($model);
129:             } else {
130:                 if($model->save())
131:                     $this->redirect(array('view','id'=>$model->id));
132:             }
133:         }
134: 
135:         if(isset($_POST['x2ajax'])){
136:             $this->renderInlineCreateForm ($model, isset ($ajaxErrors) ? $ajaxErrors : false);
137:         } else {
138:             $this->render('create',array(
139:                 'model'=>$model,
140:                 'users'=>$users,
141:             ));
142:         }
143:     }
144: 
145:     /**
146:      * Updates a particular model.
147:      * If update is successful, the browser will be redirected to the 'view' page.
148:      * @param integer $id the ID of the model to be updated
149:      */
150:     public function actionUpdate($id) {
151:         $model=$this->loadModel($id);
152: 
153:         if(isset($_POST['X2Leads'])) {
154:             $model->setX2Fields($_POST['X2Leads']);
155:             if(!empty($model->associatedContacts))
156:                 $model->associatedContacts=implode(', ',$model->associatedContacts);
157: 
158:             if ($model->save())
159:                 $this->redirect(array('view','id'=>$model->id));
160:         }
161:         /* Set assignedTo back into an array only before re-rendering the input box with assignees 
162:            selected */
163:         $model->assignedTo = array_map(function($n){
164:             return trim($n,',');
165:         },explode(' ',$model->assignedTo));
166: 
167:         $this->render('update',array(
168:             'model'=>$model,
169:         ));
170:     }
171: 
172:     /**
173:      * Lists all models.
174:      */
175:     public function actionIndex() {
176:         $model=new X2Leads('search');
177:         $this->render('index', array('model'=>$model));
178:     }
179: 
180:     public function delete($id) {
181:         $model = $this->loadModel($id);
182: 
183:         CActiveDataProvider::model('Actions')->deleteAllByAttributes(
184:             array('associationType'=>'X2Leads','associationId'=>$id));
185: 
186:         $this->cleanUpTags($model);
187:         $model->delete();
188:     }
189: 
190:     public function actionDelete($id) {
191:         $model=$this->loadModel($id);
192: 
193:         if(Yii::app()->request->isPostRequest) {
194:             $event=new Events;
195:             $event->type='record_deleted';
196:             $event->associationType=$this->modelClass;
197:             $event->associationId=$model->id;
198:             $event->text=$model->name;
199:             $event->user=Yii::app()->user->getName();
200:             $event->save();
201:             Actions::model()->deleteAll('associationId='.$id.' AND associationType=\'x2Leads\'');
202:             $this->cleanUpTags($model);
203:             $model->delete();
204:         } else
205:             throw new CHttpException(
206:                 400,Yii::t('app','Invalid request. Please do not repeat this request again.'));
207:             // if AJAX request (triggered by deletion via admin grid view), we should not redirect 
208:             // the browser
209: 
210:         if(!isset($_GET['ajax']))
211:             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
212:     }
213: 
214:     public function actionGetTerms(){
215:         $sql = 'SELECT id, name as value FROM x2_accounts WHERE name LIKE :qterm ORDER BY name ASC';
216:         $command = Yii::app()->db->createCommand($sql);
217:         $qterm = $_GET['term'].'%';
218:         $command->bindParam(":qterm", $qterm, PDO::PARAM_STR);
219:         $result = $command->queryAll();
220:         echo CJSON::encode($result); exit;
221:     }
222: 
223:     /**
224:      * Create a menu for Leads
225:      * @param array Menu options to remove
226:      * @param X2Model Model object passed to the view
227:      * @param array Additional menu parameters
228:      */
229:     public function insertMenu($selectOptions = array(), $model = null, $menuParams = null) {
230:         $Leads = Modules::displayName();
231:         $Lead = Modules::displayName(false);
232:         $modelId = isset($model) ? $model->id : 0;
233: 
234:         /**
235:          * To show all options:
236:          * $menuOptions = array(
237:          *     'index', 'create', 'view', 'edit', 'delete', 'attach', 'quotes',
238:          *     'convert', 'print', 'import', 'export',
239:          * );
240:          */
241: 
242:         $menuItems = array(
243:             array(
244:                 'name'=>'index',
245:                 'label'=>Yii::t('x2Leads','{leads} List', array(
246:                     '{leads}' => $Leads,
247:                 )),
248:                 'url'=>array('index')
249:             ),
250:             array(
251:                 'name'=>'create',
252:                 'label'=>Yii::t('x2Leads','Create {lead}', array(
253:                     '{lead}' => $Lead,
254:                 )),
255:                 'url'=>array('create')
256:             ),
257:             RecordViewLayoutManager::getViewActionMenuListItem ($modelId),
258:             array(
259:                 'name'=>'edit',
260:                 'label'=>Yii::t('x2Leads','Edit {lead}', array(
261:                     '{lead}' => $Lead,
262:                 )),
263:                 'url'=>array('update', 'id'=>$modelId)
264:             ),
265:             array(
266:                 'name'=>'delete',
267:                 'label'=>Yii::t('x2Leads','Delete {lead}', array(
268:                     '{lead}' => $Lead,
269:                 )),
270:                 'url'=>'#',
271:                 'linkOptions'=>array(
272:                     'submit'=>array('delete','id'=>$modelId),
273:                     'confirm'=>'Are you sure you want to delete this item?')
274:             ),
275:             ModelFileUploader::menuLink(),
276:             array(
277:                 'name'=>'quotes',
278:                 'label' => Yii::t('quotes', 'Quotes/Invoices'),
279:                 'url' => 'javascript:void(0)',
280:                 'linkOptions' => array(
281:                     'onclick' => 'x2.inlineQuotes.toggle(); return false;')
282:             ),
283:             array(
284:                 'name'=>'convertToContact',
285:                 'label' => Yii::t('x2Leads', 'Convert to {contact}', array(
286:                     '{contact}' => Modules::displayName(false, "Contacts"),
287:                 )),
288:                 'url' => '#',
289:                 'linkOptions' => array ('id' => 'convert-lead-to-contact-button'),
290:             ),
291:             array(
292:                 'name'=>'convert',
293:                 'label' => Yii::t('x2Leads', 'Convert to {opportunity}', array(
294:                     '{opportunity}' => Modules::displayName(false, "Opportunities"),
295:                 )),
296:                 'url' => '#',
297:                 'linkOptions' => array ('id' => 'convert-lead-button'),
298:             ),
299:             array(
300:                 'name'=>'print',
301:                 'label' => Yii::t('app', 'Print Record'),
302:                 'url' => '#',
303:                 'linkOptions' => array (
304:                     'onClick'=>"window.open('".
305:                         Yii::app()->createUrl('/site/printRecord', array (
306:                             'modelClass' => 'X2Leads',
307:                             'id' => $modelId,
308:                             'pageTitle' => Yii::t('app', 'Leads').': '.(isset($model) ?
309:                                 $model->name : "")
310:                         ))."');"
311:                 )
312:             ),
313:             array(
314:                 'name'=>'import',
315:                 'label'=>Yii::t('x2Leads', 'Import {leads}', array(
316:                     '{leads}' => $Leads,
317:                 )),
318:                 'url'=>array('admin/importModels', 'model'=>'X2Leads'),
319:                 'visible'=>Yii::app()->params->isAdmin
320:             ),
321:             array(
322:                 'name'=>'export',
323:                 'label'=>Yii::t('x2Leads', 'Export {leads}', array(
324:                     '{leads}' => $Leads,
325:                 )),
326:                 'url'=>array('admin/exportModels', 'model'=>'X2Leads'),
327:                 'visible'=>Yii::app()->params->isAdmin
328:             ),
329:             RecordViewLayoutManager::getEditLayoutActionMenuListItem (),
330:         );
331: 
332:         $this->prepareMenu($menuItems, $selectOptions);
333:         $this->actionMenu = $this->formatMenu($menuItems, $menuParams);
334:     }
335: 
336: }
337: 
X2CRM Documentation API documentation generated by ApiGen 2.8.0