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