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 [email protected].
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: * X2FlowAction that reassigns a record
39: *
40: * @package application.components.x2flow.actions
41: */
42: class X2FlowRecordReassign extends X2FlowAction {
43:
44: public $title = 'Reassign Record';
45: public $info = 'Assign the record to a user or group, or automatically using lead routing.';
46:
47: public function __construct(){
48: $this->attachBehavior('LeadRoutingBehavior', array('class' => 'LeadRoutingBehavior'));
49: }
50:
51: public function paramRules(){
52: $leadRoutingModes = array(
53: '' => 'Free For All',
54: 'roundRobin' => 'Round Robin Distribution',
55: 'roundRobin' => 'Sequential Distribution',
56: 'singleUser' => 'Direct User Assignment'
57: );
58: return array_merge (parent::paramRules (), array (
59: 'title' => Yii::t('studio', $this->title),
60: 'info' => Yii::t('studio', $this->info),
61: 'modelRequired' => 1,
62: 'options' => array(
63: // array('name'=>'routeMode','label'=>'Routing Method','type'=>'dropdown','options'=>$leadRoutingModes),
64: array(
65: 'name' => 'user',
66: 'label' => 'User',
67: 'type' => 'dropdown',
68: //'multiple' => 1,
69: 'options' => array(
70: 'auto' => Yii::t('studio', 'Use Lead Routing')) +
71: X2Model::getAssignmentOptions(true, true)
72: ),
73: // array('name'=>'onlineOnly','label'=>'Online Only?','optional'=>1,'type'=>'boolean','defaultVal'=>false),
74: )
75: ));
76: }
77:
78: public function execute(&$params){
79: $model = $params['model'];
80: if(!$model->hasAttribute('assignedTo')){
81: return array(
82: false,
83: Yii::t('studio', get_class($model).' records have no attribute "assignedTo"')
84: );
85: }
86:
87: $user = $this->parseOption('user', $params);
88: if (!is_scalar ($user)) {
89: return array(
90: false,
91: Yii::t('studio', 'Invalid value for field "User"')
92: );
93: }
94: if($user === 'auto'){
95: if (get_class ($model) === 'Contacts') {
96: $assignedTo = $this->getNextAssignee($model);
97: } else {
98: return array(
99: false, Yii::t('studio', 'Lead routing rules cannot be used with {type} records',
100: array ('{type}' => get_class ($model))));
101: }
102: }elseif(CActiveRecord::model('User')->exists('username=?', array($user)) ||
103: CActiveRecord::model('Groups')->exists('id=?', array($user))){
104: // make sure the user exists
105:
106: $assignedTo = $user;
107: }else{
108: return array(false, Yii::t('studio', 'User '.$user.' does not exist'));
109: }
110:
111: $model->assignedTo = $assignedTo;
112: if($model->save ()){
113: if(is_subclass_of($model, 'X2Model')){
114: return array(
115: true,
116: Yii::t('studio', 'View updated record: ').$model->getLink()
117: );
118: }else{
119: return array(true, "");
120: }
121: }else{
122: return array(false, "Failed to reassign the record");
123: }
124: }
125:
126: }
127: