1 <?php
2
3 namespace Docoflow\Models;
4
5 use CDbCriteria;
6 use CActiveRecord;
7 use CActiveDataProvider;
8 use Docoflow\Traits\Validable;
9 use Docoflow\Traits\HasMutator;
10 use Docoflow\Contracts\ValidationStatus;
11
12 /**
13 * This is the model class for table "workflow_step".
14 *
15 * The followings are the available columns in table 'workflow_step':
16 *
17 * @property integer $id
18 * @property integer $workflow_id
19 * @property string $name
20 * @property integer $status
21 * @property string $expired_at
22 *
23 * @author Krisan Alfa Timur <krisanalfa@docotel.co.id>
24 */
25 class WorkflowStep extends CActiveRecord implements ValidationStatus
26 {
27 use HasMutator, Validable;
28
29 /**
30 * Returns the static model of the specified AR class.
31 *
32 * @param string $className active record class name.
33 *
34 * @return WorkflowStep the static model class
35 */
36 public static function model($className = __CLASS__)
37 {
38 return parent::model($className);
39 }
40
41 /**
42 * @return CDbConnection database connection
43 */
44 public function getDbConnection()
45 {
46 return container('docoflow.connection');
47 }
48
49 /**
50 * @return string the associated database table name
51 */
52 public function tableName()
53 {
54 return 'workflow_step';
55 }
56
57 /**
58 * @return array validation rules for model attributes.
59 */
60 public function rules()
61 {
62 // NOTE: you should only define rules for those attributes that
63 // will receive user inputs.
64 return array(
65 array('workflow_id', 'required'),
66 array('workflow_id, status', 'numerical', 'integerOnly' => true),
67 array('name', 'length', 'max' => 255),
68 array('expired_at', 'safe'),
69 // The following rule is used by search().
70 // Please remove those attributes that should not be searched.
71 array('id, workflow_id, name, status, expired_at', 'safe', 'on' => 'search'),
72 );
73 }
74
75 /**
76 * @return array relational rules.
77 */
78 public function relations()
79 {
80 // NOTE: you may need to adjust the relation name and the related
81 // class name for the relations automatically generated below.
82 return array(
83 'workflow' => array(static::BELONGS_TO, '\Docoflow\Models\Workflow', 'workflow_id'),
84 'groups' => array(static::HAS_MANY, '\Docoflow\Models\WorkflowGroups', 'workflow_step_id'),
85 );
86 }
87
88 /**
89 * @return array customized attribute labels (name=>label)
90 */
91 public function attributeLabels()
92 {
93 return array(
94 'id' => 'ID',
95 'workflow_id' => 'Workflow',
96 'name' => 'Name',
97 'status' => 'Status',
98 'expired_at' => 'Expired At',
99 );
100 }
101
102 /**
103 * Retrieves a list of models based on the current search/filter conditions.
104 *
105 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
106 */
107 public function search()
108 {
109 // Warning: Please modify the following code to remove attributes that
110 // should not be searched.
111
112 $criteria = new CDbCriteria();
113
114 $criteria->compare('id', $this->id);
115 $criteria->compare('workflow_id', $this->workflow_id);
116 $criteria->compare('name', $this->name, true);
117 $criteria->compare('status', $this->status);
118 $criteria->compare('expired_at', $this->expired_at, true);
119
120 return new CActiveDataProvider($this, array(
121 'criteria' => $criteria,
122 ));
123 }
124 }
125