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_workflow_stages".
39: *
40: * @package application.modules.workflow.models
41: * @property integer $id
42: * @property integer $workflowId
43: * @property integer $stageNumber
44: * @property string $name
45: * @property string $description
46: * @property float $conversionRate
47: * @property float $value
48: * @property integer $requirePrevious
49: * @property integer $requireComment
50: */
51: class WorkflowStage extends CActiveRecord {
52:
53: /**
54: * Value of $requirePrevious which indicates that all previous stages are required
55: */
56: const REQUIRE_ALL = 1;
57:
58: public $_roles = array();
59: /**
60: * Returns the static model of the specified AR class.
61: * @return WorkflowStage the static model class
62: */
63: public static function model($className=__CLASS__) {
64: return parent::model($className);
65: }
66:
67: /**
68: * @return string the associated database table name
69: */
70: public function tableName() {
71: return 'x2_workflow_stages';
72: }
73:
74: /**
75: * @return array validation rules for model attributes.
76: */
77: public function rules() {
78: // NOTE: you should only define rules for those attributes that
79: // will receive user inputs.
80: return array(
81: array('workflowId, stageNumber, requirePrevious', 'numerical', 'integerOnly'=>true),
82: array('requireComment', 'boolean'),
83: array('conversionRate, value', 'type', 'type'=>'float'),
84: array('conversionRate', 'numerical', 'max'=>100, 'min'=>0),
85: array('name', 'length', 'max'=>40),
86: // The following rule is used by search().
87: // Please remove those attributes that should not be searched.
88: array('id, workflowId, name, description, conversionRate, value', 'safe', 'on'=>'search'),
89: );
90: }
91:
92: /**
93: * @return array relational rules.
94: */
95: public function relations() {
96: return array(
97: 'workflow'=>array(self::BELONGS_TO, 'Workflow', 'workflowId'),
98: // 'roles'=>array(self::MANY_MANY, 'Roles','x2_role_to_workflow(stageId, roleId)'),
99: );
100: }
101:
102: public function getRoles() {
103: if(empty($this->_roles) && !empty($this->id))
104: $this->_roles = Yii::app()->db->createCommand()
105: ->select('roleId')
106: ->from('x2_role_to_workflow')
107: ->where('stageId='.$this->id)
108: ->queryColumn();
109: return $this->_roles;
110: }
111:
112: public function setRoles($roles) {
113: if(is_array($roles) || !empty($roles))
114: $this->_roles = $roles;
115: }
116:
117: /**
118: * @return array customized attribute labels (name=>label)
119: */
120: public function attributeLabels() {
121: return array(
122: 'id' => 'ID',
123: 'workflowId' => Yii::t('workflow','Workflow'),
124: // 'stageNumber' => Yii::t('workflow','Stage Number'),
125: 'name' => Yii::t('workflow','Stage Name'),
126: 'description' => Yii::t('workflow','Description'),
127: 'conversionRate' => Yii::t('workflow','Conversion Rate'),
128: 'value' => Yii::t('workflow','Value'),
129: 'roles' => Yii::t('workflow','Roles'),
130: 'requirePrevious' => Yii::t('workflow','Required Stages'),
131: 'requireComment' => Yii::t('workflow','Require Comment?'),
132: );
133: }
134:
135: /**
136: * Retrieves a list of models based on the current search/filter conditions.
137: * @return CActiveDataProvider the data provider that can return the models based on the
138: * search/filter conditions.
139: */
140: public function search($id) {
141:
142: $criteria = new CDbCriteria(
143: array('condition'=>'workflowId='.$id,'order'=>'stageNumber ASC'));
144:
145: return new CActiveDataProvider(get_class($this), array(
146: 'criteria'=>$criteria,
147: 'pagination'=>array(
148: 'pageSize'=>ceil(Profile::getResultsPerPage())
149: ),
150: ));
151: }
152:
153: }
154: