1: <?php
2:
3: 4: 5: 6:
7:
8: 9: 10: 11: 12:
13: class ProductFeature extends X2Model {
14:
15: public $supportsWorkflow = false;
16:
17: 18: 19: 20:
21: public static function model($className=__CLASS__) { return parent::model($className); }
22:
23: 24: 25:
26: public function tableName() { return 'x2_product_features'; }
27:
28: public function behaviors() {
29: return array_merge(parent::behaviors(),array(
30: 'X2LinkableBehavior'=>array(
31: 'class'=>'X2LinkableBehavior',
32: 'baseRoute'=>'/products/products/productFeature'
33: )
34: ));
35: }
36:
37: 38: 39:
40: public function rules() {
41:
42:
43: $fields=Fields::model()->findAllByAttributes(array('modelName'=>get_class($this)));
44: $arr=array(
45: 'varchar'=>array(),
46: 'text'=>array(),
47: 'date'=>array(),
48: 'dropdown'=>array(),
49: 'int'=>array(),
50: 'email'=>array(),
51: 'currency'=>array(),
52: 'url'=>array(),
53: 'float'=>array(),
54: 'boolean'=>array(),
55: 'required'=>array(),
56:
57: );
58: $rules=array();
59: foreach($fields as $field){
60: $arr[$field->type][]=$field->fieldName;
61: if($field->required)
62: $arr['required'][]=$field->fieldName;
63: if($field->type!='date')
64: $arr['search'][]=$field->fieldName;
65: }
66: $arr['search'][]='name';
67: foreach($arr as $key=>$array){
68: switch($key){
69: case 'email':
70: $rules[]=array(implode(',',$array),$key);
71: break;
72: case 'required':
73: $rules[]=array(implode(',',$array),$key);
74: break;
75: case 'search':
76: $rules[]=array(implode(",",$array),'safe','on'=>'search');
77: break;
78: case 'int':
79: $rules[]=array(implode(',',$array),'numerical','integerOnly'=>true);
80: break;
81: case 'float':
82: $rules[]=array(implode(',',$array),'type','type'=>'float');
83: break;
84: case 'boolean':
85: $rules[]=array(implode(',',$array),$key);
86: break;
87: default:
88: break;
89:
90: }
91:
92: }
93: return $rules;
94: }
95:
96: 97: 98:
99: public function relations() {
100:
101:
102: return array(
103: );
104: }
105:
106: 107: 108:
109: public function attributeLabels() {
110: $fields=Fields::model()->findAllByAttributes(array('modelName'=>'ProductFeature'));
111: $arr=array();
112: foreach($fields as $field){
113: $arr[$field->fieldName]=Yii::t('app',$field->attributeLabel);
114: }
115:
116: return $arr;
117:
118: }
119:
120: 121: 122: 123:
124: public function search() {
125:
126:
127:
128: $criteria=new CDbCriteria;
129:
130: $fields=Fields::model()->findAllByAttributes(array('modelName'=>'ProductFeature'));
131: foreach($fields as $field){
132: $fieldName=$field->fieldName;
133: switch($field->type){
134: case 'boolean':
135: $criteria->compare($field->fieldName,$this->compareBoolean($this->$fieldName), true);
136: break;
137: case 'assignment':
138: $criteria->compare($field->fieldName,$this->compareAssignment($this->$fieldName), true);
139: break;
140: default:
141: $criteria->compare($field->fieldName,$this->$fieldName,true);
142: }
143:
144: }
145:
146: return new CActiveDataProvider(get_class($this), array(
147: 'criteria'=>$criteria,
148: 'pagination'=>array(
149: 'pageSize'=>Profile::getResultsPerPage(),
150: ),
151: ));
152: }
153:
154:
155:
156: }
157:
158: ?>
159: